Skip to content
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

[AC-2172] Member modal - limit admin access #3934

Merged
merged 19 commits into from Apr 29, 2024

Conversation

eliykat
Copy link
Member

@eliykat eliykat commented Mar 28, 2024

Type of change

- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Back-end changes for bitwarden/clients#8343.

Stacked on #3793.

Adds additional authorization logic on the following endpoints:

  • OrganizationUser.Invite
  • OrganizationUser.Put

Also updates authorization handlers for v1 logic.

Code changes

  • OrganizationUsersController

    • Invite - check that the saving user can modify access for the collections they're trying to give the invited user
    • Put - this is more complex. Remember that the access-selector does not emit a value for disabled rows, so the client will only send values for the collections the user can modify. This method now (1) ensures that the user can modify the collection access sent by the client, and (2) concats them with collection access that the user can't change before saving to the database. This ensures we don't overwrite collection access that we don't want to change.
  • BulkCollectionAuthorizationHandler

    • cache the managed collections so that we can call this in a loop in the Put method, above. (Now that I've done this, I think we could remove the "bulk" implementation of this, which would greatly simplify things - but I'll leave that for another day.)
    • change the Update method to take into account v1 flag and collection management setting.
  • OrganizationUser_ReadWithCollectionsById - maybe the last sproc that didn't have the Manage property 😁

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

This comment was marked as off-topic.

@eliykat eliykat force-pushed the ac/ac-2172/member-modal---access-selector-changes branch from 227b4b8 to 88b39eb Compare April 5, 2024 00:47
Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 38.13%. Comparing base (8142ba7) to head (2613c2e).

Files Patch % Lines
...Console/Controllers/OrganizationUsersController.cs 79.24% 5 Missing and 6 partials ⚠️
.../Collections/BulkCollectionAuthorizationHandler.cs 96.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3934      +/-   ##
==========================================
+ Coverage   38.02%   38.13%   +0.11%     
==========================================
  Files        1195     1195              
  Lines       58140    58194      +54     
  Branches     5568     5576       +8     
==========================================
+ Hits        22107    22192      +85     
+ Misses      34994    34957      -37     
- Partials     1039     1045       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eliykat eliykat force-pushed the ac/ac-2172/member-modal---access-selector-changes branch from 88b39eb to c8995c1 Compare April 5, 2024 01:00
@eliykat eliykat changed the title Ac/ac 2172/member modal access selector changes [AC-2172] Member modal - limit admin access Apr 5, 2024
@eliykat eliykat marked this pull request as ready for review April 5, 2024 06:05
@eliykat eliykat requested review from a team as code owners April 5, 2024 06:05
@@ -183,16 +184,29 @@ public async Task<OrganizationUserResetPasswordDetailsResponseModel> GetResetPas
}

[HttpPost("invite")]
public async Task Invite(string orgId, [FromBody] OrganizationUserInviteRequestModel model)
public async Task Invite(Guid orgId, [FromBody] OrganizationUserInviteRequestModel model)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we're starting to get some more business logic in the controller. Do you have any plans/concern here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but it is authorization logic still - you only have to sort the groups and collections in this way because you're accessing it via this endpoint as a user. It doesn't apply to using the public api, for example. This is reflected by the fact that it requires AuthorizationService for this logic, which isn't available in the core layer. So I think it stays here for now, although I do agree that the endpoint itself is on the longer side.

vincentsalucci
vincentsalucci previously approved these changes Apr 9, 2024
Copy link
Member

@vincentsalucci vincentsalucci left a comment

Choose a reason for hiding this comment

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

Besides my question, I think this is good!

@eliykat eliykat added the hold Hold this PR or item until later; DO NOT MERGE label Apr 16, 2024
@eliykat
Copy link
Member Author

eliykat commented Apr 16, 2024

Adding the hold label to remind myself not to merge yet - it's stacked on another feature branch.

Jingo88
Jingo88 previously approved these changes Apr 16, 2024
@eliykat
Copy link
Member Author

eliykat commented Apr 17, 2024

I realised that these changes weren't feature flagged properly - in particular, PUT did not check for org.FlexibleCollections. PUT and POST both contained a v1 flag check inside the authorization handler, but I think it's better if we do it expressly in the controller as well. Therefore:

  • POST now checks the v1 flag explicitly (as well as org.FlexibleCollections)
  • PUT has been split into a separate vNext method which is only called if org.FlexibleCollections and v1 flag is enabled.

This generally just makes the new code more separate from the existing code and ensures that it's only run when the flag is turned on.

@eliykat eliykat force-pushed the ac/ac-2172/member-modal---access-selector-changes branch from d4912be to b8faed7 Compare April 25, 2024 01:25
@eliykat eliykat requested review from a team as code owners April 25, 2024 01:25
@eliykat eliykat requested a review from jlf0dev April 25, 2024 01:25
@eliykat eliykat changed the base branch from vault/ac-2084/include-permissions-for-admin-endpoints to main April 25, 2024 01:25
@eliykat eliykat dismissed stale reviews from vincentsalucci and Jingo88 April 25, 2024 01:25

The base branch was changed.

@eliykat eliykat requested review from rkac-bw and removed request for a team, jlf0dev and shane-melton April 25, 2024 01:25
@eliykat eliykat removed the hold Hold this PR or item until later; DO NOT MERGE label Apr 25, 2024
@eliykat
Copy link
Member Author

eliykat commented Apr 25, 2024

I've rebased this on main so that it's not blocked by #3793. It can't be QA'd without it, but it can be reviewed and merged, and new code is feature flagged so it won't do any harm in the meantime.

That said, I apologise for the rebase blasting away review history. I believe @vincentsalucci and @Jingo88 had reviewed up to and including 1d692e5, however commits after that need a proper review.

Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

@eliykat eliykat merged commit ba36b2d into main Apr 29, 2024
52 checks passed
@eliykat eliykat deleted the ac/ac-2172/member-modal---access-selector-changes branch April 29, 2024 01:02
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.

None yet

4 participants