Skip to content

Commit 61b8153

Browse files
committed
HADOOP-18666. A whitelist of endpoints to skip Kerberos authentication doesn't work for ResourceManager and Job History Server
1 parent eee2ea0 commit 61b8153

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,12 @@ public HttpServer2 build() throws IOException {
497497
prefix -> this.conf.get(prefix + "type")
498498
.equals(PseudoAuthenticationHandler.TYPE))
499499
) {
500-
server.initSpnego(conf, hostName, usernameConfKey, keytabConfKey);
500+
server.initSpnego(
501+
conf,
502+
hostName,
503+
getFilterProperties(conf, authFilterConfigurationPrefixes),
504+
usernameConfKey,
505+
keytabConfKey);
501506
}
502507

503508
for (URI ep : endpoints) {
@@ -1340,8 +1345,12 @@ public void setThreads(int min, int max) {
13401345
}
13411346

13421347
private void initSpnego(Configuration conf, String hostName,
1343-
String usernameConfKey, String keytabConfKey) throws IOException {
1348+
Properties authFilterConfigurationPrefixes, String usernameConfKey, String keytabConfKey)
1349+
throws IOException {
13441350
Map<String, String> params = new HashMap<>();
1351+
for (Map.Entry<Object, Object> entry : authFilterConfigurationPrefixes.entrySet()) {
1352+
params.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
1353+
}
13451354
String principalInConf = conf.get(usernameConfKey);
13461355
if (principalInConf != null && !principalInConf.isEmpty()) {
13471356
params.put("kerberos.principal", SecurityUtil.getServerPrincipal(

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServerWithSpnego.java

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.fs.CommonConfigurationKeys;
22+
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
2223
import org.apache.hadoop.minikdc.MiniKdc;
2324
import org.apache.hadoop.net.NetUtils;
25+
import org.apache.hadoop.security.AuthenticationFilterInitializer;
2426
import org.apache.hadoop.security.UserGroupInformation;
2527
import org.apache.hadoop.security.authentication.KerberosTestUtils;
2628
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
@@ -104,7 +106,9 @@ public static void tearDown() {
104106
*/
105107
@Test
106108
public void testAuthenticationWithProxyUser() throws Exception {
107-
Configuration spengoConf = getSpengoConf(new Configuration());
109+
Configuration spnegoConf = getSpnegoConf(new Configuration());
110+
spnegoConf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
111+
ProxyUserAuthenticationFilterInitializer.class.getName());
108112

109113
//setup logs dir
110114
System.setProperty("hadoop.log.dir", testRootDir.getAbsolutePath());
@@ -118,15 +122,15 @@ public void testAuthenticationWithProxyUser() throws Exception {
118122
new String[]{"groupC"});
119123

120124
// Make userA impersonate users in groupB
121-
spengoConf.set("hadoop.proxyuser.userA.hosts", "*");
122-
spengoConf.set("hadoop.proxyuser.userA.groups", "groupB");
123-
ProxyUsers.refreshSuperUserGroupsConfiguration(spengoConf);
125+
spnegoConf.set("hadoop.proxyuser.userA.hosts", "*");
126+
spnegoConf.set("hadoop.proxyuser.userA.groups", "groupB");
127+
ProxyUsers.refreshSuperUserGroupsConfiguration(spnegoConf);
124128

125129
HttpServer2 httpServer = null;
126130
try {
127131
// Create http server to test.
128132
httpServer = getCommonBuilder()
129-
.setConf(spengoConf)
133+
.setConf(spnegoConf)
130134
.setACL(new AccessControlList("userA groupA"))
131135
.build();
132136
httpServer.start();
@@ -191,6 +195,48 @@ public void testAuthenticationWithProxyUser() throws Exception {
191195
}
192196
}
193197

198+
@Test
199+
public void testAuthenticationToAllowList() throws Exception {
200+
Configuration spnegoConf = getSpnegoConf(new Configuration());
201+
String[] allowList = new String[] {"/jmx", "/prom"};
202+
String[] denyList = new String[] {"/conf", "/stacks", "/logLevel"};
203+
spnegoConf.set(PREFIX + "kerberos.endpoint.whitelist", String.join(",", allowList));
204+
spnegoConf.set(CommonConfigurationKeysPublic.HADOOP_PROMETHEUS_ENABLED, "true");
205+
spnegoConf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
206+
AuthenticationFilterInitializer.class.getName());
207+
208+
//setup logs dir
209+
System.setProperty("hadoop.log.dir", testRootDir.getAbsolutePath());
210+
211+
HttpServer2 httpServer = null;
212+
try {
213+
// Create http server to test.
214+
httpServer = getCommonBuilder().setConf(spnegoConf).setSecurityEnabled(true)
215+
.setUsernameConfKey(PREFIX + "kerberos.principal")
216+
.setKeytabConfKey(PREFIX + "kerberos.keytab").build();
217+
httpServer.start();
218+
219+
String serverURL = "http://" + NetUtils.getHostPortString(httpServer.getConnectorAddress(0));
220+
221+
// endpoints in whitelist should not require Kerberos authentication
222+
for (String endpoint : allowList) {
223+
HttpURLConnection conn = (HttpURLConnection) new URL(serverURL + endpoint).openConnection();
224+
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
225+
}
226+
227+
// endpoints not in whitelist should require Kerberos authentication
228+
for (String endpoint : denyList) {
229+
HttpURLConnection conn = (HttpURLConnection) new URL(serverURL + endpoint).openConnection();
230+
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, conn.getResponseCode());
231+
}
232+
233+
} finally {
234+
if (httpServer != null) {
235+
httpServer.stop();
236+
}
237+
}
238+
}
239+
194240
private AuthenticatedURL.Token getEncryptedAuthToken(Signer signer,
195241
String user) throws Exception {
196242
AuthenticationToken token =
@@ -209,10 +255,8 @@ private Signer getSignerToEncrypt() throws Exception {
209255
return new Signer(secretProvider);
210256
}
211257

212-
private Configuration getSpengoConf(Configuration conf) {
258+
private Configuration getSpnegoConf(Configuration conf) {
213259
conf = new Configuration();
214-
conf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
215-
ProxyUserAuthenticationFilterInitializer.class.getName());
216260
conf.set(PREFIX + "type", "kerberos");
217261
conf.setBoolean(PREFIX + "simple.anonymous.allowed", false);
218262
conf.set(PREFIX + "signature.secret.file",

0 commit comments

Comments
 (0)