zookeeper digest + acl

原创
2020/08/14 15:39
阅读数 2.3K

zookeeper digest + acl

server-server

每个zookeeper节点都要配置

  1. 在zoo.cfg下添加
quorum.auth.enableSasl=true
quorum.auth.learnerRequireSasl=true
quorum.auth.serverRequireSasl=true
quorum.auth.learner.saslLoginContext=QuorumLearner
quorum.auth.server.saslLoginContext=QuorumServer
quorum.cnxn.threads.size=20
  1. 编写jaas.conf
QuorumServer {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       user_admin="admin";
};
 
QuorumLearner {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       username="admin"
       password="123456";
};
  1. 在conf下创建java.env并指定jaas.conf:
SERVER_JVMFLAGS="-Djava.security.auth.login.config=/mnt/e/libs/zookeeper/zk1/zk/conf/jaas.conf"

client-server

server

每个zookeeper节点都要配置

  1. 在zoo.cfg下添加
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider 
  1. 编写jaas.conf
Server {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       user_hello="123456";
};
  1. 在conf下创建java.env并指定jaas.conf:
SERVER_JVMFLAGS="-Djava.security.auth.login.config=/mnt/e/libs/zookeeper/zk1/zk/conf/jaas.conf"

client

选择一个zookeeper节点配置

  1. 编写jaas.conf
Client {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       username="hello"
       password="123456";
};
  1. 在conf下创建java.env并指定jaas.conf:
CLIENT_JVMFLAGS="-Djava.security.auth.login.config=/mnt/e/libs/zookeeper/zk1/zk/conf/jaas.conf"
  1. 执行 zkCli.sh
WatchedEvent state:SaslAuthenticated type:None path:null

表示sasl认证成功 创建一个节点

create /t ni sasl:hello:cdrwa
getAcl /t

在另一个没有配置client的节点执行zkCli.sh并删除该节点

[zk: localhost:2181(CONNECTED) 22] get /t
org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /t
[zk: localhost:2181(CONNECTED) 23] set /t a
Authentication is not valid : /t
[zk: localhost:2181(CONNECTED) 24] create /t/t
Authentication is not valid : /t/t
[zk: localhost:2181(CONNECTED) 25] rmr /t
The command 'rmr' has been deprecated. Please use 'deleteall' instead.
Authentication is not valid : /t

kafka连接zk

  1. server.properties添加
zookeeper.set.acl=true
  1. 编写jaas.conf
Client {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       username="hello"
       password="123456";
};
  1. 指定jaas.conf 在bin/kafka-run-class.sh第一行添加
export KAFKA_AUTH_OPTS=" -Djava.security.auth.login.config=/mnt/e/libs/kafka/kafka/010/1/config/jaas.conf"

在启动命令中指定KAFKA_AUTH_OPTS

if [ "x$DAEMON_MODE" = "xtrue" ]; then
 nohup $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS $KAFKA_AUTH_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" > "$CONSOLE_OUTPUT_FILE" 2>&1 < /dev/null &
else
 exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS $KAFKA_AUTH_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"
fi
  1. 查看kafka创建的节点均已添加了acl

参考

  1. Server-Server mutual authentication
  2. Client-Server mutual authentication
展开阅读全文
加载中
点击加入讨论🔥(2) 发布并加入讨论🔥
打赏
2 评论
0 收藏
0
分享
返回顶部
顶部