1919
2020import org .apache .hadoop .conf .Configuration ;
2121import org .apache .hadoop .fs .CommonConfigurationKeys ;
22+ import org .apache .hadoop .fs .CommonConfigurationKeysPublic ;
2223import org .apache .hadoop .minikdc .MiniKdc ;
2324import org .apache .hadoop .net .NetUtils ;
25+ import org .apache .hadoop .security .AuthenticationFilterInitializer ;
2426import org .apache .hadoop .security .UserGroupInformation ;
2527import org .apache .hadoop .security .authentication .KerberosTestUtils ;
2628import 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