From c0dd6daff8dfc2604392a11bba57d40970a4dc00 Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Mon, 1 Feb 2016 09:48:16 -0800 Subject: [PATCH] HBASE-15200 ZooKeeper znode ACL checks should only compare the shortname --- .../hadoop/hbase/zookeeper/ZooKeeperWatcher.java | 45 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java index f7a2175..55d51d4 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java @@ -215,6 +215,7 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { */ public void checkAndSetZNodeAcls() { if (!ZKUtil.isSecureZooKeeper(getConfiguration())) { + LOG.info("not a secure deployment, proceeding"); return; } @@ -259,6 +260,9 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { * @throws IOException */ private boolean isBaseZnodeAclSetup(List acls) throws IOException { + if (LOG.isDebugEnabled()) { + LOG.debug("Checking znode ACLs"); + } String[] superUsers = conf.getStrings(Superusers.SUPERUSER_CONF_KEY); // Check whether ACL set for all superusers if (superUsers != null && !checkACLForSuperUsers(superUsers, acls)) { @@ -270,6 +274,9 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { String hbaseUser = UserGroupInformation.getCurrentUser().getShortUserName(); if (acls.isEmpty()) { + if (LOG.isDebugEnabled()) { + LOG.debug("ACL is empty"); + } return false; } @@ -280,17 +287,39 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { // and one for the hbase user if (Ids.ANYONE_ID_UNSAFE.equals(id)) { if (perms != Perms.READ) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("permissions for '%s' are not correct: have 0x%x, want 0x%x", + id, perms, Perms.READ)); + } return false; } } else if (superUsers != null && isSuperUserId(superUsers, id)) { if (perms != Perms.ALL) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("permissions for '%s' are not correct: have 0x%x, want 0x%x", + id, perms, Perms.ALL)); + } return false; } - } else if (new Id("sasl", hbaseUser).equals(id)) { - if (perms != Perms.ALL) { + } else if (id.getScheme().equals("sasl")) { + if (id.getId().startsWith(hbaseUser+"/")) { + if (perms != Perms.ALL) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("permissions for '%s' are not correct: have 0x%x, want 0x%x", + id, perms, Perms.ALL)); + } + return false; + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Unexpected shortname in SASL ACL: " + id); + } return false; } } else { + if (LOG.isDebugEnabled()) { + LOG.debug("unexpected ACL id '" + id + "'"); + } return false; } } @@ -306,8 +335,16 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { // TODO: Validate super group members also when ZK supports setting node ACL for groups. if (!user.startsWith(AuthUtil.GROUP_PREFIX)) { for (ACL acl : acls) { - if (user.equals(acl.getId().getId()) && acl.getPerms() == Perms.ALL) { - hasAccess = true; + if (user.equals(acl.getId().getId())) { + if (acl.getPerms() == Perms.ALL) { + hasAccess = true; + } else { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format( + "superuser '%s' does not have correct permissions: have 0x%x, want %0x", + acl.getId().getId(), acl.getPerms(), Perms.ALL)); + } + } break; } } -- 2.4.9 (Apple Git-60)