From 401ae4ecdb64e1ae2730976f96f7949831305c07 Mon Sep 17 00:00:00 2001 From: Allen Wittenauer Date: Tue, 9 Feb 2016 14:15:21 -0800 Subject: [PATCH] HDFS-9760. WebHDFS AuthFilter cannot be configured with custom AltKerberos auth handler (Ryan Sasson via aw) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/NameNodeHttpServer.java | 11 +++++++++++ .../org/apache/hadoop/hdfs/web/AuthFilter.java | 10 ++++++---- .../apache/hadoop/hdfs/web/TestAuthFilter.java | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 670a9f8da5a..875799a520c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -2715,6 +2715,9 @@ Release 2.8.0 - UNRELEASED HDFS-9713. DataXceiver#copyBlock should return if block is pinned. (umamahesh) + HDFS-9760. WebHDFS AuthFilter cannot be configured with custom AltKerberos + auth handler (Ryan Sasson via aw) + Release 2.7.3 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java index 8f112bd6a2d..55cf00f8820 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeHttpServer.java @@ -21,7 +21,9 @@ package org.apache.hadoop.hdfs.server.namenode; import java.io.IOException; import java.net.InetSocketAddress; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import javax.servlet.ServletContext; @@ -34,6 +36,7 @@ import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.hdfs.server.common.JspHelper; import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress; import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods; +import org.apache.hadoop.hdfs.web.AuthFilter; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; import org.apache.hadoop.hdfs.web.resources.Param; import org.apache.hadoop.hdfs.web.resources.UserParam; @@ -158,6 +161,14 @@ public class NameNodeHttpServer { private Map getAuthFilterParams(Configuration conf) throws IOException { Map params = new HashMap(); + // Select configs beginning with 'dfs.web.authentication.' + Iterator> iterator = conf.iterator(); + while (iterator.hasNext()) { + Entry kvPair = iterator.next(); + if (kvPair.getKey().startsWith(AuthFilter.CONF_PREFIX)) { + params.put(kvPair.getKey(), kvPair.getValue()); + } + } String principalInConf = conf .get(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY); if (principalInConf != null && !principalInConf.isEmpty()) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/AuthFilter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/AuthFilter.java index 5ad1f2464ed..a8b7bd434b8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/AuthFilter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/AuthFilter.java @@ -46,7 +46,7 @@ import org.apache.hadoop.util.StringUtils; * obtains Hadoop-Auth configuration for webhdfs. */ public class AuthFilter extends AuthenticationFilter { - private static final String CONF_PREFIX = "dfs.web.authentication."; + public static final String CONF_PREFIX = "dfs.web.authentication."; /** * Returns the filter configuration properties, @@ -62,9 +62,11 @@ public class AuthFilter extends AuthenticationFilter { protected Properties getConfiguration(String prefix, FilterConfig config) throws ServletException { final Properties p = super.getConfiguration(CONF_PREFIX, config); - // set authentication type - p.setProperty(AUTH_TYPE, UserGroupInformation.isSecurityEnabled()? - KerberosAuthenticationHandler.TYPE: PseudoAuthenticationHandler.TYPE); + // if not set, configure based on security enabled + if (p.getProperty(AUTH_TYPE) == null) { + p.setProperty(AUTH_TYPE, UserGroupInformation.isSecurityEnabled()? + KerberosAuthenticationHandler.TYPE: PseudoAuthenticationHandler.TYPE); + } // if not set, enable anonymous for pseudo authentication if (p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED) == null) { p.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, "true"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestAuthFilter.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestAuthFilter.java index b19a08a2d35..98184618088 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestAuthFilter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestAuthFilter.java @@ -98,4 +98,19 @@ public class TestAuthFilter { Assert.assertEquals("true", p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED)); } + + @Test + public void testGetCustomAuthConfiguration() throws ServletException { + AuthFilter filter = new AuthFilter(); + Map m = new HashMap(); + + m.put(AuthFilter.CONF_PREFIX + AuthFilter.AUTH_TYPE, "com.yourclass"); + m.put(AuthFilter.CONF_PREFIX + "alt-kerberos.param", "value"); + FilterConfig config = new DummyFilterConfig(m); + + Properties p = filter.getConfiguration(AuthFilter.CONF_PREFIX, config); + Assert.assertEquals("com.yourclass", p.getProperty(AuthFilter.AUTH_TYPE)); + Assert.assertEquals("value", p.getProperty("alt-kerberos.param")); + } + }