-
Notifications
You must be signed in to change notification settings - Fork 72
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
[Backend] Add Role-Based Permissions [#2606] #2671
Conversation
…f just scopes. Roles will be associated with a list of scopes. - Update the permission check in verify_oauth_client to see if you have the scope from one of two means: either a scope you were assigned directly OR if your role(s) are associated with that scope. - Add client.roles and fidesuserpermission.roles column. Make FidesUserPermissions.scopes and client.scopes nullable, as you can assign roles or scopes. - Add a new endpoint /oauth/role to get the possible roles and their associated scopes to which you can be assigned - Update POST /oauth/token to add an admin role if the client is the root client. - Update Patch user permissions to be able to update both roles and scopes - Update get user permissions to return both the scope registry and admin roles if this is the root user. - Update CLI command "fides user permissions" to return both roles and directly-assigned scopes - Update CLI command "fides user create" which creates a user with full permissions to also have the admin role. - Add ExecutionSettings.root_user_roles - Fix the default values on Client.scopes and FidesUserPermission.scopes - this did not appear to be working as intended - Try to ensure that if a client's roles or scopes are accessed, it returns an empty list instead of null if they don't exist. - Add first draft of role -> scope mapping. - Remove old, unused privileges code. We were once intending to group scopes into "privileges" but never finished that work. This replaces that effort. - On login, give the client both root_user_scopes and root_user_roles if it's the root user. Persist permission scopes and roles to the client if the client doesn't exist.
# Conflicts: # src/fides/core/user.py # src/fides/lib/models/fides_user_permissions.py # src/fides/lib/oauth/privileges.py # tests/lib/conftest.py # tests/lib/test_client_model.py # tests/lib/test_oauth_util.py
Passing run #436 ↗︎
Details:
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
Codecov ReportBase: 86.46% // Head: 86.50% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2671 +/- ##
==========================================
+ Coverage 86.46% 86.50% +0.03%
==========================================
Files 289 288 -1
Lines 15982 16025 +43
Branches 2027 2035 +8
==========================================
+ Hits 13819 13862 +43
Misses 1779 1779
Partials 384 384
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
…ng - likely because we had two sets of user permissions schemas from the fideslib merge. - Make the "id" optional in the request to edit user permissions. The UI still passes this in but it's not used and we don't need it. - Annotate the db_dataset with the new fields.
- Assert 422 when trying to create user perms w/ invalid scope.
src/fides/api/ctl/migrations/versions/d65bbc647083_adds_gpc_info_to_consent_table.py
Outdated
Show resolved
Hide resolved
src/fides/api/ops/api/v1/endpoints/user_permission_endpoints.py
Outdated
Show resolved
Hide resolved
# Conflicts: # src/fides/core/config/security_settings.py # src/fides/core/user.py # src/fides/lib/models/fides_user_permissions.py # tests/lib/conftest.py # tests/lib/test_client_model.py # tests/lib/test_fides_user_permissions.py # tests/lib/test_oauth_util.py
…ole to the root user, pull this from the config settings instead. Permissions tests deleted (these were the "privileges" tests which is obsolete.)
hi @TheAndrewJackson @ThomasLaPiana @sanders41 @seanpreston - I'm looking for a reviewer that's worked on permissions-related items if one of you has time to look (or anyone else too!) In short, this work adds the ability to assign a larger role to a user (which is associated with a list of scopes) in addition to still preserving the ability to assign scopes directly. Permission checking still looks to see if the user has the necessary scope - whether it was assigned directly or the user has a role associated with that scope. |
Looking now 👁️ |
@pattisdr is it worth updating the CLI |
src/fides/api/ctl/migrations/versions/985d3756f908_add_role_based_foundation.py
Outdated
Show resolved
Hide resolved
CONFLICT (content): Merge conflict in tests/lib/conftest.py CONFLICT (content): Merge conflict in tests/lib/test_client_model.py CONFLICT (content): Merge conflict in tests/ops/api/v1/endpoints/test_connection_config_endpoints.py CONFLICT (content): Merge conflict in tests/ops/api/v1/endpoints/test_user_endpoints.py CONFLICT (content): Merge conflict in tests/ops/api/v1/endpoints/test_user_permission_endpoints.py CONFLICT (content): Merge conflict in tests/ops/conftest.py
…n't nullable previously). Default to an empty list.
…client - need all roles for test purposes so the client has the same role as the token.
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.
This looks fantastic! Looks good for merge if the checklist is satisfied
src/fides/api/ctl/migrations/versions/eb1e6ec39b83_add_role_based_permissions.py
Show resolved
Hide resolved
Thanks for your reviews @sanders41 and @ThomasLaPiana! |
Closes #2606
Code Changes
verify_oauth_client
to see if you have the scope from one of two means: either a scope you were assigned directly OR if your role(s) are associated with that scope.client.roles
andfidesuserpermission.roles
column. Default values are empty lists and scopes are changed likewise./oauth/role
to surface the possible roles and their associated scopes to which you can be assignedPOST /oauth/token
to add an admin role to the the token if the client is the root client.ExecutionSettings.root_user_roles
Client.scopes
andFidesUserPermission.scopes
- this did not appear to be working as intended, but we weren't hitting the error in practice.Steps to Confirm
POST {{host}}/user
admin
,viewer_and_privacy_request_manager
andviewer
,privacy_request_manager
:PUT {{host}}/user/{{user_id}}/permission
Pre-Merge Checklist
CHANGELOG.md
Description Of Changes
Optionally add the ability to grant larger roles directly to users instead of just individual scopes. Roles will be associated with a list of scopes.
Currently supporting 4 roles: