我一直在尝试使用SASL_PLAINTEXT SCRAM-SHA-256为我的Kafka Brokers添加SASL身份验证一段时间,但没有任何成功。我在Kafka的日志文件中不断收到以下错误。
ERROR [Controller id = 0,targetBrokerId = 0]与节点0的连接失败 认证原因:认证因无效而失败 SASL机制SCRAM-SHA-256的凭证 (org.apache.kafka.clients.NetworkClient)。
但是我一直在关注SCRAM Config上的Kafka文档而没有接近成功实现此功能。
我使用kafka-configs.sh在Zookeeper上注册了一个管理员用户,如下所示:
bin/kafka-configs.sh --zookeeper localhost:2181 --alter --add-config 'SCRAM-SHA-256=[password=admin-secret],SCRAM-SHA-512=[password=admin-secret]' --entity-type users --entity-name admin
以下是我配置SCRAM-SHA-256的server.properties的一部分。
broker.id=50
sasl.enabled.mechanisms=SCRAM-SHA-256
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
security.inter.broker.protocol=SASL_PLAINTEXT
listeners=SASL_PLAINTEXT://172.16.3.21:9092
advertised.listeners=SASL_PLAINTEXT://172.16.3.21:9092
listener.name.sasl_plaintext.scram-sha-256.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
username="admin" \
password="admin-secret";
答案 0 :(得分:0)
在一个节点上生成CA并将其复制到其他节点上对我来说手动工作
keytool -keystore server.keystore.jks -alias kafka -dname“ cn = kafka,ou = it ,o = stackoverflow ,l = alpha < / strong>,st = beta ,c = IN ” -storepass test123 -validity 365 -keyalg RSA -genkey -ext SAN = DNS: kafka-host1 < / strong>,DNS: kafka-host2 ,DNS: kafka-host3 ,DNS:localhost,DNS:kafka
keytool -list -v -keystore server.keystore.jks
openssl req -new -x509 -keyout ca-key -out ca-cert -days 365 -subj“ / C = IN / ST = beta / O = stackoverflow > / OU = 它 / L = alpha / CN = kafka “
keytool -keystore server.truststore.jks -alias CARoot -import -file ca-cert -storepass test123 -noprompt
keytool -keystore client.truststore.jks -alias CARoot -import -file ca-cert -storepass test123 -noprompt
keytool -keystore server.keystore.jks -alias kafka -certreq -file cert-file -storepass test123
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 3650 -CAcreateserial -passin pass:test123
keytool -keystore server.keystore.jks -alias CARoot -import -file ca-cert -storepass test123 -noprompt
keytool -keystore server.keystore.jks -alias kafka -import -file cert-signed -storepass test123 -noprompt