Skip to content

Fix authorization rules to the Assistant and UserPreferences service#29481

Merged
jakule merged 13 commits intomasterfrom
jakule/assist-rbac
Aug 2, 2023
Merged

Fix authorization rules to the Assistant and UserPreferences service#29481
jakule merged 13 commits intomasterfrom
jakule/assist-rbac

Conversation

@jakule
Copy link
Copy Markdown
Contributor

@jakule jakule commented Jul 24, 2023

Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/userpreferences/userpreferencesv1/service.go Outdated
Comment thread lib/auth/userpreferences/userpreferencesv1/service_test.go Outdated
Comment thread lib/auth/userpreferences/userpreferencesv1/service.go Outdated
Comment thread lib/auth/userpreferences/userpreferencesv1/service_test.go Outdated
@greedy52 greedy52 removed their request for review July 24, 2023 19:35
@jakule jakule force-pushed the jakule/assist-rbac branch from 7e2587c to 547ef71 Compare July 24, 2023 20:55
@jakule jakule requested review from Joerger and zmb3 July 24, 2023 21:49
Comment thread lib/auth/userpreferences/userpreferencesv1/service.go Outdated
Comment thread lib/auth/userpreferences/userpreferencesv1/service.go Outdated
Comment thread lib/authz/permissions.go Outdated
Comment thread lib/auth/userpreferences/userpreferencesv1/service_test.go Outdated
@jakule jakule force-pushed the jakule/assist-rbac branch from 1ee274c to a33a3e0 Compare July 27, 2023 03:14
@jakule jakule requested a review from Joerger July 27, 2023 03:16
Comment thread lib/auth/userpreferences/userpreferencesv1/service_test.go Outdated
Comment thread lib/authz/permissions.go
Comment thread lib/auth/userpreferences/userpreferencesv1/service.go Outdated
Comment thread lib/services/userpreferences.go Outdated
jakule added 8 commits July 28, 2023 18:54
This commit introduces authorization rules into the Assistant service to restrict operations based on the authenticated user's role permissions.

Now each method in the Assistant service checks if the authenticated user has necessary permissions to perform the requested operation. The permissions are checked via defined RBAC rules.

A user requires specific permissions to perform various operations such as creating a conversation, updating a conversation, fetching a user's conversations, deleting a conversation, and adding a message to a conversation.

Also, even if a user has necessary permissions, they cannot perform operations for a different user. Each user can only access their own data.
This commit refactors how GetUserPreferences and UpsertUserPreferences handle requests.
The `username` field is removed from request parameters. Instead of having the client send the user's username in a request, the server now automatically uses the username of the authenticated user making the request.
This change improves the security by preventing a user from attempting to fetch or manipulate another user's preferences. Removed tests were specifically testing the old, insecure behavior.
Refactored code in the 'auth_with_roles.go' file to use 'authz.HasBuiltinRole' instead of 'HasBuiltinRole'. This change is in line with recommended practices for deprecation and makes the code more standard and easier to manage. The original 'HasBuiltinRole' function is marked as deprecated and will be removed in future once 'teleport.e' is updated to use 'authz.HasBuiltinRole'.
This commit introduces two new methods in permissions.go to check if a user is a local user, and if a given action is performed by a local user. These permission checks are then used to replace existing checks in service.go, when performing actions like creating conversation, updating, listing, etc. This simplifies checks and provides a more consolidated and unified method for verifying user actions.
@jakule jakule force-pushed the jakule/assist-rbac branch from a33a3e0 to ac9a4de Compare July 28, 2023 23:13
@jakule jakule requested a review from Joerger July 28, 2023 23:26
Comment thread lib/auth/assist/assistv1/service.go Outdated
Comment thread lib/auth/assist/assistv1/service.go Outdated
Co-authored-by: Brian Joerger <bjoerger@goteleport.com>
@jakule jakule force-pushed the jakule/assist-rbac branch from d0afa59 to d38636a Compare August 1, 2023 14:16
@jakule
Copy link
Copy Markdown
Contributor Author

jakule commented Aug 2, 2023

Ping @r0mant @zmb3 @ryanclark

Copy link
Copy Markdown
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

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

Bot.

@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from ryanclark August 2, 2023 20:09
@jakule jakule added this pull request to the merge queue Aug 2, 2023
Merged via the queue into master with commit 7b5aec2 Aug 2, 2023
@jakule jakule deleted the jakule/assist-rbac branch August 2, 2023 21:20
@public-teleport-github-review-bot
Copy link
Copy Markdown

@jakule See the table below for backport results.

Branch Result
branch/v12 Failed
branch/v13 Create PR

jentfoo pushed a commit that referenced this pull request Oct 31, 2023
…29481)

* "Add authorization rules to the Assistant and UserPreferences service"

This commit introduces authorization rules into the Assistant service to restrict operations based on the authenticated user's role permissions.

Now each method in the Assistant service checks if the authenticated user has necessary permissions to perform the requested operation. The permissions are checked via defined RBAC rules.

A user requires specific permissions to perform various operations such as creating a conversation, updating a conversation, fetching a user's conversations, deleting a conversation, and adding a message to a conversation.

Also, even if a user has necessary permissions, they cannot perform operations for a different user. Each user can only access their own data.

* Add missing logger

* "Refactor user preferences request handling"

This commit refactors how GetUserPreferences and UpsertUserPreferences handle requests.
The `username` field is removed from request parameters. Instead of having the client send the user's username in a request, the server now automatically uses the username of the authenticated user making the request.
This change improves the security by preventing a user from attempting to fetch or manipulate another user's preferences. Removed tests were specifically testing the old, insecure behavior.

* Refactor to use authz.HasBuiltinRole

Refactored code in the 'auth_with_roles.go' file to use 'authz.HasBuiltinRole' instead of 'HasBuiltinRole'. This change is in line with recommended practices for deprecation and makes the code more standard and easier to manage. The original 'HasBuiltinRole' function is marked as deprecated and will be removed in future once 'teleport.e' is updated to use 'authz.HasBuiltinRole'.

* Reserve removed username again?

* Fix UT

* Add local user permissions checks in authz

This commit introduces two new methods in permissions.go to check if a user is a local user, and if a given action is performed by a local user. These permission checks are then used to replace existing checks in service.go, when performing actions like creating conversation, updating, listing, etc. This simplifies checks and provides a more consolidated and unified method for verifying user actions.

* Fix tests

* Tweak RBAC

* Address review comments

* Separate client and server interfaces for user preference services.

* Apply core review suggestions

* Apply suggestions from code review

Co-authored-by: Brian Joerger <bjoerger@goteleport.com>

---------

Co-authored-by: joerger <bjoerger@goteleport.com>
github-merge-queue Bot pushed a commit that referenced this pull request Nov 6, 2023
…rvice (#34090)

* Fix authorization rules to the Assistant and UserPreferences service (#29481)

* "Add authorization rules to the Assistant and UserPreferences service"

This commit introduces authorization rules into the Assistant service to restrict operations based on the authenticated user's role permissions.

Now each method in the Assistant service checks if the authenticated user has necessary permissions to perform the requested operation. The permissions are checked via defined RBAC rules.

A user requires specific permissions to perform various operations such as creating a conversation, updating a conversation, fetching a user's conversations, deleting a conversation, and adding a message to a conversation.

Also, even if a user has necessary permissions, they cannot perform operations for a different user. Each user can only access their own data.

* Add missing logger

* "Refactor user preferences request handling"

This commit refactors how GetUserPreferences and UpsertUserPreferences handle requests.
The `username` field is removed from request parameters. Instead of having the client send the user's username in a request, the server now automatically uses the username of the authenticated user making the request.
This change improves the security by preventing a user from attempting to fetch or manipulate another user's preferences. Removed tests were specifically testing the old, insecure behavior.

* Refactor to use authz.HasBuiltinRole

Refactored code in the 'auth_with_roles.go' file to use 'authz.HasBuiltinRole' instead of 'HasBuiltinRole'. This change is in line with recommended practices for deprecation and makes the code more standard and easier to manage. The original 'HasBuiltinRole' function is marked as deprecated and will be removed in future once 'teleport.e' is updated to use 'authz.HasBuiltinRole'.

* Reserve removed username again?

* Fix UT

* Add local user permissions checks in authz

This commit introduces two new methods in permissions.go to check if a user is a local user, and if a given action is performed by a local user. These permission checks are then used to replace existing checks in service.go, when performing actions like creating conversation, updating, listing, etc. This simplifies checks and provides a more consolidated and unified method for verifying user actions.

* Fix tests

* Tweak RBAC

* Address review comments

* Separate client and server interfaces for user preference services.

* Apply core review suggestions

* Apply suggestions from code review

Co-authored-by: Brian Joerger <bjoerger@goteleport.com>

---------

Co-authored-by: joerger <bjoerger@goteleport.com>

* Fix errors after cherry-pick

* Fix UT

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
Co-authored-by: joerger <bjoerger@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants