Skip to content

Commit ade1f26

Browse files
authored
Fixing cross domain component for dedicated server connection. (#81)
* Fixing cross domain component for dedicated server connection. Co-authored-by: Rahul Rane <[email protected]>
1 parent af7c467 commit ade1f26

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/auth/znode/groupacl/X509ZNodeGroupAclProvider.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
package org.apache.zookeeper.server.auth.znode.groupacl;
2020

2121
import java.util.Collections;
22+
import java.util.stream.Collectors;
2223
import java.util.HashSet;
2324
import java.util.Set;
25+
import java.util.List;
2426
import javax.net.ssl.X509KeyManager;
2527
import javax.net.ssl.X509TrustManager;
2628
import javax.security.auth.x500.X500Principal;
@@ -216,9 +218,19 @@ private void assignAuthInfo(ServerCnxn cnxn, String clientId, Set<String> domain
216218
String superUser = X509AuthenticationConfig.getInstance().getZnodeGroupAclSuperUserId();
217219

218220
Set<Id> newAuthIds = new HashSet<>();
221+
222+
// Find interesecting super user domains/cross domains from provided domains list
223+
List<String> commonSuperUserDomains =
224+
superUserDomainNames.stream().filter(domains::contains).collect(Collectors.toList());
225+
219226
// Check if user belongs to super user group
220227
if (clientId.equals(superUser)) {
221228
newAuthIds.add(new Id(X509AuthenticationUtil.SUPERUSER_AUTH_SCHEME, clientId));
229+
} else if (!commonSuperUserDomains.isEmpty()) {
230+
// For cross domain components, add (super:domainName) in authInfo
231+
// "super" scheme gives access to all znodes without checking znode ACL vs authorized domain name
232+
commonSuperUserDomains.stream().forEach(d ->
233+
newAuthIds.add(new Id(X509AuthenticationUtil.SUPERUSER_AUTH_SCHEME, d)));
222234
} else if (X509AuthenticationConfig.getInstance().isZnodeGroupAclDedicatedServerEnabled()) {
223235
// If connection filtering feature is turned on, use connection filtering instead of normal authorization
224236
String serverNamespace = X509AuthenticationConfig.getInstance().getZnodeGroupAclServerDedicatedDomain();
@@ -235,16 +247,8 @@ private void assignAuthInfo(ServerCnxn cnxn, String clientId, Set<String> domain
235247
cnxn.close(ServerCnxn.DisconnectReason.SSL_AUTH_FAILURE);
236248
}
237249
} else {
238-
domains.forEach(d -> {
239-
// For cross domain components, add (super:domainName) in authInfo
240-
// "super" scheme gives access to all znodes without checking znode ACL vs authorized domain name
241-
if (superUserDomainNames.contains(d)) {
242-
newAuthIds.add(new Id(X509AuthenticationUtil.SUPERUSER_AUTH_SCHEME, d));
243-
} else {
244-
// For other cases, add (x509:domainName) in authInfo
245-
newAuthIds.add(new Id(getScheme(), d));
246-
}
247-
});
250+
// For other cases, add (x509:domainName) in authInfo
251+
domains.stream().forEach(d -> newAuthIds.add(new Id(getScheme(), d)));
248252
}
249253

250254
// Update the existing connection AuthInfo accordingly.

zookeeper-server/src/test/java/org/apache/zookeeper/server/auth/znode/groupacl/X509ZNodeGroupAclProviderTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class X509ZNodeGroupAclProviderTest extends ZKTestCase {
6060
private TestNIOServerCnxnFactory serverCnxnFactory;
6161
private ZooKeeper admin;
6262
private static final String AUTH_PROVIDER_PROPERTY_NAME = "zookeeper.authProvider.x509";
63-
private static final String CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH = "/_CLIENT_URI_DOMAIN_MAPPING";
63+
private static final String CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH = "/zookeeper/uri-domain-map";
6464
private static final String[] MAPPING_PATHS = {CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH,
6565
CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH + "/CrossDomain",
6666
CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH + "/CrossDomain/CrossDomainUser",
@@ -264,6 +264,17 @@ public void testConnectionFiltering() {
264264
Assert.assertEquals("super", authInfo.get(0).getScheme());
265265
Assert.assertEquals("SuperUser", authInfo.get(0).getId());
266266
System.clearProperty(X509AuthenticationConfig.DEDICATED_DOMAIN);
267+
268+
// Cross domain components
269+
provider = createProvider(crossDomainCert);
270+
cnxn = new MockServerCnxn();
271+
cnxn.clientChain = new X509Certificate[]{crossDomainCert};
272+
Assert.assertEquals(KeeperException.Code.OK, provider
273+
.handleAuthentication(new ServerAuthenticationProvider.ServerObjs(zks, cnxn), new byte[0]));
274+
authInfo = cnxn.getAuthInfo();
275+
Assert.assertEquals(1, authInfo.size());
276+
Assert.assertEquals("super", authInfo.get(0).getScheme());
277+
Assert.assertEquals("CrossDomain", authInfo.get(0).getId());
267278
}
268279

269280
private X509ZNodeGroupAclProvider createProvider(X509Certificate trustedCert) {

zookeeper-server/src/test/java/org/apache/zookeeper/server/auth/znode/groupacl/ZkClientUriDomainMappingHelperTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ZkClientUriDomainMappingHelperTest extends ZKTestCase {
4949
private static final Logger LOG =
5050
LoggerFactory.getLogger(ZkClientUriDomainMappingHelperTest.class);
5151
private static final String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
52-
private static final String CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH = "/_CLIENT_URI_DOMAIN_MAPPING";
52+
private static final String CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH = "/zookeeper/uri-domain-map";
5353
private static final int CONNECTION_TIMEOUT = 300000;
5454
private static final String[] MAPPING_PATHS = {
5555
CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH,
@@ -108,16 +108,6 @@ public void cleanUp() throws InterruptedException, IOException, KeeperException
108108
ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
109109
}
110110

111-
/**
112-
* Mapping root path hasn't been created - should create the node automatically
113-
*/
114-
@Test
115-
public void testA_ZkClientUriDomainMappingHelper() {
116-
new ZkClientUriDomainMappingHelper(zookeeperServer);
117-
Assert.assertNotNull(
118-
zookeeperServer.getZKDatabase().getNode(CLIENT_URI_DOMAIN_MAPPING_ROOT_PATH));
119-
}
120-
121111
/**
122112
* Create a dummy mapping and verify that the helper correctly updates changes to the mapping
123113
* stored in ZNodes.

0 commit comments

Comments
 (0)