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

[SM-378] Enable SM on a user basis #2590

Merged
merged 17 commits into from
Jan 31, 2023
Merged

[SM-378] Enable SM on a user basis #2590

merged 17 commits into from
Jan 31, 2023

Conversation

Hinton
Copy link
Member

@Hinton Hinton commented Jan 17, 2023

Type of change

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

Objective

Adds support for enabling access to secrets manger on a per user basis. And adds checks to the list projects and secrets endpoints to verify access.

Left to add:

  • Access checks for remaining endpoints

Code changes

  • src/Api/Controllers/ProjectsController.cs: Check that the user has access to secrets manager on list projects.
  • src/Api/Controllers/SecretsController.cs: Check that the user has access to secrets manager on list secrets.
  • src/Api/Controllers/ServiceAccountsController.cs: Check that the user has access to secrets manager on list service accounts.
  • src/Api/Models/Request/Organizations/OrganizationUserRequestModels.cs/ResponseModels.cs: Add AccessSecretsManager to request/response model (enables setting permission).
  • src/Api/Models/Response/ProfileOrganizationResponseModel.cs: Include if the user has access to secrets manager in the sync response. Used to determine access in the client.
  • src/Core/Context/CurrentContentOrganization.cs: Change current context to use OrganizationUserOrganizationDetails when building the scopes.
  • src/Core/Context/CurrentContext.cs: Add AccessSecretsManager function on the CurrentContext used to determine if the user and org is allowed to access the secrets manager.
  • src/Core/Entities/OrganizationUser.cs: Add AccessSecretsManager to the user table.
  • src/Core/Identity/Claims.cs: Add a new claim for the jwt access.
  • src/Core/Utilities/CoreHelpers.cs: Add support for building the claims for SM.
  • src/Sql/dbo/*.sql: Update sprocs to support the new column.

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

@@ -14,6 +15,8 @@ public static class Claims
public const string ProviderAdmin = "providerprovideradmin";
public const string ProviderServiceUser = "providerserviceuser";

public const string SecretsManagerAccess = "accesssecretsmanager";
Copy link
Member Author

Choose a reason for hiding this comment

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

:/ Feels like there should be a better way to handle these things.

@Hinton Hinton marked this pull request as ready for review January 20, 2023 13:39
@Hinton Hinton requested a review from a team January 20, 2023 13:39
# Conflicts:
#	src/Api/Controllers/ProjectsController.cs
# Conflicts:
#	src/Api/SecretsManager/Controllers/SecretsController.cs
#	src/Api/SecretsManager/Controllers/ServiceAccountsController.cs
Copy link
Contributor

@cd-bitwarden cd-bitwarden left a comment

Choose a reason for hiding this comment

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

Looks good to me, I definitely see that there will be a few conflicts when I merge this into my PR though 😅

I left a couple comments, nothing major just curious about 1 or 2 things.

Thomas-Avery
Thomas-Avery previously approved these changes Jan 26, 2023
Copy link
Contributor

@Thomas-Avery Thomas-Avery left a comment

Choose a reason for hiding this comment

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

LGTM.

Any places we should use UnauthorizedAccessException or just use NotFoundException everywhere now?

@Hinton
Copy link
Member Author

Hinton commented Jan 27, 2023

@Thomas-Avery I noticed we should have used forbidden but we don't have an exception for that and changed to not found. Open for re-adding forbidden though but it's a balance point between if we should disclose the existence of items you don't have permission to or just pretend they don't exists.

@Hinton Hinton requested a review from Thomas-Avery January 31, 2023 15:54
Copy link
Contributor

@Thomas-Avery Thomas-Avery left a comment

Choose a reason for hiding this comment

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

Are we good with the stored proceduresOrganizationUser_CreateWithCollections that flows into OrganizationUser_Create not supporting the new flag?

Same question with OrganizationUser_UpdateWithCollections -> OrganizationUser_Update

@Hinton
Copy link
Member Author

Hinton commented Jan 31, 2023

@Thomas-Avery
Copy link
Contributor

Thomas-Avery commented Jan 31, 2023

@Thomas-Avery not sure I follow, those are updated? https://github.com/bitwarden/server/pull/2590/files#diff-f74fe3dc4ae507f56ff7d9dfdfc3d3d0d3cdf13a7045020441bb2063b73fb9a0R21

My apologies, I must have been in the view that just showed the changes since my last review.

Approved

@Hinton Hinton merged commit cf25d55 into master Jan 31, 2023
@Hinton Hinton deleted the sm/SM-378 branch January 31, 2023 17:38
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.

3 participants