不确定它会帮助你,但也许:)
以下是我为部分问题所做的工作(无SASL):有效客户端IP的白名单。
添加到zkServer.sh -Dzookeeper.authProvider.1=MyCustomIPAuthenticationProvider
-Dzookeeper.authProvider.1=MyCustomIPAuthenticationProvider
使用创建所有znodes withACL(ZooDefs.Ids.CREATOR_ALL_ACL) (假设策展人)
withACL(ZooDefs.Ids.CREATOR_ALL_ACL)
和
public class MyCustomIPAuthenticationProvider extends org.apache.zookeeper.server.auth.IPAuthenticationProvider { private static Set<String> validHosts = new HashSet<>(); // todo populate @Override public KeeperException.Code handleAuthentication(org.apache.zookeeper.server.ServerCnxn cnxn, byte[] authData) { String id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress(); if (! matches(id, null) || ! matches(new String(authData), null)) { return org.apache.zookeeper.KeeperException.Code.AUTHFAILED; } return super.handleAuthentication(cnxn, authData); } @Override public boolean matches(String id, String aclExpr) { return validHosts.contains(id); } @Override public boolean isAuthenticated() { return true; } }
请注意,它不是100%安全(客户端可以伪造他的IP)。 (并且用例没有Kafka!)