Skip to content

Commit b051971

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 b051971

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-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: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public static void tearDown() {
104104
*/
105105
@Test
106106
public void testAuthenticationWithProxyUser() throws Exception {
107-
Configuration spengoConf = getSpengoConf(new Configuration());
107+
Configuration spnegoConf = getSpnegoConf(new Configuration());
108+
spnegoConf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
109+
ProxyUserAuthenticationFilterInitializer.class.getName());
108110

109111
//setup logs dir
110112
System.setProperty("hadoop.log.dir", testRootDir.getAbsolutePath());
@@ -118,15 +120,15 @@ public void testAuthenticationWithProxyUser() throws Exception {
118120
new String[]{"groupC"});
119121

120122
// 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);
123+
spnegoConf.set("hadoop.proxyuser.userA.hosts", "*");
124+
spnegoConf.set("hadoop.proxyuser.userA.groups", "groupB");
125+
ProxyUsers.refreshSuperUserGroupsConfiguration(spnegoConf);
124126

125127
HttpServer2 httpServer = null;
126128
try {
127129
// Create http server to test.
128130
httpServer = getCommonBuilder()
129-
.setConf(spengoConf)
131+
.setConf(spnegoConf)
130132
.setACL(new AccessControlList("userA groupA"))
131133
.build();
132134
httpServer.start();
@@ -191,6 +193,48 @@ public void testAuthenticationWithProxyUser() throws Exception {
191193
}
192194
}
193195

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

212-
private Configuration getSpengoConf(Configuration conf) {
256+
private Configuration getSpnegoConf(Configuration conf) {
213257
conf = new Configuration();
214-
conf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
215-
ProxyUserAuthenticationFilterInitializer.class.getName());
216258
conf.set(PREFIX + "type", "kerberos");
217259
conf.setBoolean(PREFIX + "simple.anonymous.allowed", false);
218260
conf.set(PREFIX + "signature.secret.file",

0 commit comments

Comments
 (0)