19
19
20
20
import org .apache .hadoop .conf .Configuration ;
21
21
import org .apache .hadoop .fs .CommonConfigurationKeys ;
22
+ import org .apache .hadoop .fs .CommonConfigurationKeysPublic ;
22
23
import org .apache .hadoop .minikdc .MiniKdc ;
23
24
import org .apache .hadoop .net .NetUtils ;
25
+ import org .apache .hadoop .security .AuthenticationFilterInitializer ;
24
26
import org .apache .hadoop .security .UserGroupInformation ;
25
27
import org .apache .hadoop .security .authentication .KerberosTestUtils ;
26
28
import org .apache .hadoop .security .authentication .client .AuthenticatedURL ;
@@ -104,7 +106,9 @@ public static void tearDown() {
104
106
*/
105
107
@ Test
106
108
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 ());
108
112
109
113
//setup logs dir
110
114
System .setProperty ("hadoop.log.dir" , testRootDir .getAbsolutePath ());
@@ -118,15 +122,15 @@ public void testAuthenticationWithProxyUser() throws Exception {
118
122
new String []{"groupC" });
119
123
120
124
// 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 );
124
128
125
129
HttpServer2 httpServer = null ;
126
130
try {
127
131
// Create http server to test.
128
132
httpServer = getCommonBuilder ()
129
- .setConf (spengoConf )
133
+ .setConf (spnegoConf )
130
134
.setACL (new AccessControlList ("userA groupA" ))
131
135
.build ();
132
136
httpServer .start ();
@@ -191,6 +195,48 @@ public void testAuthenticationWithProxyUser() throws Exception {
191
195
}
192
196
}
193
197
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
+
194
240
private AuthenticatedURL .Token getEncryptedAuthToken (Signer signer ,
195
241
String user ) throws Exception {
196
242
AuthenticationToken token =
@@ -209,10 +255,8 @@ private Signer getSignerToEncrypt() throws Exception {
209
255
return new Signer (secretProvider );
210
256
}
211
257
212
- private Configuration getSpengoConf (Configuration conf ) {
258
+ private Configuration getSpnegoConf (Configuration conf ) {
213
259
conf = new Configuration ();
214
- conf .set (HttpServer2 .FILTER_INITIALIZER_PROPERTY ,
215
- ProxyUserAuthenticationFilterInitializer .class .getName ());
216
260
conf .set (PREFIX + "type" , "kerberos" );
217
261
conf .setBoolean (PREFIX + "simple.anonymous.allowed" , false );
218
262
conf .set (PREFIX + "signature.secret.file" ,
0 commit comments