Skip to content

Commit 366e400

Browse files
committed
HADOOP-6995. Allow wildcards to be used in ProxyUsers configurations. Contributed by Todd Lipcon
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1056006 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9b3c640 commit 366e400

File tree

4 files changed

+176
-3
lines changed

4 files changed

+176
-3
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Trunk (unreleased changes)
3939
HADOOP-7078. Improve javadocs for RawComparator interface.
4040
(Harsh J Chouraria via todd)
4141

42+
HADOOP-6995. Allow wildcards to be used in ProxyUsers configurations.
43+
(todd)
44+
4245
OPTIMIZATIONS
4346

4447
BUG FIXES

src/docs/src/documentation/content/xdocs/Superusers.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
<p>
9090
If these configurations are not present, impersonation will not be allowed and connection will fail.
9191
</p>
92+
<p>
93+
If more lax security is preferred, the wildcard value <code>*</code> may be used to allow impersonation from any host or of any user.
94+
</p>
9295
</section>
9396

9497

src/java/org/apache/hadoop/security/authorize/ProxyUsers.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ public static synchronized void authorize(UserGroupInformation user,
126126
Collection<String> allowedUserGroups = proxyGroups.get(
127127
getProxySuperuserGroupConfKey(superUser.getShortUserName()));
128128

129-
if (allowedUserGroups != null && !allowedUserGroups.isEmpty()) {
129+
if (isWildcardList(allowedUserGroups)) {
130+
groupAuthorized = true;
131+
} else if (allowedUserGroups != null && !allowedUserGroups.isEmpty()) {
130132
for (String group : user.getGroupNames()) {
131133
if (allowedUserGroups.contains(group)) {
132134
groupAuthorized = true;
@@ -142,8 +144,10 @@ public static synchronized void authorize(UserGroupInformation user,
142144

143145
Collection<String> ipList = proxyHosts.get(
144146
getProxySuperuserIpConfKey(superUser.getShortUserName()));
145-
146-
if (ipList != null && !ipList.isEmpty()) {
147+
148+
if (isWildcardList(ipList)) {
149+
ipAuthorized = true;
150+
} else if (ipList != null && !ipList.isEmpty()) {
147151
for (String allowedHost : ipList) {
148152
InetAddress hostAddr;
149153
try {
@@ -162,4 +166,15 @@ public static synchronized void authorize(UserGroupInformation user,
162166
+ superUser.getUserName() + " from IP " + remoteAddress);
163167
}
164168
}
169+
170+
/**
171+
* Return true if the configuration specifies the special configuration value
172+
* "*", indicating that any group or host list is allowed to use this configuration.
173+
*/
174+
private static boolean isWildcardList(Collection<String> list) {
175+
return (list != null) &&
176+
(list.size() == 1) &&
177+
(list.contains("*"));
178+
}
179+
165180
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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 java.util.Arrays;
21+
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.util.StringUtils;
23+
import org.apache.hadoop.security.UserGroupInformation;
24+
25+
import org.junit.Test;
26+
import static org.junit.Assert.*;
27+
28+
public class TestProxyUsers {
29+
private static final String REAL_USER_NAME = "proxier";
30+
private static final String PROXY_USER_NAME = "proxied_user";
31+
private static final String[] GROUP_NAMES =
32+
new String[] { "foo_group" };
33+
private static final String[] OTHER_GROUP_NAMES =
34+
new String[] { "bar_group" };
35+
private static final String PROXY_IP = "1.2.3.4";
36+
37+
@Test
38+
public void testProxyUsers() throws Exception {
39+
Configuration conf = new Configuration();
40+
conf.set(
41+
ProxyUsers.getProxySuperuserGroupConfKey(REAL_USER_NAME),
42+
StringUtils.join(",", Arrays.asList(GROUP_NAMES)));
43+
conf.set(
44+
ProxyUsers.getProxySuperuserIpConfKey(REAL_USER_NAME),
45+
PROXY_IP);
46+
ProxyUsers.refreshSuperUserGroupsConfiguration(conf);
47+
48+
49+
// First try proxying a group that's allowed
50+
UserGroupInformation realUserUgi = UserGroupInformation
51+
.createRemoteUser(REAL_USER_NAME);
52+
UserGroupInformation proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
53+
PROXY_USER_NAME, realUserUgi, GROUP_NAMES);
54+
55+
// From good IP
56+
assertAuthorized(proxyUserUgi, "1.2.3.4");
57+
// From bad IP
58+
assertNotAuthorized(proxyUserUgi, "1.2.3.5");
59+
60+
// Now try proxying a group that's not allowed
61+
realUserUgi = UserGroupInformation.createRemoteUser(REAL_USER_NAME);
62+
proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
63+
PROXY_USER_NAME, realUserUgi, OTHER_GROUP_NAMES);
64+
65+
// From good IP
66+
assertNotAuthorized(proxyUserUgi, "1.2.3.4");
67+
// From bad IP
68+
assertNotAuthorized(proxyUserUgi, "1.2.3.5");
69+
}
70+
71+
@Test
72+
public void testWildcardGroup() {
73+
Configuration conf = new Configuration();
74+
conf.set(
75+
ProxyUsers.getProxySuperuserGroupConfKey(REAL_USER_NAME),
76+
"*");
77+
conf.set(
78+
ProxyUsers.getProxySuperuserIpConfKey(REAL_USER_NAME),
79+
PROXY_IP);
80+
ProxyUsers.refreshSuperUserGroupsConfiguration(conf);
81+
82+
// First try proxying a group that's allowed
83+
UserGroupInformation realUserUgi = UserGroupInformation
84+
.createRemoteUser(REAL_USER_NAME);
85+
UserGroupInformation proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
86+
PROXY_USER_NAME, realUserUgi, GROUP_NAMES);
87+
88+
// From good IP
89+
assertAuthorized(proxyUserUgi, "1.2.3.4");
90+
// From bad IP
91+
assertNotAuthorized(proxyUserUgi, "1.2.3.5");
92+
93+
// Now try proxying a different group (just to make sure we aren't getting spill over
94+
// from the other test case!)
95+
realUserUgi = UserGroupInformation.createRemoteUser(REAL_USER_NAME);
96+
proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
97+
PROXY_USER_NAME, realUserUgi, OTHER_GROUP_NAMES);
98+
99+
// From good IP
100+
assertAuthorized(proxyUserUgi, "1.2.3.4");
101+
// From bad IP
102+
assertNotAuthorized(proxyUserUgi, "1.2.3.5");
103+
}
104+
105+
@Test
106+
public void testWildcardIP() {
107+
Configuration conf = new Configuration();
108+
conf.set(
109+
ProxyUsers.getProxySuperuserGroupConfKey(REAL_USER_NAME),
110+
StringUtils.join(",", Arrays.asList(GROUP_NAMES)));
111+
conf.set(
112+
ProxyUsers.getProxySuperuserIpConfKey(REAL_USER_NAME),
113+
"*");
114+
ProxyUsers.refreshSuperUserGroupsConfiguration(conf);
115+
116+
// First try proxying a group that's allowed
117+
UserGroupInformation realUserUgi = UserGroupInformation
118+
.createRemoteUser(REAL_USER_NAME);
119+
UserGroupInformation proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
120+
PROXY_USER_NAME, realUserUgi, GROUP_NAMES);
121+
122+
// From either IP should be fine
123+
assertAuthorized(proxyUserUgi, "1.2.3.4");
124+
assertAuthorized(proxyUserUgi, "1.2.3.5");
125+
126+
// Now set up an unallowed group
127+
realUserUgi = UserGroupInformation.createRemoteUser(REAL_USER_NAME);
128+
proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
129+
PROXY_USER_NAME, realUserUgi, OTHER_GROUP_NAMES);
130+
131+
// Neither IP should be OK
132+
assertNotAuthorized(proxyUserUgi, "1.2.3.4");
133+
assertNotAuthorized(proxyUserUgi, "1.2.3.5");
134+
}
135+
136+
private void assertNotAuthorized(UserGroupInformation proxyUgi, String host) {
137+
try {
138+
ProxyUsers.authorize(proxyUgi, host, null);
139+
fail("Allowed authorization of " + proxyUgi + " from " + host);
140+
} catch (AuthorizationException e) {
141+
// Expected
142+
}
143+
}
144+
145+
private void assertAuthorized(UserGroupInformation proxyUgi, String host) {
146+
try {
147+
ProxyUsers.authorize(proxyUgi, host, null);
148+
} catch (AuthorizationException e) {
149+
fail("Did not allowed authorization of " + proxyUgi + " from " + host);
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)