@@ -104,7 +104,9 @@ public static void tearDown() {
104
104
*/
105
105
@ Test
106
106
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 ());
108
110
109
111
//setup logs dir
110
112
System .setProperty ("hadoop.log.dir" , testRootDir .getAbsolutePath ());
@@ -118,15 +120,15 @@ public void testAuthenticationWithProxyUser() throws Exception {
118
120
new String []{"groupC" });
119
121
120
122
// 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 );
124
126
125
127
HttpServer2 httpServer = null ;
126
128
try {
127
129
// Create http server to test.
128
130
httpServer = getCommonBuilder ()
129
- .setConf (spengoConf )
131
+ .setConf (spnegoConf )
130
132
.setACL (new AccessControlList ("userA groupA" ))
131
133
.build ();
132
134
httpServer .start ();
@@ -191,6 +193,48 @@ public void testAuthenticationWithProxyUser() throws Exception {
191
193
}
192
194
}
193
195
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
+
194
238
private AuthenticatedURL .Token getEncryptedAuthToken (Signer signer ,
195
239
String user ) throws Exception {
196
240
AuthenticationToken token =
@@ -209,10 +253,8 @@ private Signer getSignerToEncrypt() throws Exception {
209
253
return new Signer (secretProvider );
210
254
}
211
255
212
- private Configuration getSpengoConf (Configuration conf ) {
256
+ private Configuration getSpnegoConf (Configuration conf ) {
213
257
conf = new Configuration ();
214
- conf .set (HttpServer2 .FILTER_INITIALIZER_PROPERTY ,
215
- ProxyUserAuthenticationFilterInitializer .class .getName ());
216
258
conf .set (PREFIX + "type" , "kerberos" );
217
259
conf .setBoolean (PREFIX + "simple.anonymous.allowed" , false );
218
260
conf .set (PREFIX + "signature.secret.file" ,
0 commit comments