Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit bcb7ffe

Browse files
committed
SENTRY-1846 - Use a consistent configuration variable for the sentry provider property
- Reviewed by Sergio Pena, Brian Towles, Na Li.
1 parent 5b7cccc commit bcb7ffe

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

conf/sentry-site.xml.hive-client.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
-->
7373

7474
<property>
75-
<name>sentry.provider</name>
75+
<name>sentry.hive.provider</name>
7676
<value>org.apache.sentry.provider.file.HadoopGroupResourceAuthorizationProvider</value>
7777
<description> Deprecated name: hive.sentry.provider. Group mapping which should be used at client side</description>
7878
</property>

conf/sentry-site.xml.solr-client.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<configuration>
2121
<property>
22-
<name>sentry.provider</name>
22+
<name>sentry.solr.provider</name>
2323
<value>org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider</value>
2424
</property>
2525
<property>

sentry-binding/sentry-binding-hive-conf/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java

+27-14
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public class HiveAuthzConf extends Configuration {
8888
* Config setting definitions
8989
*/
9090
public static enum AuthzConfVars {
91-
AUTHZ_PROVIDER("sentry.provider",
91+
AUTHZ_PROVIDER("sentry.hive.provider",
9292
"org.apache.sentry.provider.common.HadoopGroupResourceAuthorizationProvider"),
9393
AUTHZ_PROVIDER_RESOURCE("sentry.hive.provider.resource", ""),
9494
AUTHZ_PROVIDER_BACKEND("sentry.hive.provider.backend", "org.apache.sentry.provider.file.SimpleFileProviderBackend"),
@@ -108,6 +108,8 @@ public static enum AuthzConfVars {
108108

109109
AUTHZ_PROVIDER_DEPRECATED("hive.sentry.provider",
110110
"org.apache.sentry.provider.file.ResourceAuthorizationProvider"),
111+
AUTHZ_PROVIDER_DEPRECATED2("sentry.provider",
112+
"org.apache.sentry.provider.common.HadoopGroupResourceAuthorizationProvider"),
111113
AUTHZ_PROVIDER_RESOURCE_DEPRECATED("hive.sentry.provider.resource", ""),
112114
AUTHZ_SERVER_NAME_DEPRECATED("hive.sentry.server", ""),
113115
AUTHZ_RESTRICT_DEFAULT_DB_DEPRECATED("hive.sentry.restrict.defaultDB", "false"),
@@ -146,16 +148,22 @@ public static String getDefault(String varName) {
146148
// as long as the new property names aren't also provided. Since the binding code
147149
// only calls the new property names, we require a map from current names to deprecated
148150
// names in order to check if the deprecated name of a property was set.
149-
private static final Map<String, AuthzConfVars> currentToDeprecatedProps =
150-
new HashMap<String, AuthzConfVars>();
151+
private static final Map<String, List<AuthzConfVars>> currentToDeprecatedProps = new HashMap<>();
151152
static {
152-
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_PROVIDER.getVar(), AuthzConfVars.AUTHZ_PROVIDER_DEPRECATED);
153-
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar(), AuthzConfVars.AUTHZ_PROVIDER_RESOURCE_DEPRECATED);
154-
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_SERVER_NAME.getVar(), AuthzConfVars.AUTHZ_SERVER_NAME_DEPRECATED);
155-
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_RESTRICT_DEFAULT_DB.getVar(), AuthzConfVars.AUTHZ_RESTRICT_DEFAULT_DB_DEPRECATED);
156-
currentToDeprecatedProps.put(AuthzConfVars.SENTRY_TESTING_MODE.getVar(), AuthzConfVars.SENTRY_TESTING_MODE_DEPRECATED);
157-
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_ALLOW_HIVE_IMPERSONATION.getVar(), AuthzConfVars.AUTHZ_ALLOW_HIVE_IMPERSONATION_DEPRECATED);
158-
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_ONFAILURE_HOOKS.getVar(), AuthzConfVars.AUTHZ_ONFAILURE_HOOKS_DEPRECATED);
153+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_PROVIDER.getVar(),
154+
Arrays.asList(AuthzConfVars.AUTHZ_PROVIDER_DEPRECATED, AuthzConfVars.AUTHZ_PROVIDER_DEPRECATED2));
155+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar(),
156+
Collections.singletonList(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE_DEPRECATED));
157+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_SERVER_NAME.getVar(),
158+
Collections.singletonList(AuthzConfVars.AUTHZ_SERVER_NAME_DEPRECATED));
159+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_RESTRICT_DEFAULT_DB.getVar(),
160+
Collections.singletonList(AuthzConfVars.AUTHZ_RESTRICT_DEFAULT_DB_DEPRECATED));
161+
currentToDeprecatedProps.put(AuthzConfVars.SENTRY_TESTING_MODE.getVar(),
162+
Collections.singletonList(AuthzConfVars.SENTRY_TESTING_MODE_DEPRECATED));
163+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_ALLOW_HIVE_IMPERSONATION.getVar(),
164+
Collections.singletonList(AuthzConfVars.AUTHZ_ALLOW_HIVE_IMPERSONATION_DEPRECATED));
165+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_ONFAILURE_HOOKS.getVar(),
166+
Collections.singletonList(AuthzConfVars.AUTHZ_ONFAILURE_HOOKS_DEPRECATED));
159167
};
160168

161169
private static final Logger LOG = LoggerFactory
@@ -168,7 +176,6 @@ public HiveAuthzConf(URL hiveAuthzSiteURL) {
168176
LOG.info("DefaultFS: " + super.get("fs.defaultFS"));
169177
addResource(hiveAuthzSiteURL);
170178
applySystemProperties();
171-
LOG.info("DefaultFS: " + super.get("fs.defaultFS"));
172179
this.hiveAuthzSiteFile = hiveAuthzSiteURL.toString();
173180
}
174181
/**
@@ -208,14 +215,20 @@ public String get(String varName, String defaultVal) {
208215
String retVal = super.get(varName);
209216
if (retVal == null) {
210217
// check if the deprecated value is set here
218+
String deprecatedPropName = null;
211219
if (currentToDeprecatedProps.containsKey(varName)) {
212-
retVal = super.get(currentToDeprecatedProps.get(varName).getVar());
220+
for (AuthzConfVars var : currentToDeprecatedProps.get(varName)) {
221+
retVal = super.get(var.getVar());
222+
if (retVal != null) {
223+
deprecatedPropName = var.getVar();
224+
break;
225+
}
226+
}
213227
}
214228
if (retVal == null) {
215229
retVal = AuthzConfVars.getDefault(varName);
216230
} else {
217-
LOG.warn("Using the deprecated config setting " + currentToDeprecatedProps.get(varName).getVar() +
218-
" instead of " + varName);
231+
LOG.warn("Using the deprecated config setting " + deprecatedPropName + " instead of " + varName);
219232
}
220233
}
221234
if (retVal == null) {

sentry-binding/sentry-binding-hive-v2/src/main/java/org/apache/sentry/binding/hive/v2/authorizer/DefaultSentryAccessController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public void applyAuthorizationConfigPolicy(HiveConf hiveConf) throws HiveAuthzPl
333333
// Apply rest of the configuration only to HiveServer2
334334
if (ctx.getClientType() != CLIENT_TYPE.HIVESERVER2
335335
|| !hiveConf.getBoolVar(ConfVars.HIVE_AUTHORIZATION_ENABLED)) {
336-
throw new HiveAuthzPluginException("Sentry just support for hiveserver2");
336+
throw new HiveAuthzPluginException("Sentry only supports hiveserver2");
337337
}
338338
}
339339

sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/conf/SolrAuthzConf.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.apache.sentry.binding.solr.conf;
1818

1919
import java.net.URL;
20+
import java.util.HashMap;
21+
import java.util.Map;
2022

2123
import org.apache.hadoop.conf.Configuration;
2224
import org.slf4j.Logger;
@@ -29,11 +31,14 @@ public class SolrAuthzConf extends Configuration {
2931
* Config setting definitions
3032
*/
3133
public static enum AuthzConfVars {
32-
AUTHZ_PROVIDER("sentry.provider",
34+
AUTHZ_PROVIDER("sentry.solr.provider",
3335
"org.apache.sentry.provider.common.HadoopGroupResourceAuthorizationProvider"),
3436
AUTHZ_PROVIDER_RESOURCE("sentry.solr.provider.resource", ""),
3537
AUTHZ_PROVIDER_BACKEND("sentry.solr.provider.backend", "org.apache.sentry.provider.file.SimpleFileProviderBackend"),
36-
AUTHZ_POLICY_ENGINE("sentry.solr.policy.engine", "org.apache.sentry.policy.engine.common.CommonPolicyEngine");
38+
AUTHZ_POLICY_ENGINE("sentry.solr.policy.engine", "org.apache.sentry.policy.engine.common.CommonPolicyEngine"),
39+
40+
AUTHZ_PROVIDER_DEPRECATED("sentry.provider",
41+
"org.apache.sentry.provider.common.HadoopGroupResourceAuthorizationProvider");
3742

3843
private final String varName;
3944
private final String defaultVal;
@@ -61,6 +66,11 @@ public static String getDefault(String varName) {
6166
}
6267
}
6368

69+
private static final Map<String, AuthzConfVars> currentToDeprecatedProps = new HashMap<>();
70+
static {
71+
currentToDeprecatedProps.put(AuthzConfVars.AUTHZ_PROVIDER.getVar(), AuthzConfVars.AUTHZ_PROVIDER_DEPRECATED);
72+
}
73+
6474
@SuppressWarnings("unused")
6575
private static final Logger LOG = LoggerFactory
6676
.getLogger(SolrAuthzConf.class);
@@ -73,6 +83,19 @@ public SolrAuthzConf(URL solrAuthzSiteURL) {
7383

7484
@Override
7585
public String get(String varName) {
76-
return get(varName, AuthzConfVars.getDefault(varName));
86+
String retVal = super.get(varName);
87+
if (retVal == null) {
88+
// check if the deprecated value is set here
89+
if (currentToDeprecatedProps.containsKey(varName)) {
90+
AuthzConfVars var = currentToDeprecatedProps.get(varName);
91+
retVal = super.get(var.getVar());
92+
}
93+
if (retVal == null) {
94+
retVal = AuthzConfVars.getDefault(varName);
95+
} else {
96+
LOG.warn("Using the deprecated config setting " + currentToDeprecatedProps.get(varName).getVar() + " instead of " + varName);
97+
}
98+
}
99+
return retVal;
77100
}
78101
}

0 commit comments

Comments
 (0)