我已经通过包括加密在内的SSL两种方式对生产者和消费者设置了SASL + ACL和Kafka的Kafka和zookeeper身份验证。
通过在Kafka和Zookeeper之间启用SASL和ACL,不允许未经授权的Kafka经纪人登录Zookeeper集群。但是,主题创建和删除仍然可以不受任何限制。
zookeeper.properties
dataDir=/x02/lsesv2-s/data/Zookeeper
clientPort=15300
tickTime=2000
initLimit=10
syncLimit=5
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl
jaasLoginRenew=3600000
quorum.auth.enableSasl=true
quorum.auth.learnerRequireSasl=true
quorum.auth.serverRequireSasl=true
quorum.auth.learner.loginContext=QuorumLearner
quorum.auth.server.loginContext=QuorumServer
server.1=172.25.33.12:15302:15301
server.2=172.25.33.13:15302:15301
server.3=172.25.33.11:15302:15301
zookeeper_jaas.conf
Server {
org.apache.zookeeper.server.auth.DigestLoginModule required
username="admin"
password="abc123"
user_admin="abc123";
};
QuorumServer {
org.apache.zookeeper.server.auth.DigestLoginModule required
user_admin="abc123";
};
QuorumLearner {
org.apache.zookeeper.server.auth.DigestLoginModule required
username="admin"
password="abc123";
};
通过以下代码设置ACL
final CountDownLatch connectedSignal = new CountDownLatch(1);
String connect = "localhost:15300";
ZooKeeper zooKeeper = null;
try
{
String userName = "admin";
String password = "mit123";
zooKeeper = new ZooKeeper(connect, 5000, we ->
{
if (we.getState() == Watcher.Event.KeeperState.SyncConnected)
{
connectedSignal.countDown();
}
});
connectedSignal.await();
zooKeeper.addAuthInfo("digest", (userName + ":" + password).getBytes());
final String aclString = "auth:" + userName + ":" + password + ":" + "cdrwa" +
",sasl:" + userName + ":" + "cdrwa";
zooKeeper.setACL("/", parseACLs(aclString), -1);
} finally
{
if (zooKeeper != null)
{
zooKeeper.close();
}
}
上面的代码正在运行,下面是执行代码后的结果。
Welcome to ZooKeeper!
JLine support is disabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
getAcl /
'sasl,'admin
: cdrwa
'digest,'admin:oiasY+rmnmmK9mec8kpnvv281HE=
: cdrwa
启动时,我替代了Kafka属性,而不是server.properties文件。 *
Kafka属性
kafka/bin/kafka-server-start.sh /x02/lsesv2-s/current/kafka/config/server.properties
--override broker.id=1
--override zookeeper.connect=10g-flton-onl01:15300,10g-flton-onl02:15300,10g-flton-nor02:15300
--override num.network.threads=16
--override num.io.threads=16
--override socket.send.buffer.bytes=10240000
--override socket.receive.buffer.bytes=10240000
--override log.dirs=/x02/lsesv2-s/data/Kafka
--override offsets.topic.replication.factor=1
--override min.insync.replicas=1
--override inter.broker.listener.name=INTERNAL
--override listeners=INTERNAL://10g-flton-onl01:15307
--override advertised.listeners=INTERNAL://10g-flton-onl01:15307
--override listener.security.protocol.map=INTERNAL:SSL
--override security.protocol=SSL
--override ssl.client.auth=required
--override ssl.key.password=abc123
--override ssl.keystore.location=configs/MHV/kafka.server.keystore.jks
--override ssl.keystore.password=abc123
--override ssl.truststore.location=configs/MHV/kafka.server.truststore.jks
--override ssl.truststore.password=abc123
--override ssl.endpoint.identification.algorithm=
对生产者/消费者身份验证的卡夫卡工作正常,对卡夫卡身份验证的动物园管理员也工作正常。 但是,未经授权的用户也可以创建和删除主题。
主题创建
kafka/bin/kafka-topics.sh --create --zookeeper localhost:15300 --replication-factor 3 --partitions 8 --topic test
主题删除
kafka/bin/kafka-topics.sh --zookeeper localhost:15300 --delete --topic test
注意:创建或删除主题时,我没有设置-Djava.security.auth.login.config = kafka_server_jaas.conf。因此,应限制此操作。但实际上并非如此。
仅针对授权用户帮助我创建和删除主题。
答案 0 :(得分:0)
似乎这是本地测试的必需属性。
KAFKA_ZOOKEEPER_SET_ACL: "true"
也可直接用于融合图像或地图。
zookeeper.set.acl
所述
ZooKeeper中存储的元数据使得只有代理人才能修改相应的znode,但是znode是世界可读的。
由于我们将ZooKeeper配置为需要SASL身份验证,因此我们需要在启动kafka-topics工具时设置java.security.auth.login.config系统属性:
显示了一个代码示例和docker-compose文件here