Skip to content

Commit 002b3f6

Browse files
committed
HBASE-27693 Support for Hadoop's LDAP Authentication mechanism
1 parent 735fb43 commit 002b3f6

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.http;
19+
20+
import java.io.IOException;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import org.apache.hadoop.conf.Configuration;
24+
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
25+
import org.apache.hadoop.security.SecurityUtil;
26+
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
27+
import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
28+
import org.apache.yetus.audience.InterfaceAudience;
29+
30+
/**
31+
* Initializes hadoop-auth AuthenticationFilter which provides support for Kerberos HTTP SPNEGO
32+
* authentication.
33+
* <p>
34+
* It enables anonymous access, simple/pseudo and Kerberos HTTP SPNEGO authentication for Hadoop
35+
* JobTracker, NameNode, DataNodes and TaskTrackers.
36+
* <p>
37+
* Refer to the <code>core-default.xml</code> file, after the comment 'HTTP Authentication' for
38+
* details on the configuration options. All related configuration properties have
39+
* 'hadoop.http.authentication.' as prefix.
40+
*/
41+
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
42+
public class AuthenticationFilterInitializer extends FilterInitializer {
43+
44+
static final String PREFIX = "hadoop.http.authentication.";
45+
46+
/**
47+
* Initializes hadoop-auth AuthenticationFilter.
48+
* <p>
49+
* Propagates to hadoop-auth AuthenticationFilter configuration all Hadoop configuration
50+
* properties prefixed with "hadoop.http.authentication."
51+
* @param container The filter container
52+
* @param conf Configuration for run-time parameters
53+
*/
54+
@Override
55+
public void initFilter(FilterContainer container, Configuration conf) {
56+
Map<String, String> filterConfig = getFilterConfigMap(conf, PREFIX);
57+
58+
container.addFilter("authentication", AuthenticationFilter.class.getName(), filterConfig);
59+
}
60+
61+
public static Map<String, String> getFilterConfigMap(Configuration conf, String prefix) {
62+
Map<String, String> filterConfig = new HashMap<String, String>();
63+
64+
// setting the cookie path to root '/' so it is used for all resources.
65+
filterConfig.put(AuthenticationFilter.COOKIE_PATH, "/");
66+
Map<String, String> propsWithPrefix = conf.getPropsWithPrefix(prefix);
67+
68+
for (Map.Entry<String, String> entry : propsWithPrefix.entrySet()) {
69+
filterConfig.put(entry.getKey(), entry.getValue());
70+
}
71+
72+
// Resolve _HOST into bind address
73+
String bindAddress = conf.get(HttpServer.BIND_ADDRESS);
74+
String principal = filterConfig.get(KerberosAuthenticationHandler.PRINCIPAL);
75+
if (principal != null) {
76+
try {
77+
principal = SecurityUtil.getServerPrincipal(principal, bindAddress);
78+
} catch (IOException ex) {
79+
throw new RuntimeException("Could not resolve Kerberos principal name: " + ex.toString(),
80+
ex);
81+
}
82+
filterConfig.put(KerberosAuthenticationHandler.PRINCIPAL, principal);
83+
}
84+
return filterConfig;
85+
}
86+
87+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.http;
19+
20+
import static org.junit.Assert.*;
21+
import static org.mockito.ArgumentMatchers.any;
22+
23+
import java.util.Map;
24+
import org.apache.hadoop.conf.Configuration;
25+
import org.apache.hadoop.hbase.HBaseClassTestRule;
26+
import org.apache.hadoop.hbase.testclassification.MiscTests;
27+
import org.apache.hadoop.hbase.testclassification.SmallTests;
28+
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
29+
import org.junit.ClassRule;
30+
import org.junit.Test;
31+
import org.junit.experimental.categories.Category;
32+
import org.mockito.Mockito;
33+
import org.mockito.invocation.InvocationOnMock;
34+
import org.mockito.stubbing.Answer;
35+
36+
@Category({ MiscTests.class, SmallTests.class })
37+
public class TestAuthenticationFilterInitializer {
38+
@ClassRule
39+
public static final HBaseClassTestRule CLASS_RULE =
40+
HBaseClassTestRule.forClass(TestAuthenticationFilterInitializer.class);
41+
42+
@Test
43+
public void testConfiguration() throws Exception {
44+
Configuration conf = new Configuration();
45+
conf.set("hadoop.http.authentication.foo", "bar");
46+
47+
conf.set(HttpServer.BIND_ADDRESS, "barhost");
48+
49+
FilterContainer container = Mockito.mock(FilterContainer.class);
50+
Mockito.doAnswer(new Answer() {
51+
@Override
52+
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
53+
Object[] args = invocationOnMock.getArguments();
54+
55+
assertEquals("authentication", args[0]);
56+
57+
assertEquals(AuthenticationFilter.class.getName(), args[1]);
58+
59+
Map<String, String> conf = (Map<String, String>) args[2];
60+
assertEquals("/", conf.get("cookie.path"));
61+
62+
assertEquals("simple", conf.get("type"));
63+
assertEquals("36000", conf.get("token.validity"));
64+
assertNull(conf.get("cookie.domain"));
65+
assertEquals("true", conf.get("simple.anonymous.allowed"));
66+
assertEquals("HTTP/barhost@LOCALHOST", conf.get("kerberos.principal"));
67+
assertEquals(System.getProperty("user.home") + "/hadoop.keytab",
68+
conf.get("kerberos.keytab"));
69+
assertEquals("bar", conf.get("foo"));
70+
71+
return null;
72+
}
73+
}).when(container).addFilter(any(), any(), any());
74+
75+
new AuthenticationFilterInitializer().initFilter(container, conf);
76+
}
77+
78+
}

src/main/asciidoc/_chapters/security.adoc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,64 @@ non-sensitive endpoints in the Web UI.
185185

186186
If it doesn't go without saying: non-authenticated users cannot access any part of the Web UI.
187187

188+
[[hbase.secure.ldap.ui]]
189+
=== Using LDAP authentication with Web UIs
190+
191+
LDAP authentication to HBase Web UIs can be enabled via configuring LDAP with the `hbase.security.authentication.ui`
192+
property in _hbase-site.xml_. The `hbase.http.filter.initializers` property also needs to have the `AuthenticationFilterInitializer` class.
193+
194+
*IMPORTANT:* A LDAP server must be configured and running. When TLS is enabled for communication with LDAP server (either via ldaps scheme or ‘start TLS’ extension), configure the public certificate of the LDAP server in the local truststore.
195+
The LDAP authentication mechanism uses HTTP Basic authentication scheme to verify user specified credentials against a configured LDAP (or Active Directory) server. The authentication filter must be configured with the following init parameters:
196+
197+
[source,xml]
198+
----
199+
<property>
200+
<name>hbase.security.authentication.ui</name>
201+
<value>ldap</value>
202+
<description>Controls what kind of authentication should be used for the HBase web UIs.</description>
203+
</property>
204+
<property>
205+
<name>hbase.http.filter.initializers</name>
206+
<value>org.apache.hadoop.hbase.http.AuthenticationFilterInitializer</value>
207+
<description>Comma separated class names corresponding to the Filters that will be initialized.
208+
Then, the Filters will be applied to all user facing jsp and servlet web pages.</description>
209+
</property>
210+
<property>
211+
<name>hadoop.http.authentication.type</name>
212+
<value>ldap</value>
213+
<description>Defines authentication used for the HTTP web-consoles in Hadoop ecosystem.</description>
214+
</property>
215+
----
216+
217+
A number of properties exist to configure LDAP authentication for the web server:
218+
219+
[source,xml]
220+
----
221+
<property>
222+
<name>hadoop.http.authentication.ldap.binddomain</name>
223+
<value>EXAMPLE.COM</value>
224+
<description>The LDAP bind domain value to be used with the LDAP server. This property is optional
225+
and useful only in case of Active Directory server (e.g. example.com).</description>
226+
</property>
227+
<property>
228+
<name>hadoop.http.authentication.ldap.providerurl</name>
229+
<value>ldap://ldap-server-host:8920</value>
230+
<description>The url of the LDAP server.</description>
231+
</property>
232+
<property>
233+
<name>hadoop.http.authentication.ldap.enablestarttls</name>
234+
<value>false</value>
235+
<description>A boolean value used to define if the LDAP server supports ‘StartTLS’ extension.</description>
236+
</property>
237+
<property>
238+
<name>hadoop.http.authentication.ldap.basedn</name>
239+
<value>ou=users,dc=example,dc=com</value>
240+
<description>The base distinguished name (DN) to be used with the LDAP server. This value is
241+
appended to the provided user id for authentication purpose. This property is not useful in case
242+
of Active Directory server.</description>
243+
</property>
244+
----
245+
188246
=== Other UI security-related configuration
189247

190248
While it is a clear anti-pattern for HBase developers, the developers acknowledge that the HBase

0 commit comments

Comments
 (0)