HADOOP-13707. If kerberos is enabled while HTTP SPNEGO is not configured, some links cannot be accessed. Contributed by Yuanbo Liu.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/dbb133cc Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/dbb133cc Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/dbb133cc Branch: refs/heads/YARN-4752 Commit: dbb133ccfc00e20622a5dbf7a6e1126fb63d7487 Parents: 026b39a Author: Brahma Reddy Battula <[email protected]> Authored: Tue Nov 8 20:52:36 2016 +0530 Committer: Brahma Reddy Battula <[email protected]> Committed: Tue Nov 8 20:55:10 2016 +0530 ---------------------------------------------------------------------- .../org/apache/hadoop/conf/ConfServlet.java | 8 ++++- .../hadoop/http/AdminAuthorizedServlet.java | 11 +++++-- .../org/apache/hadoop/http/HttpServer2.java | 32 ++++++++++++++++++-- .../org/apache/hadoop/jmx/JMXJsonServlet.java | 8 ++++- .../java/org/apache/hadoop/log/LogLevel.java | 11 +++++-- .../org/apache/hadoop/http/TestHttpServer.java | 17 ++++++++++- 6 files changed, 75 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/dbb133cc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java index cdc9581..cfd7b97 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java @@ -20,6 +20,7 @@ package org.apache.hadoop.conf; import java.io.IOException; import java.io.Writer; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -58,7 +59,12 @@ public class ConfServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!HttpServer2.isInstrumentationAccessAllowed(getServletContext(), + // If user is a static user and auth Type is null, that means + // there is a non-security environment and no need authorization, + // otherwise, do the authorization. + final ServletContext servletContext = getServletContext(); + if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && + !HttpServer2.isInstrumentationAccessAllowed(servletContext, request, response)) { return; } http://git-wip-us.apache.org/repos/asf/hadoop/blob/dbb133cc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/AdminAuthorizedServlet.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/AdminAuthorizedServlet.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/AdminAuthorizedServlet.java index a4b05a1..456e89f 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/AdminAuthorizedServlet.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/AdminAuthorizedServlet.java @@ -19,6 +19,7 @@ package org.apache.hadoop.http; import java.io.IOException; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -35,9 +36,13 @@ public class AdminAuthorizedServlet extends DefaultServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - // Do the authorization - if (HttpServer2.hasAdministratorAccess(getServletContext(), request, + throws ServletException, IOException { + // If user is a static user and auth Type is null, that means + // there is a non-security environment and no need authorization, + // otherwise, do the authorization. + final ServletContext servletContext = getServletContext(); + if (HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) || + HttpServer2.hasAdministratorAccess(servletContext, request, response)) { // Authorization is done. Just call super. super.doGet(request, response); http://git-wip-us.apache.org/repos/asf/hadoop/blob/dbb133cc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java index 49ec90a..b930f75 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java @@ -98,6 +98,9 @@ import com.google.common.collect.Lists; import com.sun.jersey.spi.container.servlet.ServletContainer; import org.eclipse.jetty.util.ssl.SslContextFactory; +import static org.apache.hadoop.fs.CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER; +import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_HTTP_STATIC_USER; + /** * Create a Jetty embedded server to answer http requests. The primary goal is * to serve up status information for the server. There are three contexts: @@ -1112,6 +1115,24 @@ public final class HttpServer2 implements FilterContainer { } /** + * check whether user is static and unauthenticated, if the + * answer is TRUE, that means http sever is in non-security + * environment. + * @param servletContext the servlet context. + * @param request the servlet request. + * @return TRUE/FALSE based on the logic described above. + */ + public static boolean isStaticUserAndNoneAuthType( + ServletContext servletContext, HttpServletRequest request) { + Configuration conf = + (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE); + final String authType = request.getAuthType(); + final String staticUser = conf.get(HADOOP_HTTP_STATIC_USER, + DEFAULT_HADOOP_HTTP_STATIC_USER); + return authType == null && staticUser.equals(request.getRemoteUser()); + } + + /** * Checks the user has privileges to access to instrumentation servlets. * <p/> * If <code>hadoop.security.instrumentation.requires.admin</code> is set to FALSE @@ -1208,9 +1229,14 @@ public final class HttpServer2 implements FilterContainer { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - if (!HttpServer2.isInstrumentationAccessAllowed(getServletContext(), - request, response)) { + throws ServletException, IOException { + // If user is a static user and auth Type is null, that means + // there is a non-security environment and no need authorization, + // otherwise, do the authorization. + final ServletContext servletContext = getServletContext(); + if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && + !HttpServer2.isInstrumentationAccessAllowed(servletContext, + request, response)) { return; } response.setContentType("text/plain; charset=UTF-8"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/dbb133cc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServlet.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServlet.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServlet.java index b6ec7bc..05434d6 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServlet.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/jmx/JMXJsonServlet.java @@ -38,6 +38,7 @@ import javax.management.RuntimeMBeanException; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeType; import javax.management.openmbean.TabularData; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -168,7 +169,12 @@ public class JMXJsonServlet extends HttpServlet { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) { try { - if (!isInstrumentationAccessAllowed(request, response)) { + // If user is a static user and auth Type is null, that means + // there is a non-security environment and no need authorization, + // otherwise, do the authorization. + final ServletContext servletContext = getServletContext(); + if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && + !isInstrumentationAccessAllowed(request, response)) { return; } JsonGenerator jg = null; http://git-wip-us.apache.org/repos/asf/hadoop/blob/dbb133cc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java index 79eae12..8802f83 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSocketFactory; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -323,9 +324,13 @@ public class LogLevel { public void doGet(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { - // Do the authorization - if (!HttpServer2.hasAdministratorAccess(getServletContext(), request, - response)) { + // If user is a static user and auth Type is null, that means + // there is a non-security environment and no need authorization, + // otherwise, do the authorization. + final ServletContext servletContext = getServletContext(); + if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && + !HttpServer2.hasAdministratorAccess(servletContext, + request, response)) { return; } http://git-wip-us.apache.org/repos/asf/hadoop/blob/dbb133cc/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java index a36e8ca..bac3fbb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java @@ -67,6 +67,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import static org.apache.hadoop.fs.CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER; +import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_HTTP_STATIC_USER; + public class TestHttpServer extends HttpServerFunctionalTest { static final Log LOG = LogFactory.getLog(TestHttpServer.class); private static HttpServer2 server; @@ -459,7 +462,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { String serverURL = "http://" + NetUtils.getHostPortString(myServer.getConnectorAddress(0)) + "/"; for (String servlet : new String[] { "conf", "logs", "stacks", - "logLevel" }) { + "logLevel", "jmx" }) { for (String user : new String[] { "userA", "userB", "userC", "userD" }) { assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode(serverURL + servlet, user)); @@ -467,6 +470,18 @@ public class TestHttpServer extends HttpServerFunctionalTest { assertEquals(HttpURLConnection.HTTP_FORBIDDEN, getHttpStatusCode( serverURL + servlet, "userE")); } + + // hadoop.security.authorization is set as true while + // hadoop.http.authentication.type's value is `simple`(default value) + // in this case, static user has administrator access + final String staticUser = conf.get(HADOOP_HTTP_STATIC_USER, + DEFAULT_HADOOP_HTTP_STATIC_USER); + for (String servlet : new String[] {"conf", "logs", "stacks", + "logLevel", "jmx"}) { + assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode( + serverURL + servlet, staticUser)); + } + myServer.stop(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
