Skip to content

Commit f7648da

Browse files
committed
HADOOP-10649. Allow overriding the default ACL for service authorization (Contributed by Benoy Antony)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1606179 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5cd0b44 commit f7648da

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

hadoop-common-project/hadoop-common/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ Release 2.5.0 - UNRELEASED
483483
HADOOP-10565. Support IP ranges (CIDR) in proxyuser.hosts. (Benoy Antony
484484
via Arpit Agarwal)
485485

486+
HADOOP-10649. Allow overriding the default ACL for service authorization
487+
(Benoy Antony via Arpit Agarwal)
488+
486489
OPTIMIZATIONS
487490

488491
BUG FIXES

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic {
131131
* Service Authorization
132132
*/
133133
public static final String
134+
HADOOP_SECURITY_SERVICE_AUTHORIZATION_DEFAULT_ACL =
135+
"security.service.authorization.default.acl";
136+
public static final String
134137
HADOOP_SECURITY_SERVICE_AUTHORIZATION_REFRESH_POLICY =
135138
"security.refresh.policy.protocol.acl";
136139
public static final String

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/authorize/ServiceAuthorizationManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ public void refreshWithLoadedConfiguration(Configuration conf,
131131
PolicyProvider provider) {
132132
final Map<Class<?>, AccessControlList> newAcls =
133133
new IdentityHashMap<Class<?>, AccessControlList>();
134+
135+
String defaultAcl = conf.get(
136+
CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_AUTHORIZATION_DEFAULT_ACL,
137+
AccessControlList.WILDCARD_ACL_VALUE);
134138

135139
// Parse the config file
136140
Service[] services = provider.getServices();
@@ -139,7 +143,7 @@ public void refreshWithLoadedConfiguration(Configuration conf,
139143
AccessControlList acl =
140144
new AccessControlList(
141145
conf.get(service.getServiceKey(),
142-
AccessControlList.WILDCARD_ACL_VALUE)
146+
defaultAcl)
143147
);
144148
newAcls.put(service.getProtocol(), acl);
145149
}

hadoop-common-project/hadoop-common/src/site/apt/ServiceLevelAuth.apt.vm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ security.ha.service.protocol.acl | ACL for HAService protocol used by HAAdm
100100
Example: <<<user1,user2 group1,group2>>>.
101101

102102
Add a blank at the beginning of the line if only a list of groups is to
103-
be provided, equivalently a comman-separated list of users followed by
103+
be provided, equivalently a comma-separated list of users followed by
104104
a space or nothing implies only a set of given users.
105105

106106
A special value of <<<*>>> implies that all users are allowed to access the
107-
service.
107+
service.
108+
109+
If access control list is not defined for a service, the value of
110+
<<<security.service.authorization.default.acl>>> is applied. If
111+
<<<security.service.authorization.default.acl>>> is not defined, <<<*>>> is applied.
108112

109113
** Refreshing Service Level Authorization Configuration
110114

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
package org.apache.hadoop.security.authorize;
19+
20+
import static org.junit.Assert.assertEquals;
21+
22+
import org.apache.hadoop.conf.Configuration;
23+
import org.apache.hadoop.fs.CommonConfigurationKeys;
24+
import org.apache.hadoop.ipc.TestRPC.TestProtocol;
25+
import org.junit.Test;
26+
27+
public class TestServiceAuthorization {
28+
29+
private static final String ACL_CONFIG = "test.protocol.acl";
30+
private static final String ACL_CONFIG1 = "test.protocol1.acl";
31+
32+
public interface TestProtocol1 extends TestProtocol {};
33+
34+
private static class TestPolicyProvider extends PolicyProvider {
35+
36+
@Override
37+
public Service[] getServices() {
38+
return new Service[] { new Service(ACL_CONFIG, TestProtocol.class),
39+
new Service(ACL_CONFIG1, TestProtocol1.class),
40+
};
41+
}
42+
}
43+
44+
@Test
45+
public void testDefaultAcl() {
46+
ServiceAuthorizationManager serviceAuthorizationManager =
47+
new ServiceAuthorizationManager();
48+
Configuration conf = new Configuration ();
49+
//test without setting a default acl
50+
conf.set(ACL_CONFIG, "user1 group1");
51+
serviceAuthorizationManager.refresh(conf, new TestPolicyProvider());
52+
AccessControlList acl = serviceAuthorizationManager.getProtocolsAcls(TestProtocol.class);
53+
assertEquals("user1 group1", acl.getAclString());
54+
acl = serviceAuthorizationManager.getProtocolsAcls(TestProtocol1.class);
55+
assertEquals(AccessControlList.WILDCARD_ACL_VALUE, acl.getAclString());
56+
57+
//test with a default acl
58+
conf.set(
59+
CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_AUTHORIZATION_DEFAULT_ACL,
60+
"user2 group2");
61+
serviceAuthorizationManager.refresh(conf, new TestPolicyProvider());
62+
acl = serviceAuthorizationManager.getProtocolsAcls(TestProtocol.class);
63+
assertEquals("user1 group1", acl.getAclString());
64+
acl = serviceAuthorizationManager.getProtocolsAcls(TestProtocol1.class);
65+
assertEquals("user2 group2", acl.getAclString());
66+
}
67+
}

0 commit comments

Comments
 (0)