Skip to content

Commit

Permalink
RANGER-4723: updated zone matcher to handle descendent match
Browse files Browse the repository at this point in the history
  • Loading branch information
mneethiraj committed Feb 22, 2024
1 parent c4f6cc3 commit 84ef6e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef;
import org.apache.ranger.plugin.model.validation.RangerZoneResourceMatcher;
import org.apache.ranger.plugin.policyresourcematcher.RangerPolicyResourceMatcher;
import org.apache.ranger.plugin.policyresourcematcher.RangerPolicyResourceMatcher.MatchType;
import org.apache.ranger.plugin.store.EmbeddedServiceDefsUtil;
import org.apache.ranger.plugin.util.RangerResourceEvaluatorsRetriever;
import org.apache.ranger.plugin.util.ServicePolicies.SecurityZoneInfo;
Expand Down Expand Up @@ -103,7 +104,14 @@ private Set<String> getZonesForResourceAndChildren(Map<String, ?> resource, Rang
LOG.debug("Trying to match resource:[{}] using matcher:[{}]", accessResource, matcher);
}

if (matcher.getPolicyResourceMatcher().isMatch(accessResource, RangerPolicyResourceMatcher.MatchScope.ANY, null)) {
RangerPolicyResourceMatcher policyResourceMatcher = matcher.getPolicyResourceMatcher();
MatchType matchType = policyResourceMatcher.getMatchType(accessResource, null);

if (matchType == MatchType.DESCENDANT) { // add unzoned name
ret.add("");
}

if (matchType != MatchType.NONE) {
if (LOG.isDebugEnabled()) {
LOG.debug("Matched resource:[{}] using matcher:[{}]", accessResource, matcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testZoneMatcher() {

res = createResource("database", "db3");
zones = zoneMatcher.getZonesForResourceAndChildren(res);
assertEquals(createSet("z3", "z4"), zones);
assertEquals(createSet("", "z3", "z4"), zones);
}

private Map<String, SecurityZoneInfo> createSecurityZones() {
Expand Down

0 comments on commit 84ef6e5

Please sign in to comment.