zookeeper开启SASL权限认证
创始人
2024-11-27 03:32:58
0

目录

一、SASL介绍

二、使用 SASL 进行身份验证

2.1 服务器到服务器的身份验证

2.2 客户端到服务器身份验证

三、验证功能


一、SASL介绍

默认情况下,ZooKeeper 不使用任何形式的身份验证并允许匿名连接。但是,它支持 Java 身份验证与授权服务(JAAS),可用于使用简单身份验证和安全层(SASL)设置身份验证。zookeeper 支持使用带有本地存储的凭证的 DIGEST-MD5 SASL 机制进行身份验证。

SASL是一种用来扩充C/S模式验证能力的机制认证机制, 全称Simple Authentication and Security Layer。

二、使用 SASL 进行身份验证

JAAS 使用单独的配置文件进行配置。建议将 JAAS 配置文件放在与 ZooKeeper 配置相同的目录中(/zookeeper/conf/)。如文件名是 jaas.conf。ZooKeeper 是集群部署时,必须在所有节点上创建 JAAS 配置文件。

SASL 身份验证是单独配置的,用于服务器对服务器通信( ZooKeeper 实例之间的通信)和客户端对服务器通信( 客户端和 ZooKeeper 之间的通信)。服务器对服务器身份验证仅与具有多个节点的 ZooKeeper 集群相关。

2.1 服务器到服务器的身份验证

对于服务器到服务器身份验证,JAAS 配置文件包含两个部分:

  • 服务器配置
  • 客户端配置

使用 DIGEST-MD5 SASL 机制时,QuorumServer 上下文用于配置身份验证服务器。它必须包含允许所有用户名,以便其以未加密的形式与其密码连接。第二个上下文 QuorumLearner 必须为内置在 ZooKeeper 中的客户端配置。它还包含未加密格式的密码。以下是 DIGEST-MD5 机制的 JAAS 配置文件示例:

QuorumServer {        org.apache.zookeeper.server.auth.DigestLoginModule required        user_zookeeper="123456"; };  QuorumLearner {        org.apache.zookeeper.server.auth.DigestLoginModule required        username="zookeeper"        password="123456"; };

除了 JAAS 配置文件外,还必须通过指定以下选项在 ZooKeeper 的配置文件中启用服务器到服务器身份验证:

quorum.auth.enableSasl=true quorum.auth.learnerRequireSasl=true quorum.auth.serverRequireSasl=true quorum.auth.learner.loginContext=QuorumLearner quorum.auth.server.loginContext=QuorumServer quorum.cnxn.threads.size=20  # 客户端到服务器身份验证 requireClientAuthScheme=sasl # authProvider.myId=org.apache.zookeeper.server.auth.SASLAuthenticationProvider authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider # authProvider.2=org.apache.zookeeper.server.auth.SASLAuthenticationProvider # authProvider.3=org.apache.zookeeper.server.auth.SASLAuthenticationProvider 

然后,通过系统环境变量设置jaas.conf的路径

"-Djava.security.auth.login.config=/opt/kafka/config/jaas.conf"

2.2 客户端到服务器身份验证

客户端到服务器身份验证在与服务器到服务器身份验证相同的 JAAS 文件中配置。

将服务器上下文添加到 JAAS 配置文件,以配置客户端到服务器的身份验证。对于 DIGEST-MD5 机制,它会配置所有用户名和密码:

QuorumServer { 	org.apache.zookeeper.server.auth.DigestLoginModule required 	user_zookeeper="123456"; };  QuorumLearner { 	org.apache.zookeeper.server.auth.DigestLoginModule required 	username="zookeeper" 	password="123456"; };  Server { 	org.apache.zookeeper.server.auth.DigestLoginModule required 	user_test="123456"; };  Client { 	org.apache.zookeeper.server.auth.DigestLoginModule required 	username="test" 	password="123456"; };

同时,zookeeper的配置文件中需要添加如下配置:

# 客户端连接是否必须进行SASL认证 sessionRequireClientSASLAuth=true

三、验证功能

1、启动zk集群,zk集群可通过sasl认证并正常选举

2、编写客户端demo

System.setProperty("java.security.auth.login.config", "E:\\study\\apache-zookeeper-3.8.4-bin\\conf\\jaas.conf");         System.out.println("********************** start zk ********************** ");         CountDownLatch countDownLatch = new CountDownLatch(1);         ZooKeeperAdmin zooKeeper = new ZooKeeperAdmin("127.0.0.1:2181", 5000, event -> {             System.out.println("触发了事件:" + event.getState());             countDownLatch.countDown();         });          Stat existsName = zooKeeper.exists("/age", watchedEvent -> System.out.println("--" + watchedEvent.getState()));         if (existsName == null) {             zooKeeper.create("/age", "18".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);         } else {             byte[] data = zooKeeper.getData("/name", false, null);             System.out.println("--->" + new String(data));         }          String srvr = FourLetterWordMain.send4LetterWord("127.0.0.1", 2181, "srvr", false);         System.out.println(srvr);

相关内容

热门资讯

欢乐棋牌!wepower有辅助... 欢乐棋牌!wepower有辅助器(透视挂)苹果版本教程-都是真的有挂(百度贴吧)1、许多玩家不知道欢...
WPk!wepoke透明真的(... WPk!wepoke透明真的(透视辅助)插件挂教程-原来真的有挂(微博热搜)1、操作简单,无需注册,...
aapOKER!wepoke辅... aapOKER!wepoke辅助透视教程(透视辅助)输赢教程-好像真的有挂(头条)1、aapOKER...
AaPOKER!wepoke挂... AaPOKER!wepoke挂(辅助挂)智能教程-原来真的有挂(抖音);1、AaPOKER机器人多个...
wpk有透视辅助!wepoke... wpk有透视辅助!wepoke辅助是真的,AApoker的确真的有挂,详细教程(有挂教程);该软件可...
AApOKER!wepoke中... AApOKER!wepoke中牌率(透视挂)系统教程-果真真的有挂(微博热搜)1、AApOKER!w...
微扑克辅助挂!wepoke里面... 微扑克辅助挂!wepoke里面有ai,We辅poker助原来真的有挂,揭秘攻略(有挂攻略);1、让任...
wepoke有挂!来玩app德... wepoke有挂!来玩app德州辅助器,poker master安卓版的确是有挂的,技巧教程(有挂规...
轰趴十三水!wepoke游戏数... 轰趴十三水!wepoke游戏数据有说法(透视挂)开挂教程-果然真的有挂(知乎)轰趴十三水辅助器中分为...
AaPOKER!wopoker... AaPOKER!wopoker游戏辅助器(透视辅助)黑科技教程-果然真的有挂(哔哩哔哩)1)AaPO...