apache kafka与spark 1.6.3的安全和非安全连接

xxslljrj  于 2021-06-08  发布在  Kafka
关注(0)|答案(2)|浏览(416)

尝试将启用kerberos的apache kafka(0.9)与apache spark 1.6.3一起使用时出错。zookeeper版本为3.4.5我必须连接到两个kafka。一个启用了keberos,另一个没有,所以我没有在spark executor的extra java opts中设置java.security.auth.login.config属性。

Kafka Initialization failed: org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
    at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:648)
    at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:542)
    at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:524)
    at com.spark.receiver.helper.KafkaChannelHelper.initializeConnection(KafkaChannelHelper.java:277)
    at com.spark.receiver.helper.KafkaChannelHelper$2.run(KafkaChannelHelper.java:240)
Caused by: org.apache.kafka.common.KafkaException: java.lang.IllegalArgumentException: Could not find a 'KafkaClient' entry in `/home/user/kafka_client.conf`.
    at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:74)
    at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:60)
    at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:79)
    at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:577)
    ... 4 more
Caused by: java.lang.IllegalArgumentException: Could not find a 'KafkaClient' entry in `/home/user/kafka_client.conf`.
    at org.apache.kafka.common.security.kerberos.Login.login(Login.java:294)
    at org.apache.kafka.common.security.kerberos.Login.<init>(Login.java:104)
    at org.apache.kafka.common.security.kerberos.LoginManager.<init>(LoginManager.java:44)
    at org.apache.kafka.common.security.kerberos.LoginManager.acquireLoginManager(LoginManager.java:85)
    at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:55)
    ... 7 more

java.security.auth.login.config在使用者本身中设置。连接到kafkaconsumer的代码是:

public void initializeConnection() {
    props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT");
         System.setProperty("java.security.auth.login.config", jassFilePath);
        try {
            this.consumer = new KafkaConsumer<String, byte[]>(props);
        } catch (Exception e) {
            LOGGER.error("Kafka Initialization failed: ", e);
        }
    }

kafka_client.conf仅包含以下部分:

KafkaClient{
    com.sun.security.auth.module.Krb5LoginModule required
    debug=true
    useKeyTab=true
    keyTab="/etc/security/keytabs/user.keytab"
    storeKey=true
    principal="user@REALM"
    serviceName="kafka";
};
jhiyze9q

jhiyze9q1#

在向安全en发布/使用数据之前,应该考虑两件事vironment:-
配置security.protocol

Properties props = new Properties();
props.put("security.protocol", "PLAINTEXTSASL");

传递jaas配置和javavm选项

java -Djava.security.auth.login.config=/home/kafka-user/kafka-jaas.conf \
-Djava.security.krb5.conf=/etc/krb5.conf \
-Djavax.security.auth.useSubjectCredsOnly=false \
-cp hdp-kafka-sample-1.0-SNAPSHOT.jar:/usr/hdp/current/kafka-broker/libs/* \
hdp.sample.KafkaProducer one.hdp:6667 test

请访问securekafkajava producer with kerberos以获得完整的解释。

dauxcl2d

dauxcl2d2#

我对Kafka1.11.0也有类似的问题。
同一jvm中的监控程序正在访问多个代理,一些代理使用sasl kerberos,而另一些代理则不安全。
在访问安全集群时,程序self添加了参数。

-Djava.security.auth.login.config=/home/kafka-user/kafka-jaas.conf

但是程序抛出了一个异常:

Could not find a 'KafkaClient' entry in the JAAS configuration. System property 'java.security.auth.login.config' is /path/to/jaas/kafka_client_jaas_usekeytab.conf

奇怪的是 java.security.auth.login.config 设置正确,文件中的内容也很好。
另一个单集群程序运行良好。
kafka客户端的官方文档jaas配置说明:

Clients may specify JAAS configuration as a producer or consumer property without creating a physical configuration file. 

This mode also enables different producers and consumers within the same JVM to use different credentials by specifying different properties for each client. 

If both static JAAS configuration system property java.security.auth.login.config and client property sasl.jaas.config are specified, the client property will be used.

另一个问题是:
他面对的一些问题只有 java.security.auth.login.config .

也许解决办法是:

提供 sasl.jaas.configjava.security.auth.login.config 在你的程序里。
我会为这个案子核实的。

相关问题