-
Notifications
You must be signed in to change notification settings - Fork 46
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
Refactored permissions for roles and API keys #97
Refactored permissions for roles and API keys #97
Conversation
…larity based on role group.
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.
@billkalter I left a comment. Otherwise the change looks good to me.
@@ -332,7 +352,8 @@ private void migrateApiKey(ImmutableMultimap<String, String> parameters, PrintWr | |||
output.println("\nWarning: This is your only chance to see this key. Save it somewhere now."); | |||
} | |||
|
|||
private void deleteApiKey(ImmutableMultimap<String, String> parameters, PrintWriter output) { | |||
private void deleteApiKey(Subject subject, ImmutableMultimap<String, String> parameters, PrintWriter output) { | |||
subject.checkPermission(Permissions.deleteApiKey()); | |||
String key = getValueFromParams("key", parameters); |
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.
I know that the user will not provide the roles when deleting the api-key, so no roles in the parameters input, but do you think we need to pull up all the roles of the api-key and do a subject.checkPermission(Permissions.grantRole(RoleIdentifier.fromString(role)));
for each role before deleting the api-key:?
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.
That's a great question. My reasoning is this:
- The grant-role check when removing a role from an API key is to prevent an accidental or possibly malicious user from revoking permissions which he himself cannot grant back. Basically, the grant-role permission is being used as a proxy for group ownership.
- When an API key is being deleted there is no API key left for which the role can be granted back. Therefore, rather than requiring permission to grant each individual role a much higher and more protected delete-api-key permission is needed.
It's possible that an API key can exist which has delete-api-key permission but not grant-role permission for all roles on an API key. However, I don't see a use case for this since, unlike API key creation, deletion in practice is tightly controlled and limited only to Emo administrators. It seems like a bad practice to delegate this particular permission to non-trusted administrators.
TL;DR: I have no objection to adding this check, it just seemed redundant since any user with delete permission would be an administrator.
@sujithvaddi Addressed feedback |
jenkins retest this please |
for (String role : apiKey.getRoles()) { | ||
subject.checkPermission(Permissions.grantRole(RoleIdentifier.fromString(role))); | ||
} | ||
|
||
_authIdentityManager.deleteIdentity(key); |
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.
@billkalter Looks good. 👍
Github Issue
None
What Are We Doing Here?
Currently the ability to create roles, create API keys, and assign roles to API keys are all managed by the following wide permissions:
system|manage_roles
can CRUD any rolesystem|manage_api_keys
can CRUD any API key and assign or unassign any role from any API keyWith the move to delegated authentication these permissions are being replaced with much narrower ones:
role|read
, which can be restricted by role group and then further restricted by ID. For example,role|*|team_x|*
grants full permissions on any role in the "team_x" group and no permissions on any role outside that group.role|grant|team_x|*
grants permission to add or remove any role in group "team_x" to or from any API key.apikey|read
. Since API keys are randomly generated and there is currently no concept of grouping API keys by any attribute these provide blanket permissions to act on any API key. For example,apikey|read
grants the ability to read all API keys, though other permissions would be necessary create, update, or delete an API key.Several notable decisions made in this PR:
role|grant|...
. There didn't seem to be a use case where a user could grant a role but not be able to revoke it, or vice versa, so separating them would be an unnecessary complication.role|read|_|*
How to Test and Verify
role
andapikey
permissions.Risk
Risk is relatively low. Currently only administrators can perform these tasks anyway, so worst case if there is an issue it won't be client-facing. The actual validation of all existing permissions is unchanged so there is no risk of breaking existing non-administrative API keys or their ability to interact normally with EmoDB.
Level
Medium
Required Testing
Manual
Risk Summary
The greatest risk is that the new permissions don't work as expected and lock out administrative access. However, even were that to happen it's not client-facing and can be worked around until a fix version is released.
Code Review Checklist
Tests are included. If not, make sure you leave us a line or two for the reason.
Pulled down the PR and performed verification of at least being able to
build and run.
Well documented, including updates to any necessary markdown files. When
we inevitably come back to this code it will only take hours to figure out, not
days.
Consistent/Clear/Thoughtful? We are better with this code. We also aren't
a victim of rampaging consistency, and should be using this course of action.
We don't have coding standards out yet for this project, so please make sure to address any feedback regarding STYLE so the codebase remains consistent.
PR has a valid summary, and a good description.