Skip to content

Commit

Permalink
RANGER-4114: updated plugin to use consistent property-prefix across …
Browse files Browse the repository at this point in the history
…all references

(cherry picked from commit 6b5628f)
  • Loading branch information
mneethiraj committed Mar 2, 2023
1 parent a28c05a commit c14a7ce
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ public void notifyAuthContextChanged() {
}
}

public String getPropertyPrefix() {
RangerPluginConfig pluginConfig = getPluginConfig();

return pluginConfig != null ? pluginConfig.getPropertyPrefix() : "ranger.plugin." + serviceDef.getName();
}

public String getConfig(String configName, String defaultValue) {
RangerPluginContext pluginContext = this.pluginContext;
String ret = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void init() {

super.init();

String propertyPrefix = "ranger.plugin." + serviceDef.getName();
String propertyPrefix = getPropertyPrefix();
String tagRetrieverClassName = getOption(TAG_RETRIEVER_CLASSNAME_OPTION);
long pollingIntervalMs = getLongOption(TAG_REFRESHER_POLLINGINTERVAL_OPTION, 60 * 1000);

Expand Down Expand Up @@ -404,7 +404,7 @@ public EnrichedServiceTags getEnrichedServiceTags() {
}

protected RangerReadWriteLock createLock() {
String propertyPrefix = "ranger.plugin." + serviceDef.getName();
String propertyPrefix = getPropertyPrefix();
RangerPluginConfig config = getPluginConfig();
boolean deltasEnabled = config != null && config.getBoolean(propertyPrefix + RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_TAG_DELTA, RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_TAG_DELTA_DEFAULT);
boolean inPlaceUpdatesEnabled = config != null && config.getBoolean(propertyPrefix + RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_IN_PLACE_TAG_UPDATES, RangerCommonConstants.PLUGIN_CONFIG_SUFFIX_IN_PLACE_TAG_UPDATES_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public void init() {

super.init();

String propertyPrefix = getPropertyPrefix();
String userStoreRetrieverClassName = getOption(USERSTORE_RETRIEVER_CLASSNAME_OPTION);
long pollingIntervalMs = getLongOption(USERSTORE_REFRESHER_POLLINGINTERVAL_OPTION, 3600 * 1000);

dedupStrings = getBooleanConfig("ranger.plugin." + serviceDef.getName() + ".dedup.strings", true);
dedupStrings = getBooleanConfig(propertyPrefix + ".dedup.strings", true);

if (StringUtils.isNotBlank(userStoreRetrieverClassName)) {

Expand All @@ -81,7 +82,6 @@ public void init() {
}

if (userStoreRetriever != null) {
String propertyPrefix = "ranger.plugin." + serviceDef.getName();
disableCacheIfServiceNotFound = getBooleanConfig(propertyPrefix + ".disable.cache.if.servicenotfound", true);
String cacheDir = getConfig(propertyPrefix + ".policy.cache.dir", null);
String cacheFilename = String.format("%s_%s_userstore.json", appId, serviceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.ranger.admin.client.RangerAdminClient;
import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
import org.apache.ranger.plugin.service.RangerBasePlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -57,7 +58,7 @@ public class RangerRolesProvider {
private boolean rangerUserGroupRolesSetInPlugin;
private boolean serviceDefSetInPlugin;

public RangerRolesProvider(String serviceType, String appId, String serviceName, RangerAdminClient rangerAdmin, String cacheDir, Configuration config) {
public RangerRolesProvider(String serviceType, String appId, String serviceName, RangerAdminClient rangerAdmin, String cacheDir, RangerPluginConfig config) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerRolesProvider(serviceName=" + serviceName + ").RangerRolesProvider()");
}
Expand Down Expand Up @@ -87,7 +88,7 @@ public RangerRolesProvider(String serviceType, String appId, String serviceName,
}
this.gson = gson;

String propertyPrefix = "ranger.plugin." + serviceType;
String propertyPrefix = config.getPropertyPrefix();
disableCacheIfServiceNotFound = config.getBoolean(propertyPrefix + ".disable.cache.if.servicenotfound", true);

if (LOG.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,9 @@ private void runTests(InputStreamReader reader, String testName) {
servicePolicies.setTagPolicies(tagPolicies);
}

boolean useForwardedIPAddress = pluginContext.getConfig().getBoolean("ranger.plugin.hive.use.x-forwarded-for.ipaddress", false);
String trustedProxyAddressString = pluginContext.getConfig().get("ranger.plugin.hive.trusted.proxy.ipaddresses");
RangerPluginConfig config = pluginContext.getConfig();
boolean useForwardedIPAddress = config.getBoolean(config.getPropertyPrefix() + ".use.x-forwarded-for.ipaddress", false);
String trustedProxyAddressString = config.get(config.getPropertyPrefix() + ".trusted.proxy.ipaddresses");
String[] trustedProxyAddresses = StringUtils.split(trustedProxyAddressString, ';');
if (trustedProxyAddresses != null) {
for (int i = 0; i < trustedProxyAddresses.length; i++) {
Expand Down Expand Up @@ -578,18 +579,18 @@ private void runTests(InputStreamReader reader, String testName) {

roles.setRangerRoles(rolesSet);

RangerPolicyEngineOptions policyEngineOptions = pluginContext.getConfig().getPolicyEngineOptions();
RangerPolicyEngineOptions policyEngineOptions = config.getPolicyEngineOptions();

policyEngineOptions.disableAccessEvaluationWithPolicyACLSummary = true;

setPluginConfig(pluginContext.getConfig(), ".super.users", testCase.superUsers);
setPluginConfig(pluginContext.getConfig(), ".super.groups", testCase.superGroups);
setPluginConfig(pluginContext.getConfig(), ".audit.exclude.users", testCase.auditExcludedUsers);
setPluginConfig(pluginContext.getConfig(), ".audit.exclude.groups", testCase.auditExcludedGroups);
setPluginConfig(pluginContext.getConfig(), ".audit.exclude.roles", testCase.auditExcludedRoles);
setPluginConfig(config, ".super.users", testCase.superUsers);
setPluginConfig(config, ".super.groups", testCase.superGroups);
setPluginConfig(config, ".audit.exclude.users", testCase.auditExcludedUsers);
setPluginConfig(config, ".audit.exclude.groups", testCase.auditExcludedGroups);
setPluginConfig(config, ".audit.exclude.roles", testCase.auditExcludedRoles);

// so that setSuperUsersAndGroups(), setAuditExcludedUsersGroupsRoles() will be called on the pluginConfig
new RangerBasePlugin(pluginContext.getConfig());
new RangerBasePlugin(config);

RangerPolicyEngineImpl policyEngine = new RangerPolicyEngineImpl(servicePolicies, pluginContext, roles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ private void runTests(InputStreamReader reader, String testName) {
servicePolicies.setTagPolicies(tagPolicies);
}

boolean useForwardedIPAddress = pluginContext.getConfig().getBoolean("ranger.plugin.hive.use.x-forwarded-for.ipaddress", false);
String trustedProxyAddressString = pluginContext.getConfig().get("ranger.plugin.hive.trusted.proxy.ipaddresses");
RangerPluginConfig config = pluginContext.getConfig();
boolean useForwardedIPAddress = config.getBoolean(config.getPropertyPrefix() + ".use.x-forwarded-for.ipaddress", false);
String trustedProxyAddressString = config.get(config.getPropertyPrefix() + ".trusted.proxy.ipaddresses");
String[] trustedProxyAddresses = StringUtils.split(trustedProxyAddressString, ';');
if (trustedProxyAddresses != null) {
for (int i = 0; i < trustedProxyAddresses.length; i++) {
Expand Down Expand Up @@ -272,18 +273,18 @@ private void runTests(InputStreamReader reader, String testName) {

roles.setRangerRoles(rolesSet);

RangerPolicyEngineOptions policyEngineOptions = pluginContext.getConfig().getPolicyEngineOptions();
RangerPolicyEngineOptions policyEngineOptions = config.getPolicyEngineOptions();

policyEngineOptions.disableAccessEvaluationWithPolicyACLSummary = true;

setPluginConfig(pluginContext.getConfig(), ".super.users", testCase.superUsers);
setPluginConfig(pluginContext.getConfig(), ".super.groups", testCase.superGroups);
setPluginConfig(pluginContext.getConfig(), ".audit.exclude.users", testCase.auditExcludedUsers);
setPluginConfig(pluginContext.getConfig(), ".audit.exclude.groups", testCase.auditExcludedGroups);
setPluginConfig(pluginContext.getConfig(), ".audit.exclude.roles", testCase.auditExcludedRoles);
setPluginConfig(config, ".super.users", testCase.superUsers);
setPluginConfig(config, ".super.groups", testCase.superGroups);
setPluginConfig(config, ".audit.exclude.users", testCase.auditExcludedUsers);
setPluginConfig(config, ".audit.exclude.groups", testCase.auditExcludedGroups);
setPluginConfig(config, ".audit.exclude.roles", testCase.auditExcludedRoles);

// so that setSuperUsersAndGroups(), setAuditExcludedUsersGroupsRoles() will be called on the pluginConfig
new RangerBasePlugin(pluginContext.getConfig());
new RangerBasePlugin(config);

RangerPolicyEngineImpl policyEngine = new RangerPolicyEngineImpl(servicePolicies, pluginContext, roles);

Expand Down

0 comments on commit c14a7ce

Please sign in to comment.