Skip to content

Commit

Permalink
[apache#5336]feat(auth-ranger): Remove MANAGED_BY_GRAVITINO limit and…
Browse files Browse the repository at this point in the history
… compatible for existing ranger policy
  • Loading branch information
theoryxu committed Nov 26, 2024
1 parent fbd9fc4 commit 552f08e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -800,15 +800,8 @@ private void doRemoveSchemaMetadataObject(RangerMetadataObject rangerMetadataObj
try {
List<RangerPolicy> policies = rangerClient.getPoliciesInService(rangerServiceName);
policies.stream()
.forEach(
policy -> {
try {
rangerClient.deletePolicy(policy.getId());
} catch (RangerServiceException e) {
LOG.error("Failed to rename the policy {}!", policy);
throw new RuntimeException(e);
}
});
.filter(rangerHelper::hasGravitinoManagedPolicyItem)
.forEach(rangerHelper::removeAllGravitinoManagedPolicyItem);
} catch (RangerServiceException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -977,32 +970,7 @@ private void removePolicyByMetadataObject(List<String> metadataNames) {
.getValues()
.contains(preciseFilters.get(entry.getKey()))))
.collect(Collectors.toList());
policies.stream()
.forEach(
policy -> {
try {
policy.setPolicyItems(
policy.getPolicyItems().stream()
.filter(i -> !rangerHelper.isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
policy.setDenyPolicyItems(
policy.getDenyPolicyItems().stream()
.filter(i -> !rangerHelper.isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
policy.setRowFilterPolicyItems(
policy.getRowFilterPolicyItems().stream()
.filter(i -> !rangerHelper.isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
policy.setDataMaskPolicyItems(
policy.getDataMaskPolicyItems().stream()
.filter(i -> !rangerHelper.isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
rangerClient.updatePolicy(policy.getId(), policy);
} catch (RangerServiceException e) {
LOG.error("Failed to rename the policy {}!", policy);
throw new RuntimeException(e);
}
});
policies.forEach(rangerHelper::removeAllGravitinoManagedPolicyItem);
}

private void updatePolicyByMetadataObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,39 @@ public boolean isGravitinoManagedPolicyItemAccess(RangerPolicy.RangerPolicyItem
return policyItem.getRoles().stream().anyMatch(role -> role.startsWith(GRAVITINO_ROLE_PREFIX));
}

public boolean hasGravitinoManagedPolicyItem(RangerPolicy policy) {
List<RangerPolicy.RangerPolicyItem> policyItems = policy.getPolicyItems();
policyItems.addAll(policy.getDenyPolicyItems());
policyItems.addAll(policy.getRowFilterPolicyItems());
policyItems.addAll(policy.getDataMaskPolicyItems());
return policyItems.stream().anyMatch(this::isGravitinoManagedPolicyItemAccess);
}

public void removeAllGravitinoManagedPolicyItem(RangerPolicy policy) {
try {
policy.setPolicyItems(
policy.getPolicyItems().stream()
.filter(i -> !isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
policy.setDenyPolicyItems(
policy.getDenyPolicyItems().stream()
.filter(i -> !isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
policy.setRowFilterPolicyItems(
policy.getRowFilterPolicyItems().stream()
.filter(i -> !isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
policy.setDataMaskPolicyItems(
policy.getDataMaskPolicyItems().stream()
.filter(i -> !isGravitinoManagedPolicyItemAccess(i))
.collect(Collectors.toList()));
rangerClient.updatePolicy(policy.getId(), policy);
} catch (RangerServiceException e) {
LOG.error("Failed to update the policy {}!", policy);
throw new RuntimeException(e);
}
}

protected boolean checkRangerRole(String roleName) throws AuthorizationPluginException {
roleName = generateGravitinoRoleName(roleName);
try {
Expand Down

0 comments on commit 552f08e

Please sign in to comment.