8000 RBAC implementation for key value pair by shivani-orch · Pull Request #55 · StackStorm/st2-rbac-backend · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RBAC implementation for key value pair #55

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

Merged
merged 52 commits into from
Dec 10, 2021

Conversation

shivani-orch
Copy link
@shivani-orch shivani-orch commented Sep 9, 2021

Implemented RBAC functionality and unit tests for key-value pairs for existing and new permission types. Previously, RBAC feature for key value pairs are not yet implemented.

  • Existing permission types - KEY_VALUE_VIEW, KEY_VALUE_SET, KEY_VALUE_DELETE
  • New permission types - KEY_VALUE_LIST, KEY_VALUE_ALL

RBAC is enabled in the st2.conf file. Access to a key value pair is checked in the KeyValuePair API controller.

  • SET and DELETE permissions will automatically grant LIST and VIEW permissions.
  • By default, user has access to his/her own user scoped KVPs without requiring specific permission grant.
  • A non-admin user can be explicitly granted permission to one or more system scoped KVPs.
  • A non-admin user cannot access another user's KVPs.
  • By default, admin and system_admin has ALL access to system scoped KVPs.
  • Admin has full access to another user's KVPs (behavior in current version).

This change requires KeyValuePair API changes at StackStorm/st2#5354.

@shivani-orch shivani-orch reopened this Sep 9, 2021
@shivani-orch
Copy link
Author

We couldn't resolve why circleci checks have failed.
Following is the error - . virtualenv/bin/activate; flake8 --config=lint-configs/python/.flake8 st2rbac_backend/ tests/
/bin/sh: 85: virtualenv/bin/activate: /tmp/st2/st2api: Permission denied

@m4dcoder
Copy link
Contributor

Please make sure CIs are green before asking for reviews.

@m4dcoder
Copy link
Contributor

@ashwini-orchestral The CIs are failing with the following. If you click on "Details" above next to the failed job, do you see the details?

. virtualenv/bin/activate; pylint -j 1 -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models --load-plugins=pylint_plugins.db_models st2rbac_backend/
************* Module st2rbac_backend.resolvers
st2rbac_backend/resolvers.py:726:35: E1101: Class 'PermissionType' has no 'KEY_VALUE_LIST' member (no-member)
make: *** [Makefile:115: .pylint] Error 2

Copy link
Contributor
@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments that need to be addressed. Otherwise, LGTM.

Copy link
Contributor
@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor the unit tests to cover test cases I documented in the comments.

)
UserRoleAssignment.add_or_update(role_assignment_db)

def test_user_resource_db_permissions(self):
Copy link
Contributor
@m4dcoder m4dcoder Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This single test function covers too much. It's also missing some test cases.

Please separate current test function to multiple test functions (or classes/modules) for readability. Please also move the creation of required user/roles/grants to the test functions for readability. Right now, those are all put into the setup method and it's hard to figure out which users/roles/grants are for which tests.

Please systematically refactor the unit tests according to the following list.

  • System roles

    • System Observer role on all system scoped KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_observer_permissions_for_system_scope_kvps
      • Succeed on LIST permission
      • Succeed on VIEW permission
      • Fail on SET permission
      • Fail on DELETE permission
    • System Admin role on all system scoped KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_admin_permissions_for_system_scope_kvps
      • Succeed on ALL permission
    • System role should have permission to other users' KVPs (edited)
      • Currently, StackStorm grants admin access permission to another users' KVPs. Keep this behavior to not introduce breaking changes.
        KeyValueUserScopePermissionsResolverTestCase.test_admin_permissions_for_user_scoped_kvps
  • Default for user on user owned KVPs

    • No specific roles and grants need to be defined for user to set/delete their own KVPs. Succeed on ALL permission to user owned KVPs. KeyValueUserScopePermissionsResolverTestCase.test_user_permissions_for_user_scope_kvps
    • User should not have any permission to another user's KVPs. KeyValueUserScopePermissionsResolverTestCase.test_user_permissions_on_another_user_kvps
  • User roles with permission on specific system scope KVPs

    • User by default has no access to any system scope KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_user_default_permissions_for_system_scope_kvps
    • Custom user role with LIST on specific system scope KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_user_custom_read_permissions_for_system_scope_kvps
      • Succeed on LIST permission
      • Should VIEW permission succeed or fail here?
      • Fail on SET permission
      • Fail on DELETE permission
    • Custom user role with VIEW on specific system scope KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_user_custom_read_permissions_for_system_scope_kvps
      • Succeed on LIST permission
      • Succeed on VIEW permission
      • Fail on SET permission
      • Fail on DELETE permission
    • Custom user role with SET on specific system scope KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_user_custom_set_permissions_for_system_scope_kvps
      • Succeed on LIST permission
      • Succeed on VIEW permission
      • Succeed on SET permission
      • Fail on DELETE permission
    • Custom user role with DELETE on specific system scope KVPs
      KeyValueSystemScopePermissionsResolverTestCase.test_user_custom_delete_permissions_for_system_scope_kvps
      • Succeed on LIST permission
      • Succeed on VIEW permission
      • Fail on SET permission (requires explicit set on system kvps)
      • Succeed on DELETE permission

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashwini-orchestral Please review the outline above. I highlighted the unit tests for each of the test cases in the outline here.

@ankita-orchestral
Copy link
Contributor

@m4dcoder - We have refactored the unit test cases as per your comment. Please review and let us know your feedback.

Rollback manual code formatting changes made by developer.
The removal of empty lines in docs section of codes make them not
readable.
m4dcoder added a commit to StackStorm/st2 that referenced this pull request Sep 22, 2021
Add RBAC permission types for key value pairs so the changes at
StackStorm/st2-rbac-backend#55 to introduce RBAC
to KVP can pass CI.
By default, user has access to their own user scoped KVPs. Therefore,
the list permission should be assigned automatically to users.
@amanda11
Copy link
Contributor

LGTM - with an imminent release of 3.6 do we need to make sure that this only goes in with the paired ST2 pair?

ankita-orchestral and others added 5 commits September 30, 2021 03:10
Currently, st2 permits administrator to have access to another user's
key value pairs. To avoid introducing breaking changes, make feature
backward compatible.
Copy link
Member
@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot here. It will be wonderful to have RBAC on the datastore. :)
I have a couple of questions, but overall I think this is excellent.

Copy link
Member
@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. I don't see anything else that has to be changed before we merge.

Refactor unit tests for key value API controller to match test cases in
the unit tests for the key value permission resolvers.
Ensure that values are encrypted and can be decrypted if user has
permission.
Temporary and should be replaced with main st2 repo before merge.
The PR depends on changes from a development branch. The target repo and
branch was changed to the development branch temporary.
@m4dcoder m4dcoder merged commit 405fdb2 into StackStorm:master Dec 10, 2021
@m4dcoder m4dcoder deleted the keyValuePair branch December 10, 2021 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0