Skip to content

Commit 405b055

Browse files
authored
Allow super user to set acl (#67)
Currently, if isX509ClientIdAsAclEnabled is set to true, all the acls passed in by user will be overwritten by the zk server, basically users do not have the right to set acls if znode group acl feature is on. But for super user, it should have the privilege to set acls since usually zk admins will be the super users, and when they manage zk clusters, there's need to manually set acls. This commit allows super users superUserId to set acls.
1 parent 2b93fc8 commit 405b055

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,14 @@ public static List<ACL> fixupACL(String path, List<Id> authInfo, List<ACL> acls)
10251025
if (cid.getScheme().equals(X509AuthenticationUtil.SUPERUSER_AUTH_SCHEME)) {
10261026
// No need to check authentication provider because user has "super" scheme
10271027
authIdValid = true;
1028-
if (!cid.getId().equals(
1028+
if (cid.getId().equals(
10291029
X509AuthenticationConfig.getInstance().getZnodeGroupAclSuperUserId())) {
1030-
// Allow operation but set domain name as znode ACL for cross domain components
1030+
// Allow operation and set the passed-in acl list as znode ACL for super user
1031+
rv.add(a);
1032+
} else {
1033+
// Allow operation and set domain name as znode ACL for cross domain components
10311034
rv.add(new ACL(a.getPerms(), new Id("x509", cid.getId())));
1032-
} // else allow operation but do not set client Id as znode ACL for super user
1035+
}
10331036
} else {
10341037
ServerAuthenticationProvider ap =
10351038
ProviderRegistry.getServerProvider(cid.getScheme());
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.zookeeper.server.auth.znode.groupacl;
20+
21+
import java.util.Collections;
22+
import java.util.HashMap;
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
import org.apache.zookeeper.KeeperException;
27+
import org.apache.zookeeper.ZooDefs;
28+
import org.apache.zookeeper.data.ACL;
29+
import org.apache.zookeeper.data.Id;
30+
import org.apache.zookeeper.server.PrepRequestProcessor;
31+
import org.apache.zookeeper.server.auth.X509AuthenticationConfig;
32+
import org.junit.AfterClass;
33+
import org.junit.Assert;
34+
import org.junit.BeforeClass;
35+
import org.junit.Test;
36+
37+
/**
38+
* This class test fixupACL method in {@link org.apache.zookeeper.server.PrepRequestProcessor}
39+
* under the znode group acl settings
40+
*/
41+
public class TestFixupACL {
42+
private final List<Id> superUserAuthInfo =
43+
Collections.singletonList(new Id("super", "superUserId"));
44+
private final List<Id> crossDomainComponentAuthInfo =
45+
Collections.singletonList(new Id("super", "crossDomain"));
46+
private final List<ACL> aclList =
47+
Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id("x509", "toBeAdded")));
48+
private final String testPath = "/zookeeper/testPath";
49+
private static final Map<String, String> SYSTEM_PROPERTIES = new HashMap<>();
50+
51+
static {
52+
SYSTEM_PROPERTIES.put(X509AuthenticationConfig.SET_X509_CLIENT_ID_AS_ACL, "true");
53+
SYSTEM_PROPERTIES
54+
.put(X509AuthenticationConfig.ZOOKEEPER_ZNODEGROUPACL_SUPERUSER_ID, "superUserId");
55+
SYSTEM_PROPERTIES.put(X509AuthenticationConfig.CROSS_DOMAIN_ACCESS_DOMAIN_NAME, "crossDomain");
56+
}
57+
58+
@BeforeClass
59+
public static void beforeClass() {
60+
SYSTEM_PROPERTIES.forEach(System::setProperty);
61+
}
62+
63+
@AfterClass
64+
public static void afterClass() {
65+
SYSTEM_PROPERTIES.keySet().forEach(System::clearProperty);
66+
}
67+
68+
@Test
69+
public void testCrossDomainComponents() throws KeeperException.InvalidACLException {
70+
List<ACL> returnedList =
71+
PrepRequestProcessor.fixupACL(testPath, crossDomainComponentAuthInfo, aclList);
72+
Assert.assertEquals(1, returnedList.size());
73+
Id returnedId = returnedList.get(0).getId();
74+
Assert.assertEquals("x509", returnedId.getScheme());
75+
Assert.assertEquals("crossDomain", returnedId.getId());
76+
}
77+
78+
@Test
79+
public void testSuperUserId() throws KeeperException.InvalidACLException {
80+
List<ACL> returnedList =
81+
PrepRequestProcessor.fixupACL(testPath, superUserAuthInfo, aclList);
82+
Assert.assertEquals(1, returnedList.size());
83+
Id returnedId = returnedList.get(0).getId();
84+
Assert.assertEquals("x509", returnedId.getScheme());
85+
Assert.assertEquals("toBeAdded", returnedId.getId());
86+
}
87+
}

0 commit comments

Comments
 (0)