-
Notifications
You must be signed in to change notification settings - Fork 406
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
base: main
Are you sure you want to change the base?
[#4620] improvement(authz): Throw the necessary exception when handling Ranger plugin exception #6515
Changes from 1 commit
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!"); | ||
} | ||
|
||
|
@@ -278,9 +278,18 @@ protected RangerRole createRangerRoleIfNotExists(String roleName, boolean isOwne | |
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); | ||
|
||
// The client will return a error message contains `doesn't have permission` if the role does | ||
// not exist, then create it. | ||
if (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()); | ||
} | ||
} | ||
|
||
try { | ||
if (rangerRole == null) { | ||
rangerRole = new RangerRole(roleName, RangerHelper.MANAGED_BY_GRAVITINO, null, null, null); | ||
|
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.
The
e.getMessage().contains("No RangerRole found for name")
is Not a stable way. I think we can userangerClient.getRole()?
to double check it.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.
if role doesn't,
getRole
will return exception. It isn't a good way.