Skip to content

Commit e51fcd2

Browse files
committed
RANGER-5517: remove ranger-plugins-common dependency from kms, embeddedwebserver and shim modules
1 parent 0855b33 commit e51fcd2

34 files changed

Lines changed: 815 additions & 139 deletions

File tree

distro/src/main/assembly/kms.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<include>org.apache.hadoop.thirdparty:hadoop-shaded-guava:jar:${hadoop-shaded-guava.version}</include>
4343
<include>org.apache.hadoop:hadoop-auth:jar:${hadoop.version}</include>
4444
<include>com.google.code.gson:gson</include>
45+
<include>com.sun.jersey:jersey-bundle</include>
4546
<include>org.eclipse.persistence:eclipselink</include>
4647
<include>org.eclipse.persistence:javax.persistence</include>
4748
<include>com.googlecode.log4jdbc:log4jdbc</include>
@@ -214,8 +215,6 @@
214215
<include>org.apache.hadoop:hadoop-client-api:jar:${hadoop.version}</include>
215216
<include>org.apache.hadoop:hadoop-client-runtime:jar:${hadoop.version}</include>
216217
<include>org.apache.solr:solr-solrj:jar:${solr.version}</include>
217-
<include>org.apache.ranger:ranger-authz-api</include>
218-
<include>org.apache.ranger:ranger-plugins-common</include>
219218
<include>org.apache.ranger:ugsync-util</include>
220219
<include>com.kstruct:gethostname4j:jar:${kstruct.gethostname4j.version}</include>
221220
<include>net.java.dev.jna:jna:jar:${jna.version}</include>
@@ -230,7 +229,6 @@
230229
<include>org.slf4j:slf4j-api</include>
231230
<include>ch.qos.logback:logback-classic:jar:${logback.version}</include>
232231
<include>ch.qos.logback:logback-core:jar:${logback.version}</include>
233-
<include>com.sun.jersey:jersey-bundle</include>
234232
<include>com.fasterxml.jackson.core:jackson-annotations:jar:${fasterxml.jackson.version}</include>
235233
<include>com.fasterxml.jackson.core:jackson-core:jar:${fasterxml.jackson.version}</include>
236234
<include>com.fasterxml.jackson.core:jackson-databind:jar:${fasterxml.jackson.version}</include>
@@ -283,6 +281,7 @@
283281
<include>org.apache.ranger:ranger-audit-core</include>
284282
<include>org.apache.ranger:ranger-audit-dest-hdfs</include>
285283
<include>org.apache.ranger:ranger-audit-dest-solr</include>
284+
<include>org.apache.ranger:ranger-authz-api</include>
286285
<include>org.apache.ranger:ranger-plugins-cred</include>
287286
<include>org.apache.ranger:ranger-plugins-common</include>
288287
<include>org.apache.ranger:ugsync-util</include>

embeddedwebserver/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@
9191
<artifactId>ranger-audit-dest-solr</artifactId>
9292
<version>${project.version}</version>
9393
</dependency>
94-
<dependency>
95-
<groupId>org.apache.ranger</groupId>
96-
<artifactId>ranger-plugins-common</artifactId>
97-
<version>${project.version}</version>
98-
</dependency>
9994
<dependency>
10095
<groupId>org.apache.tomcat</groupId>
10196
<artifactId>tomcat-annotations-api</artifactId>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.hadoop.security;
21+
22+
import javax.security.auth.Subject;
23+
import javax.security.auth.callback.CallbackHandler;
24+
import javax.security.auth.login.LoginException;
25+
import javax.security.auth.spi.LoginModule;
26+
27+
import java.util.Map;
28+
29+
public class KrbPasswordSaverLoginModule implements LoginModule {
30+
public static final String USERNAME_PARAM = "javax.security.auth.login.name";
31+
public static final String PASSWORD_PARAM = "javax.security.auth.login.password";
32+
33+
@SuppressWarnings("rawtypes")
34+
private Map sharedState;
35+
36+
public KrbPasswordSaverLoginModule() {
37+
}
38+
39+
@SuppressWarnings("unchecked")
40+
@Override
41+
public void initialize(Subject subject, CallbackHandler callbackhandler, Map<String, ?> sharedMap, Map<String, ?> options) {
42+
this.sharedState = sharedMap;
43+
44+
String userName = (options != null) ? (String) options.get(USERNAME_PARAM) : null;
45+
String password = (options != null) ? (String) options.get(PASSWORD_PARAM) : null;
46+
47+
if (userName != null) {
48+
this.sharedState.put(USERNAME_PARAM, userName);
49+
}
50+
51+
if (password != null) {
52+
this.sharedState.put(PASSWORD_PARAM, password.toCharArray());
53+
}
54+
}
55+
56+
@Override
57+
public boolean login() throws LoginException {
58+
return true;
59+
}
60+
61+
@Override
62+
public boolean commit() throws LoginException {
63+
return true;
64+
}
65+
66+
@Override
67+
public boolean abort() throws LoginException {
68+
return true;
69+
}
70+
71+
@Override
72+
public boolean logout() throws LoginException {
73+
return true;
74+
}
75+
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.hadoop.security;
20+
21+
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
22+
import org.apache.hadoop.security.authentication.util.KerberosName;
23+
import org.apache.hadoop.security.authentication.util.KerberosUtil;
24+
import org.apache.hadoop.util.StringUtils;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
28+
import javax.security.auth.Subject;
29+
import javax.security.auth.login.AppConfigurationEntry;
30+
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
31+
import javax.security.auth.login.LoginContext;
32+
import javax.security.auth.login.LoginException;
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
import java.security.Principal;
37+
import java.util.HashMap;
38+
import java.util.HashSet;
39+
import java.util.Map;
40+
import java.util.Set;
41+
42+
public class SecureClientLogin {
43+
private static final Logger LOG = LoggerFactory.getLogger(SecureClientLogin.class);
44+
45+
public static final String HOSTNAME_PATTERN = "_HOST";
46+
47+
private SecureClientLogin() {
48+
// to block instantiation
49+
}
50+
51+
public static synchronized Subject loginUserFromKeytab(String user, String path) throws IOException {
52+
try {
53+
Subject subject = new Subject();
54+
SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(true, user, path);
55+
LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
56+
57+
subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
58+
59+
login.login();
60+
61+
return login.getSubject();
62+
} catch (LoginException le) {
63+
throw new IOException("Login failure for " + user + " from keytab " + path, le);
64+
}
65+
}
66+
67+
public static synchronized Subject loginUserFromKeytab(String user, String path, String nameRules) throws IOException {
68+
try {
69+
Subject subject = new Subject();
70+
SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(true, user, path);
71+
LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
72+
73+
KerberosName.setRules(nameRules);
74+
75+
subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
76+
77+
login.login();
78+
79+
return login.getSubject();
80+
} catch (LoginException le) {
81+
throw new IOException("Login failure for " + user + " from keytab " + path, le);
82+
}
83+
}
84+
85+
public static synchronized Subject loginUserWithPassword(String user, String password) throws IOException {
86+
try {
87+
Subject subject = new Subject();
88+
SecureClientLoginConfiguration loginConf = new SecureClientLoginConfiguration(false, user, password);
89+
LoginContext login = new LoginContext("hadoop-keytab-kerberos", subject, null, loginConf);
90+
91+
subject.getPrincipals().add(new User(user, AuthenticationMethod.KERBEROS, login));
92+
93+
login.login();
94+
95+
return login.getSubject();
96+
} catch (LoginException le) {
97+
throw new IOException("Login failure for " + user + " using password ****", le);
98+
}
99+
}
100+
101+
public static synchronized Subject login(String user) throws IOException {
102+
Subject subject = new Subject();
103+
104+
subject.getPrincipals().add(new User(user));
105+
106+
return subject;
107+
}
108+
109+
public static Set<Principal> getUserPrincipals(Subject aSubject) {
110+
if (aSubject != null) {
111+
Set<User> list = aSubject.getPrincipals(User.class);
112+
113+
return list != null ? new HashSet<>(list) : null;
114+
} else {
115+
return null;
116+
}
117+
}
118+
119+
public static Principal createUserPrincipal(String aLoginName) {
120+
return new User(aLoginName);
121+
}
122+
123+
public static boolean isKerberosCredentialExists(String principal, String keytabPath) {
124+
boolean isValid = false;
125+
126+
if (keytabPath != null && !keytabPath.isEmpty()) {
127+
File keytabFile = new File(keytabPath);
128+
129+
if (!keytabFile.exists()) {
130+
LOG.warn("{} doesn't exist.", keytabPath);
131+
} else if (!keytabFile.canRead()) {
132+
LOG.warn("Unable to read {}. Please check the file access permissions for user", keytabPath);
133+
} else {
134+
isValid = true;
135+
}
136+
} else {
137+
LOG.warn("Can't find keyTab Path : {}", keytabPath);
138+
}
139+
if (!(principal != null && !principal.isEmpty() && isValid)) {
140+
isValid = false;
141+
142+
LOG.warn("Can't find principal : {}", principal);
143+
}
144+
145+
return isValid;
146+
}
147+
148+
public static String getPrincipal(String principalConfig, String hostName) throws IOException {
149+
String[] components = getComponents(principalConfig);
150+
151+
if (components == null || components.length != 3 || !HOSTNAME_PATTERN.equals(components[1])) {
152+
return principalConfig;
153+
} else {
154+
if (hostName == null) {
155+
throw new IOException("Can't replace " + HOSTNAME_PATTERN + " pattern since client ranger.service.host is null");
156+
}
157+
158+
return replacePattern(components, hostName);
159+
}
160+
}
161+
162+
private static String[] getComponents(String principalConfig) {
163+
if (principalConfig == null) {
164+
return null;
165+
}
166+
167+
return principalConfig.split("[/@]");
168+
}
169+
170+
private static String replacePattern(String[] components, String hostname) throws IOException {
171+
String fqdn = hostname;
172+
173+
if (org.apache.commons.lang3.StringUtils.isEmpty(fqdn) || "0.0.0.0".equals(fqdn)) {
174+
fqdn = java.net.InetAddress.getLocalHost().getCanonicalHostName();
175+
}
176+
177+
return components[0] + "/" + StringUtils.toLowerCase(fqdn) + "@" + components[2];
178+
}
179+
180+
static class SecureClientLoginConfiguration extends javax.security.auth.login.Configuration {
181+
private final Map<String, String> kerberosOptions = new HashMap<>();
182+
private boolean usePassword;
183+
184+
public SecureClientLoginConfiguration(boolean useKeyTab, String principal, String credential) {
185+
kerberosOptions.put("principal", principal);
186+
kerberosOptions.put("debug", "false");
187+
188+
if (useKeyTab) {
189+
kerberosOptions.put("useKeyTab", "true");
190+
kerberosOptions.put("keyTab", credential);
191+
kerberosOptions.put("doNotPrompt", "true");
192+
} else {
193+
usePassword = true;
194+
195+
kerberosOptions.put("useKeyTab", "false");
196+
kerberosOptions.put(KrbPasswordSaverLoginModule.USERNAME_PARAM, principal);
197+
kerberosOptions.put(KrbPasswordSaverLoginModule.PASSWORD_PARAM, credential);
198+
kerberosOptions.put("doNotPrompt", "false");
199+
kerberosOptions.put("useFirstPass", "true");
200+
kerberosOptions.put("tryFirstPass", "false");
201+
}
202+
203+
kerberosOptions.put("storeKey", "true");
204+
kerberosOptions.put("refreshKrb5Config", "true");
205+
}
206+
207+
@Override
208+
public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
209+
AppConfigurationEntry keytabKerberosLogin = new AppConfigurationEntry(KerberosUtil.getKrb5LoginModuleName(), LoginModuleControlFlag.REQUIRED, kerberosOptions);
210+
211+
if (usePassword) {
212+
AppConfigurationEntry kerberosPwdSaver = new AppConfigurationEntry(KrbPasswordSaverLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, kerberosOptions);
213+
214+
return new AppConfigurationEntry[] {kerberosPwdSaver, keytabKerberosLogin};
215+
} else {
216+
return new AppConfigurationEntry[] {keytabKerberosLogin};
217+
}
218+
}
219+
}
220+
}

embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/EmbeddedServerUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.ranger.server.tomcat;
2121

2222
import org.apache.commons.lang3.StringUtils;
23-
import org.apache.ranger.plugin.util.XMLUtils;
2423

2524
import java.util.ArrayList;
2625
import java.util.List;

embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/SolrCollectionBootstrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.http.client.methods.HttpPost;
2626
import org.apache.http.entity.ByteArrayEntity;
2727
import org.apache.http.util.EntityUtils;
28-
import org.apache.ranger.authorization.utils.StringUtil;
2928
import org.apache.solr.client.solrj.SolrClient;
3029
import org.apache.solr.client.solrj.SolrServerException;
3130
import org.apache.solr.client.solrj.impl.CloudSolrClient;
@@ -446,7 +445,7 @@ private File getConfigSetFolder() {
446445
private static List<String> getZkHosts() {
447446
List<String> zookeeperHosts = null;
448447

449-
if (!StringUtil.isEmpty(EmbeddedServerUtil.getConfig(SOLR_ZK_HOSTS))) {
448+
if (!StringUtils.isEmpty(EmbeddedServerUtil.getConfig(SOLR_ZK_HOSTS))) {
450449
String zkHosts = EmbeddedServerUtil.getConfig(SOLR_ZK_HOSTS).trim();
451450

452451
zookeeperHosts = new ArrayList<>(Arrays.asList(zkHosts.split(",")));

0 commit comments

Comments
 (0)