Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class RangerBasePlugin {
private final boolean dedupStrings;
private boolean isUserStoreEnricherAddedImplcitly = false;
private Map<String, String> serviceConfigs;

private boolean synchronousPolicyRefresh;

public RangerBasePlugin(String serviceType, String appId) {
this(new RangerPluginConfig(serviceType, null, appId, null, null, null));
Expand Down Expand Up @@ -362,6 +362,12 @@ public void setPolicies(ServicePolicies policies) {
}
}

String isSyncPolicyRefresh = this.pluginConfig == null ? null : this.serviceConfigs.get(this.pluginConfig.getPropertyPrefix() + ".policy.refresh.synchronous");
this.synchronousPolicyRefresh = Boolean.parseBoolean(isSyncPolicyRefresh);
if (this.synchronousPolicyRefresh) {
LOG.info("synchronousPolicyRefresh = {}", this.synchronousPolicyRefresh);
}

// guard against catastrophic failure during policy engine Initialization or
try {
RangerPolicyEngine oldPolicyEngine = this.policyEngine;
Expand Down Expand Up @@ -558,6 +564,9 @@ public Collection<RangerAccessResult> isAccessAllowed(Collection<RangerAccessReq
}

public RangerAccessResult isAccessAllowed(RangerAccessRequest request, RangerAccessResultProcessor resultProcessor) {
if (this.synchronousPolicyRefresh) {
refreshPoliciesAndTags();
}
RangerAccessResult ret = null;
RangerPolicyEngine policyEngine = this.policyEngine;

Expand Down Expand Up @@ -603,6 +612,9 @@ public RangerAccessResult isAccessAllowed(RangerAccessRequest request, RangerAcc
}

public Collection<RangerAccessResult> isAccessAllowed(Collection<RangerAccessRequest> requests, RangerAccessResultProcessor resultProcessor) {
if (this.synchronousPolicyRefresh) {
refreshPoliciesAndTags();
}
Collection<RangerAccessResult> ret = null;
RangerPolicyEngine policyEngine = this.policyEngine;

Expand Down Expand Up @@ -644,6 +656,9 @@ public Collection<RangerAccessResult> isAccessAllowed(Collection<RangerAccessReq
}

public RangerAccessResult evalDataMaskPolicies(RangerAccessRequest request, RangerAccessResultProcessor resultProcessor) {
if (this.synchronousPolicyRefresh) {
refreshPoliciesAndTags();
}
RangerPolicyEngine policyEngine = this.policyEngine;
RangerAccessResult ret = null;

Expand Down Expand Up @@ -680,6 +695,9 @@ public RangerAccessResult evalDataMaskPolicies(RangerAccessRequest request, Rang
}

public RangerAccessResult evalRowFilterPolicies(RangerAccessRequest request, RangerAccessResultProcessor resultProcessor) {
if (this.synchronousPolicyRefresh) {
refreshPoliciesAndTags();
}
RangerPolicyEngine policyEngine = this.policyEngine;
RangerAccessResult ret = null;

Expand Down Expand Up @@ -716,6 +734,9 @@ public RangerAccessResult evalRowFilterPolicies(RangerAccessRequest request, Ran
}

public void evalAuditPolicies(RangerAccessResult result) {
if (this.synchronousPolicyRefresh) {
refreshPoliciesAndTags();
}
RangerPolicyEngine policyEngine = this.policyEngine;

if (policyEngine != null) {
Expand All @@ -738,6 +759,9 @@ public RangerResourceACLs getResourceACLs(RangerAccessRequest request) {
}

public RangerResourceACLs getResourceACLs(RangerAccessRequest request, Integer policyType) {
if (this.synchronousPolicyRefresh) {
refreshPoliciesAndTags();
}
RangerResourceACLs ret = null;
RangerPolicyEngine policyEngine = this.policyEngine;

Expand Down Expand Up @@ -1037,7 +1061,7 @@ public static RangerAdminClient createAdminClient(RangerPluginConfig pluginConfi

public void refreshPoliciesAndTags() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> refreshPoliciesAndTags()");
LOG.debug("==> refreshPoliciesAndTags(): synchronousPolicyRefresh={}", synchronousPolicyRefresh);
}

try {
Expand Down Expand Up @@ -1224,7 +1248,7 @@ public static RangerResourceACLs getMergedResourceACLs(RangerResourceACLs baseAC
}

public Map<String, String> getServiceConfigs() {
return serviceConfigs;
return (serviceConfigs == null) ? Collections.emptyMap() : serviceConfigs;
}

protected RangerPolicyEngine getPolicyEngine() {
Expand Down
25 changes: 17 additions & 8 deletions dev-support/ranger-docker/scripts/create-ranger-services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ def service_not_exists(service):
'configs': {'username': 'hdfs', 'password': 'hdfs',
'fs.default.name': 'hdfs://ranger-hadoop:9000',
'hadoop.security.authentication': 'simple',
'hadoop.security.authorization': 'true'}})
'hadoop.security.authorization': 'true',
'ranger.plugin.hdfs.policy.refresh.synchronous':'true'}})

hive = RangerService({'name': 'dev_hive', 'type': 'hive',
'configs': {'username': 'hive', 'password': 'hive',
'jdbc.driverClassName': 'org.apache.hive.jdbc.HiveDriver',
'jdbc.url': 'jdbc:hive2://ranger-hive:10000',
'hadoop.security.authorization': 'true'}})
'hadoop.security.authorization': 'true',
'ranger.plugin.hive.policy.refresh.synchronous':'true'}})

kafka = RangerService({'name': 'dev_kafka', 'type': 'kafka',
'configs': {'username': 'kafka', 'password': 'kafka',
'zookeeper.connect': 'ranger-zk.example.com:2181'}})
'zookeeper.connect': 'ranger-zk.example.com:2181',
'ranger.plugin.kafka.policy.refresh.synchronous':'true'}})

knox = RangerService({'name': 'dev_knox', 'type': 'knox',
'configs': {'username': 'knox', 'password': 'knox', 'knox.url': 'https://ranger-knox:8443'}})
'configs': {'username': 'knox', 'password': 'knox', 'knox.url': 'https://ranger-knox:8443',
'ranger.plugin.knox.policy.refresh.synchronous':'true'}})

yarn = RangerService({'name': 'dev_yarn', 'type': 'yarn',
'configs': {'username': 'yarn', 'password': 'yarn',
'yarn.url': 'http://ranger-hadoop:8088'}})
'yarn.url': 'http://ranger-hadoop:8088',
'ranger.plugin.yarn.policy.refresh.synchronous':'true'}})

hbase = RangerService({'name': 'dev_hbase', 'type': 'hbase',
'configs': {'username': 'hbase', 'password': 'hbase',
Expand All @@ -43,11 +48,13 @@ def service_not_exists(service):
'hadoop.security.authorization': 'true',
'hbase.zookeeper.property.clientPort': '2181',
'hbase.zookeeper.quorum': 'ranger-zk',
'zookeeper.znode.parent': '/hbase'}})
'zookeeper.znode.parent': '/hbase',
'ranger.plugin.hbase.policy.refresh.synchronous':'true'}})

kms = RangerService({'name': 'dev_kms', 'type': 'kms',
'configs': {'username': 'keyadmin', 'password': 'rangerR0cks!',
'provider': 'http://ranger-kms:9292'}})
'provider': 'http://ranger-kms:9292',
'ranger.plugin.kms.policy.refresh.synchronous':'true'}})

trino = RangerService({'name': 'dev_trino',
'type': 'trino',
Expand All @@ -56,14 +63,16 @@ def service_not_exists(service):
'password': 'trino',
'jdbc.driverClassName': 'io.trino.jdbc.TrinoDriver',
'jdbc.url': 'jdbc:trino://ranger-trino:8080',
'ranger.plugin.trino.policy.refresh.synchronous':'true'
}})

ozone = RangerService({'name': 'dev_ozone',
'type': 'ozone',
'displayName': 'dev_ozone',
'configs': {'username': 'hdfs', 'password': 'hdfs',
'ozone.om.http-address': 'http://om:9874',
'hadoop.security.authentication': 'simple'}})
'hadoop.security.authentication': 'simple',
'ranger.plugin.ozone.policy.refresh.synchronous':'true'}})

services = [hdfs, yarn, hive, hbase, kafka, knox, kms, trino, ozone]
for service in services:
Expand Down