-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#4620] improvement(authz): Throw the necessary exception when handling Ranger plugin exception #6515
[#4620] improvement(authz): Throw the necessary exception when handling Ranger plugin exception #6515
Changes from all commits
3ed323b
8e4b01f
b3b1627
1507a14
343f070
88b52ec
1847c5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,7 +236,7 @@ protected GrantRevokeRoleRequest createGrantRevokeRoleRequest( | |
Set<String> groups = | ||
StringUtils.isEmpty(groupName) ? Sets.newHashSet() : Sets.newHashSet(groupName); | ||
|
||
if (users.size() == 0 && groups.size() == 0) { | ||
if (users.isEmpty() && groups.isEmpty()) { | ||
throw new AuthorizationPluginException("The user and group cannot be empty!"); | ||
} | ||
|
||
|
@@ -274,13 +274,8 @@ protected RangerRole createRangerRoleIfNotExists(String roleName, boolean isOwne | |
GRAVITINO_METALAKE_OWNER_ROLE, GRAVITINO_CATALOG_OWNER_ROLE, GRAVITINO_OWNER_ROLE)); | ||
} | ||
|
||
RangerRole rangerRole = null; | ||
try { | ||
rangerRole = rangerClient.getRole(roleName, rangerAdminName, rangerServiceName); | ||
} catch (RangerServiceException e) { | ||
// ignore exception, If the role does not exist, then create it. | ||
LOG.warn("The role({}) does not exist in the Ranger!", roleName); | ||
} | ||
RangerRole rangerRole = getRangerRole(roleName); | ||
|
||
try { | ||
if (rangerRole == null) { | ||
rangerRole = new RangerRole(roleName, RangerHelper.MANAGED_BY_GRAVITINO, null, null, null); | ||
|
@@ -293,6 +288,26 @@ protected RangerRole createRangerRoleIfNotExists(String roleName, boolean isOwne | |
return rangerRole; | ||
} | ||
|
||
public RangerRole getRangerRole(String roleName) { | ||
RangerRole rangerRole = null; | ||
try { | ||
rangerRole = rangerClient.getRole(roleName, rangerAdminName, rangerServiceName); | ||
} catch (RangerServiceException e) { | ||
|
||
// The client will return a error message contains `doesn't have permission` if the role does | ||
// not exist, then create it. | ||
if (e.getMessage() != null | ||
&& e.getMessage().contains("User doesn't have permissions to get details")) { | ||
LOG.warn("The role({}) does not exist in the Ranger!, e: {}", roleName, e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, this method ensures that that a specific ranger role exists. If the user cannot check if a role exists or not, we still allow the function to continue. Does this mean that a user can create a role but he/she cannot view it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point. Maybe we need to treat this seriously. For whatever permission related errors, always raise a special exception type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no better way to check this. Do you have suggestion? |
||
} else { | ||
throw new AuthorizationPluginException( | ||
"Failed to check role(%s) whether exists in the Ranger! e: %s", | ||
roleName, e.getMessage()); | ||
} | ||
} | ||
return rangerRole; | ||
} | ||
|
||
protected void updatePolicyOwner(RangerPolicy policy, Owner preOwner, Owner newOwner) { | ||
// Find matching policy items based on the owner's privileges | ||
List<RangerPolicy.RangerPolicyItem> matchPolicyItems = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another consideration as to why you don't throw an exception is to support idempotent operations.
Gravitino -> Ranger
Maybe the data was deleted in the last operation of the Ranger, and now it's being operated again. You can't throw an exception.
If you want to throw an exception, you have to cover the idempotent operation, with a test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You origin test code have covered the logic. You can see RangerHiveIT#testOnGrantedRolesToUser