Skip to content

Commit 2f79e36

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 2f79e36

File tree

2 files changed

+74
-10
lines changed

2 files changed

+74
-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,
1349+
String usernameConfKey, String keytabConfKey) 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: 63 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,61 @@ 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[] {
200+
"/jmx",
201+
"/prom"
202+
};
203+
String[] denyList = new String[] {
204+
"/conf",
205+
"/stacks",
206+
"/logLevel"
207+
};
208+
spnegoConf.set(PREFIX + "kerberos.endpoint.whitelist", String.join(",", allowList));
209+
spnegoConf.set("hadoop.prometheus.endpoint.enabled", "true");
210+
spnegoConf.set("hadoop.http.filter.initializers",
211+
"org.apache.hadoop.security.AuthenticationFilterInitializer");
212+
213+
//setup logs dir
214+
System.setProperty("hadoop.log.dir", testRootDir.getAbsolutePath());
215+
216+
HttpServer2 httpServer = null;
217+
try {
218+
// Create http server to test.
219+
httpServer = getCommonBuilder()
220+
.setConf(spnegoConf)
221+
.setSecurityEnabled(true)
222+
.setUsernameConfKey(PREFIX + "kerberos.principal")
223+
.setKeytabConfKey(PREFIX + "kerberos.keytab")
224+
.build();
225+
httpServer.start();
226+
227+
String serverURL = "http://" +
228+
NetUtils.getHostPortString(httpServer.getConnectorAddress(0));
229+
230+
// endpoints in whitelist should not require Kerberos authentication
231+
for (String endpoint :
232+
allowList) {
233+
HttpURLConnection conn = (HttpURLConnection) new URL(serverURL + endpoint).openConnection();
234+
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
235+
}
236+
237+
// endpoints not in whitelist should require Kerberos authentication
238+
for (String endpoint :
239+
denyList) {
240+
HttpURLConnection conn = (HttpURLConnection) new URL(serverURL + endpoint).openConnection();
241+
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, conn.getResponseCode());
242+
}
243+
244+
} finally {
245+
if (httpServer != null) {
246+
httpServer.stop();
247+
}
248+
}
249+
}
250+
194251
private AuthenticatedURL.Token getEncryptedAuthToken(Signer signer,
195252
String user) throws Exception {
196253
AuthenticationToken token =
@@ -209,10 +266,8 @@ private Signer getSignerToEncrypt() throws Exception {
209266
return new Signer(secretProvider);
210267
}
211268

212-
private Configuration getSpengoConf(Configuration conf) {
269+
private Configuration getSpnegoConf(Configuration conf) {
213270
conf = new Configuration();
214-
conf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
215-
ProxyUserAuthenticationFilterInitializer.class.getName());
216271
conf.set(PREFIX + "type", "kerberos");
217272
conf.setBoolean(PREFIX + "simple.anonymous.allowed", false);
218273
conf.set(PREFIX + "signature.secret.file",

0 commit comments

Comments
 (0)