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.
This commit is contained in:
parent
06e984b086
commit
5645684ec9
|
@ -915,7 +915,7 @@ public class ZKUtil {
|
|||
// TODO: Set node ACL for groups when ZK supports this feature
|
||||
groups.add(user);
|
||||
} else {
|
||||
acls.add(new ACL(Perms.ALL, new Id("auth", user)));
|
||||
acls.add(new ACL(Perms.ALL, new Id("sasl", user)));
|
||||
}
|
||||
}
|
||||
if (!groups.isEmpty()) {
|
||||
|
|
|
@ -26,6 +26,7 @@ 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;
|
||||
|
@ -39,6 +40,29 @@ 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<ACL> 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<ACL> 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()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateACL() throws ZooKeeperConnectionException, IOException {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
|
@ -47,10 +71,10 @@ public class TestZKUtil {
|
|||
ZooKeeperWatcher watcher = new ZooKeeperWatcher(conf, node, null, false);
|
||||
List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
|
||||
Assert.assertEquals(aclList.size(), 4); // 3+1, since ACL will be set for the creator by default
|
||||
Assert.assertTrue(!aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group1")))
|
||||
&& !aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group2"))));
|
||||
Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("auth", "user1")))
|
||||
&& aclList.contains(new ACL(Perms.ALL, new Id("auth", "user2")))
|
||||
&& aclList.contains(new ACL(Perms.ALL, new Id("auth", "user3"))));
|
||||
Assert.assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group1"))));
|
||||
Assert.assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group2"))));
|
||||
Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1"))));
|
||||
Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user2"))));
|
||||
Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user3"))));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue