如何使用zkCli从ZooKeeper访问受保护的znode?

sq1bmfud  于 2022-12-09  发布在  Apache
关注(0)|答案(2)|浏览(140)

我创建了一个znode,使用:

zookeeper-0:/opt/zookeeper/bin # ./zkCli.sh create /mynode content digest:user:pass:cdrwa

现在如何使用zkCli.sh实用程序访问znode?

zookeeper-0:/opt/zookeeper/bin # ./zkCli.sh get /mynode
Connecting to localhost:2181

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
Authentication is not valid : /mynode
zookeeper-0:/opt/zookeeper/bin #

getAcl显示以下内容:

zookeeper-0:/opt/zookeeper/bin # ./zkCli.sh getAcl /mynode
Connecting to localhost:2181

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
'digest,'user:pass
: cdrwa
zookeeper-0:/opt/zookeeper/bin #
fkaflof6

fkaflof61#

您需要使用散列密码创建摘要ACL。
ZooKeeper Programmer's Guide

digest使用username:password字符串生成MD5哈希,然后将其用作ACL ID标识。通过以明文形式发送username:password来完成验证。在ACL中使用时,表达式将为username:base64编码的SHA1密码摘要。

生成散列密码

$ java -cp "./zookeeper-3.4.13.jar:./lib/slf4j-api-1.7.25.jar" \
org.apache.zookeeper.server.auth.DigestAuthenticationProvider user:pass
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
user:pass->user:smGaoVKd/cQkjm7b88GyorAUz20=

使用散列密码创建节点

[zk: zookeeper(CONNECTED) 0] create /mynode content digest:user:smGaoVKd/cQkjm7b88GyorAUz20=:cdrwa
Created /mynode

访问受保护的节点

[zk: zookeeper(CONNECTED) 1] get /mynode
Authentication is not valid : /mynode
[zk: zookeeper(CONNECTED) 2] addauth digest user:pass
[zk: zookeeper(CONNECTED) 3] get /mynode
content
cZxid = 0x14
ctime = Wed Sep 12 19:37:48 GMT 2018
mZxid = 0x14
mtime = Wed Sep 12 19:37:48 GMT 2018
pZxid = 0x14
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
xdyibdwo

xdyibdwo2#

如果查看www.example.com脚本的内容zkcli.sh,您将看到一个注解掉的块,显示如何使用凭据配置环境变量:

#SOLR_ZK_CREDS_AND_ACLS="-DzkACLProvider=org.apache.solr.common.cloud.VMParamsAllAndReadonlyDigestZkACLProvider \
#  -DzkCredentialsProvider=org.apache.solr.common.cloud.VMParamsSingleSetCredentialsDigestZkCredentialsProvider \
#  -DzkDigestUsername=admin-user -DzkDigestPassword=CHANGEME-ADMIN-PASSWORD \
#  -DzkDigestReadonlyUsername=readonly-user -DzkDigestReadonlyPassword=CHANGEME-READONLY-PASSWORD"

您可以按照此模板使用正确的凭据在本地系统上配置环境变量SOLR_ZK_CREDS_AND_ACLS,然后zkcli.sh脚本将在与ZooKeeper通信时使用它们。

相关问题