From 54747ccb285484dbbf823e30d08bace16bbc10bb Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Wed, 1 Mar 2017 18:41:05 -0500 Subject: [PATCH] HBASE-17717 Explicitly use "sasl" ACL scheme for hbase superuser The special "auth" ZK ACL scheme will always set the ACL's id (the user who is allowed) to be the authenticated user of the ZK connection. This results in the HBase superuser not actually receiving the permissions as the ZKUtil intends to do. Since we know we have security enabled, we can instead explicitly list "sasl" as the ACL scheme instead. --- .../org/apache/hadoop/hbase/zookeeper/ZKUtil.java | 2 +- .../apache/hadoop/hbase/zookeeper/TestZKUtil.java | 65 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 6480592..2b35e09 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -1034,7 +1034,7 @@ public class ZKUtil { ArrayList acls = new ArrayList(); // add permission to hbase supper user if (superUser != null) { - acls.add(new ACL(Perms.ALL, new Id("auth", superUser))); + acls.add(new ACL(Perms.ALL, new Id("sasl", superUser))); } // Certain znodes are accessed directly by the client, // so they must be readable by non-authenticated clients diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java new file mode 100644 index 0000000..8b2dd54 --- /dev/null +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKUtil.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.hadoop.hbase.zookeeper; + +import java.io.IOException; +import java.util.List; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.ZooKeeperConnectionException; +import org.apache.hadoop.hbase.security.Superusers; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.Perms; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * + */ +@Category({SmallTests.class}) +public class TestZKUtil { + + @Test + public void testUnsecure() throws ZooKeeperConnectionException, IOException { + Configuration conf = HBaseConfiguration.create(); + conf.set(Superusers.SUPERUSER_CONF_KEY, "user1"); + String node = "/hbase/testUnsecure"; + ZooKeeperWatcher watcher = new ZooKeeperWatcher(conf, node, null, false); + List aclList = ZKUtil.createACL(watcher, node, false); + Assert.assertEquals(aclList.size(), 1); + Assert.assertTrue(aclList.contains(Ids.OPEN_ACL_UNSAFE.iterator().next())); + } + + @Test + public void testSecuritySingleSuperuser() throws ZooKeeperConnectionException, IOException { + Configuration conf = HBaseConfiguration.create(); + conf.set(Superusers.SUPERUSER_CONF_KEY, "user1"); + String node = "/hbase/testSecuritySingleSuperuser"; + ZooKeeperWatcher watcher = new ZooKeeperWatcher(conf, node, null, false); + List aclList = ZKUtil.createACL(watcher, node, true); + Assert.assertEquals(aclList.size(), 2); // 1+1, since ACL will be set for the creator by default + Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1")))); + Assert.assertTrue(aclList.contains(Ids.CREATOR_ALL_ACL.iterator().next())); + } +} -- 2.10.2