stoty commented on a change in pull request #1576: URL: https://github.com/apache/hbase/pull/1576#discussion_r415588683
########## File path: hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestProxyUserSpnegoHttpServer.java ########## @@ -0,0 +1,262 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.http; + +import java.io.File; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.Principal; +import java.security.PrivilegedExceptionAction; +import java.util.Set; + +import javax.security.auth.Subject; +import javax.security.auth.kerberos.KerberosTicket; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; +import org.apache.hadoop.hbase.http.TestHttpServer.EchoServlet; +import org.apache.hadoop.hbase.http.resource.JerseyResource; +import org.apache.hadoop.hbase.testclassification.MiscTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.security.authentication.util.KerberosName; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthSchemeProvider; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.KerberosCredentials; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.AuthSchemes; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.config.Lookup; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.impl.auth.SPNegoSchemeFactory; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.apache.kerby.kerberos.kerb.KrbException; +import org.apache.kerby.kerberos.kerb.client.JaasKrbUtil; +import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer; +import org.ietf.jgss.GSSCredential; +import org.ietf.jgss.GSSManager; +import org.ietf.jgss.GSSName; +import org.ietf.jgss.Oid; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for SPNEGO Proxyuser authentication on the HttpServer. Uses Kerby's MiniKDC and Apache + * HttpComponents to verify that the doas= mechanicsm works, and that the proxyuser settings are + * observed + */ +@Category({MiscTests.class, SmallTests.class}) +public class TestProxyUserSpnegoHttpServer extends HttpServerFunctionalTest { + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestProxyUserSpnegoHttpServer.class); + + private static final Logger LOG = LoggerFactory.getLogger(TestProxyUserSpnegoHttpServer.class); + private static final String KDC_SERVER_HOST = "localhost"; + private static final String WHEEL_PRINCIPAL = "wheel"; + private static final String STANDARD_PRINCIPAL = "standard"; + private static final String DOAS_PRINCIPAL = "doas"; + + private static HttpServer server; + private static URL baseUrl; + private static SimpleKdcServer kdc; + private static File infoServerKeytab; + private static File wheelKeytab; + private static File standardKeytab; + private static File doasKeytab; + + @BeforeClass + public static void setupServer() throws Exception { + Configuration conf = new Configuration(); + HBaseCommonTestingUtility htu = new HBaseCommonTestingUtility(conf); + + final String serverPrincipal = "HTTP/" + KDC_SERVER_HOST; + + kdc = buildMiniKdc(); + kdc.start(); + File keytabDir = new File(htu.getDataTestDir("keytabs").toString()); + if (keytabDir.exists()) { + deleteRecursively(keytabDir); + } + keytabDir.mkdirs(); + + infoServerKeytab = new File(keytabDir, serverPrincipal.replace('/', '_') + ".keytab"); + wheelKeytab = new File(keytabDir, WHEEL_PRINCIPAL + ".keytab"); + standardKeytab = new File(keytabDir, STANDARD_PRINCIPAL + ".keytab"); + doasKeytab = new File(keytabDir, DOAS_PRINCIPAL + ".keytab"); + + setupUser(kdc, wheelKeytab, WHEEL_PRINCIPAL); + setupUser(kdc, standardKeytab, STANDARD_PRINCIPAL); + setupUser(kdc, doasKeytab, DOAS_PRINCIPAL); + setupUser(kdc, infoServerKeytab, serverPrincipal); + + buildSpnegoConfiguration(conf, serverPrincipal, infoServerKeytab); + + server = createTestServerWithSecurity(conf); + server.addPrivilegedServlet("echo", "/echo", EchoServlet.class); Review comment: Done. We have four combinations of privileged/allowed to sudo, I have addedd tests for three of those. I think that there is no point trying to unsuccessfully sudo to an unprivileged user, as that would fail the same way as trying to sudo unsuccessfully to a privileged user. Adding the new test uncovered a problem in the test setup, I've fixed that as well. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
