Skip to content

Commit

Permalink
Support Listing with ES authorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbonte21 committed Dec 26, 2023
1 parent 79d4293 commit 83d29e2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ private List<AtlasEntityHeader> getAtlasPolicies(String serviceName) throws Atla

List<Map<String, Object>> mustClauseList = new ArrayList<>();
mustClauseList.add(getMap("term", getMap(ATTR_POLICY_SERVICE_NAME, serviceName)));
mustClauseList.add(getMap("term", getMap(ATTR_POLICY_IS_ENABLED, true)));
mustClauseList.add(getMap("match", getMap("__state", Id.EntityState.ACTIVE)));

dsl.put("query", getMap("bool", getMap("must", mustClauseList)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -61,13 +62,16 @@ public static boolean listEndsWith(String value, List<String> list) {
}

public static Set<String> getTypeAndSupertypesList(String typeName) {
Set<String> entityTypes = typeRegistry.getEntityTypeByName(typeName).getTypeAndAllSuperTypes();
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

return entityTypes;
if (entityType == null) {
return Collections.singleton(typeName);
} else {
return entityType.getTypeAndAllSuperTypes();
}
}

public static AtlasEntityType getEntityTypeByName(String typeName) {
return typeRegistry.getEntityTypeByName(typeName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,20 @@ private static Map<String, Object> getDSLForResources(List<String> entities, Set
List<Map<String, Object>> filterClauses = new ArrayList<>();

if (!typeNames.isEmpty() && !typeNames.contains("*")) {
filterClauses.add(getMap("terms", getMap("__typeName.keyword", typeNames)));
List<Map<String, Object>> typeClauses = new ArrayList<>();
typeClauses.add(getMap("terms", getMap("__typeName.keyword", typeNames)));
typeClauses.add(getMap("terms", getMap("__superTypeNames.keyword", typeNames)));

filterClauses.add(getMap("bool", getMap("should", typeClauses)));
}

if (classifications != null && !classifications.isEmpty() && !classifications.contains("*")) {
filterClauses.add(getMap("terms", getMap("__traitNames", classifications)));
filterClauses.add(getMap("terms", getMap("__propagatedTraitNames", classifications)));
List<Map<String, Object>> classificationClauses = new ArrayList<>();

classificationClauses.add(getMap("terms", getMap("__traitNames", classifications)));
classificationClauses.add(getMap("terms", getMap("__propagatedTraitNames", classifications)));

filterClauses.add(getMap("bool", getMap("should", classificationClauses)));
}

if (!filterClauses.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static List<RangerPolicy> getRelevantPolicies(String persona, String purp
if ("atlas".equals(serviceName)) {
policies = getResourcePolicies();
} else if ("atlas_tag".equals(serviceName)) {
policies =getTagPolicies();
policies = getTagPolicies();
} else if ("atlas_abac".equals(serviceName)) {
policies = getAbacPolicies();
}
Expand Down Expand Up @@ -139,7 +139,10 @@ private static List<RangerPolicy> getFilteredPoliciesForUser(List<RangerPolicy>
List<String> policyUsers = policyItem.getUsers();
List<String> policyGroups = policyItem.getGroups();
List<String> policyRoles = policyItem.getRoles();
if (policyUsers.contains(user) || AuthorizerCommon.arrayListContains(policyGroups, groups) || AuthorizerCommon.arrayListContains(policyRoles, roles)) {
if (policyUsers.contains(user)
|| policyGroups.contains("public")
|| AuthorizerCommon.arrayListContains(policyGroups, groups)
|| AuthorizerCommon.arrayListContains(policyRoles, roles)) {
filterPolicies.add(policy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,14 @@ private void addPreFiltersToSearchQuery(SearchParams searchParams) {

String dslString = searchParams.getQuery();
JsonNode node = mapper.readTree(dslString);
String userQueryString = node.get("query").toString();
String userQueryBase64 = Base64.getEncoder().encodeToString(userQueryString.getBytes());;
mustClauseList.add(getMap("wrapper", getMap("query", userQueryBase64)));
JsonNode userQueryNode = node.get("query");
if (userQueryNode != null) {

String userQueryString = userQueryNode.toString();

String userQueryBase64 = Base64.getEncoder().encodeToString(userQueryString.getBytes());
mustClauseList.add(getMap("wrapper", getMap("query", userQueryBase64)));
}

JsonNode updateQueryNode = mapper.valueToTree(getMap("bool", getMap("must", mustClauseList)));

Expand Down Expand Up @@ -1144,7 +1148,10 @@ private void prepareSearchResult(AtlasSearchResult ret, DirectIndexQueryResult i
} catch (Exception e) {
throw e;
}
scrubSearchResults(ret, searchParams.getSuppressLogs());

if (!searchParams.getUseAccessControlv2()) {
scrubSearchResults(ret, searchParams.getSuppressLogs());
}
}

private Map<String, Object> getMap(String key, Object value) {
Expand Down

0 comments on commit 83d29e2

Please sign in to comment.