server icon indicating copy to clipboard operation
server copied to clipboard

[SM-713] Add database support for secret access policies

Open Thomas-Avery opened this issue 1 year ago • 3 comments

Type of change

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

Objective

The purpose of this PR is to add database support for individual secret permissions for the Secrets Manager project. This includes changes to EF Core code to clean up secret access policies on deletion events.

Code changes

  • bitwarden_license/src/Commercial.Infrastructure.EntityFramework/SecretsManager/Repositories/ServiceAccountRepository.cs: Move to using a transaction, ExecuteDeleteAsync and added cleanup for secret access policies.

  • src/Core/SecretsManager/Entities/AccessPolicy.cs: Add secret access policy entities.

  • src/Infrastructure.EntityFramework/AdminConsole/Repositories/OrganizationRepository.cs: Add secret access policy cleanup.

  • src/Infrastructure.EntityFramework/AdminConsole/Repositories/OrganizationUserRepository.cs: Add secret access policy cleanup for single delete. Bulk delete was broken swapped to using a transaction, ExecuteDeleteAsync, and cleanup code.

  • src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs: Add new access policy types to database context.

  • src/Infrastructure.EntityFramework/SecretsManager/Configurations/AccessPolicyEntityTypeConfiguration.cs: Add new access policy types to database configuration.

  • src/Infrastructure.EntityFramework/SecretsManager/Discriminators/AccessPolicyDiscriminator.cs: Add new discriminators for TPH mappings.

  • src/Infrastructure.EntityFramework/SecretsManager/Models/AccessPolicy.cs Add mappings for new entities into EF models.

  • src/Infrastructure.EntityFramework/SecretsManager/Models/Secret.cs Add access policy EF navigation properties.

  • src/Sql/SecretsManager/dbo/Tables/AccessPolicy.sql: Add column, FK, and index. Run the mssql formatter on this file to be more inline with our other SQL files.

  • util/Migrator/DbScripts/2024-01-10_00_AddSecretAccessPolicies.sql: Add mssql migration script.

  • util/MySqlMigrations/Migrations/*: MySql EF migrations

  • util/PostgresMigrations/Migrations/*: Postgres EF migrations

  • util/SqliteMigrations/Migrations/*: Sqlite EF migrations

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

Thomas-Avery avatar Jan 17 '24 20:01 Thomas-Avery

Codecov Report

Attention: 54 lines in your changes are missing coverage. Please review.

Comparison is base (374b59b) 36.36% compared to head (caff7a1) 36.42%.

Files Patch % Lines
...Console/Repositories/OrganizationUserRepository.cs 7.69% 24 Missing :warning:
src/Core/SecretsManager/Entities/AccessPolicy.cs 0.00% 13 Missing :warning:
...ityFramework/SecretsManager/Models/AccessPolicy.cs 52.00% 12 Missing :warning:
...re.EntityFramework/SecretsManager/Models/Secret.cs 25.00% 3 Missing :warning:
...dminConsole/Repositories/OrganizationRepository.cs 0.00% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3681      +/-   ##
==========================================
+ Coverage   36.36%   36.42%   +0.05%     
==========================================
  Files        1158     1158              
  Lines       55885    55998     +113     
  Branches     5376     5376              
==========================================
+ Hits        20325    20395      +70     
- Misses      34614    34657      +43     
  Partials      946      946              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 17 '24 20:01 codecov[bot]

Logo Checkmarx One – Scan Summary & Details02c1a8b4-f23c-4b7a-8e54-9657df595c48

No New Or Fixed Issues Found

bitwarden-bot avatar Jan 26 '24 23:01 bitwarden-bot

Quality Gate Failed Quality Gate failed

Failed conditions
21.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Feb 21 '24 16:02 sonarqubecloud[bot]