我想使用 2 个侦听器配置 Kafka 身份验证(现在只需要身份验证,不需要加密):
- 一种用于具有 PLAINTEXT 安全性的经纪人间私人通信
- 一种用于消费者/生产者与 SASL_PLAINTEXT 和 SCRAM-SHA-256 的公共通信
我有一个只有一个代理(用于测试目的)的 Kafka 集群和一个有 2 个节点的 Zookeeper 集群
我已经完成的步骤是:
- 在 zookeeper 上创建 'admin' 和 'test-user' 用户
kafka-configs.sh --zookeeper zk:2181 --alter --add-config 'SCRAM-SHA-256=[iterations=8192,password=test-secret]' \
--entity-type users --entity-name test-user
kafka-configs.sh --zookeeper zk:2181 --alter --add-config 'SCRAM-SHA-256=[password=admin-secret]' \
--entity-type users --entity-name admin
- 配置服务器属性如下:
############################# Server Basics #############################
broker.id=1
############################# Socket Server Settings #############################
listeners=EXTERNAL://0.0.0.0:9095,INTERNAL://:9092
advertised.listeners=EXTERNAL://172.20.30.40:9095,INTERNAL://:9092
listener.security.protocol.map=INTERNAL:PLAINTEXT, EXTERNAL:SASL_PLAINTEXT
inter.broker.listener.name=INTERNAL
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
sasl.enabled.mechanisms=PLAIN, SCRAM-SHA-256
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
############################# Log Basics #############################
log.dirs=/opt/kafka/logs
num.partitions=1
num.recovery.threads.per.data.dir=1
delete.topic.enable=false
auto.create.topics.enable=true
default.replication.factor=1
############################# Log Flush Policy #############################
#log.flush.interval.messages=10000
#log.flush.interval.ms=1000
############################# Log Retention Policy #############################
log.retention.hours=168
#log.retention.bytes=1073741824
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
log.cleaner.enable=true
############################# Offset Retention #############################
offsets.retention.minutes=1440
############################# Connect Policy #############################
zookeeper.connect=10.42.203.74:2181,10.42.214.116:2181
zookeeper.connection.timeout.ms=6000
- 创建一个文件 kafka_server_jaas.conf 并在引导期间使用-Djava.security.auth.login.config=/opt/kafka/config/kafka_server_jaas.conf将其传递给 kafka
internal.KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin-secret";
};
external.KafkaServer {
org.apache.kafka.common.security.scram.ScramLoginModule required;
};
- 创建一个测试主题来发布/订阅
kafka-topics.sh --create --zookeeper zk:2181 --replication-factor 1 --partitions 3 --topic test-topic
- 使用 test-user 及其凭据创建要发布的 client-secure.properties 文件:
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
username="test-user" \
password="test-secret";
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256
- 最后尝试使用EXTERNAL监听器发布到之前创建的'test-topic'使用'test-user'进行身份验证
kafka-console-producer.sh --broker-list 172.20.30.40:9095 --topic test-topic
--producer.config client-secure.properties
我总是收到以下错误:
ERROR [Producer clientId=console-producer] Connection to node -1 failed authentication due to:
Client SASL mechanism 'SCRAM-SHA-256' not enabled in the server, enabled mechanisms are [PLAIN]
(org.apache.kafka.clients.NetworkClient)
为什么服务器上没有启用 SCRAM-SHA-256 机制?不应该使用“server.properties”文件上的“sasl.enabled.mechanisms=PLAIN, SCRAM-SHA-256”属性和“kafka_server_jaas.conf”文件上定义的外部侦听器配置上的 scram 配置来启用它吗?
我已经连续两天与这种应用不同的配置作斗争,但没有任何成功。任何帮助将非常感激
提前致谢