Kafka安全认证机制主要有SASL和SSL两种,以下是其配置方法:
server.properties
中,添加或修改listeners
为SASL_PLAINTEXT://host.name:port
或SASL_SSL://host.name:port
,设置security.inter.broker.protocol
为相应的协议,启用所需的SASL机制,如sasl.enabled.mechanisms=PLAIN,SCRAM-SHA-256
等。kafka-server-jaas.conf
文件,配置Broker的认证信息,如KafkaServer {org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";};
。也可通过listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config
属性为不同的监听器和机制配置JAAS。security.protocol
为SASL_PLAINTEXT
或SASL_SSL
,并通过ssl.truststore.location
等属性配置信任库,或使用client.sasl.jaas.config
属性配置客户端的JAAS。server.properties
,设置listeners
为SSL://
开头的地址,配置ssl.keystore.location
、ssl.keystore.password
、ssl.truststore.location
和ssl.truststore.password
等属性,指定证书和密钥的位置及密码。ssl.client.trust - cert - store.location
等属性,指向Kafka的证书。security.protocol
为SSL
,并配置ssl.truststore.location
和ssl.keystore.location
等属性,以信任Kafka的证书。