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

[PM-13026] Refactor remove and bulkremove methods to throw error if user is managed by an organization #5034

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

r-tome
Copy link
Contributor

@r-tome r-tome commented Nov 13, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-13026

📔 Objective

Verified members should not be removed. Instead, verified members should go through the deletion flow to ensure all their individual data is properly deleted. This change will prevent accidental removals and enforce consistent deletion practices for verified members.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 97.82609% with 2 lines in your changes missing coverage. Please review.

Project coverage is 43.13%. Comparing base (92b94fd) to head (45c23c0).

Files with missing lines Patch % Lines
...Console/Controllers/OrganizationUsersController.cs 0.00% 1 Missing ⚠️
...OrganizationUsers/RemoveOrganizationUserCommand.cs 98.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5034      +/-   ##
==========================================
+ Coverage   43.09%   43.13%   +0.03%     
==========================================
  Files        1414     1414              
  Lines       64808    64851      +43     
  Branches     5925     5930       +5     
==========================================
+ Hits        27929    27973      +44     
  Misses      35645    35645              
+ Partials     1234     1233       -1     

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


🚨 Try these New Features:

Copy link
Contributor

github-actions bot commented Nov 13, 2024

Logo
Checkmarx One – Scan Summary & Details1fe43fe9-a1b0-4a9d-85f1-ce17d75c7192

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Missing_HSTS_Header /src/Admin/Views/Home/Index.cshtml: 14 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 455 Attack Vector
LOW Log_Forging /src/Api/Auth/Controllers/TwoFactorController.cs: 406 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 339 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 402 Attack Vector
LOW Missing_CSP_Header /src/Core/MailTemplates/Handlebars/FamiliesForEnterprise/FamiliesForEnterpriseRemovedFromFamilyUser.html.hbs: 5 Attack Vector

Fixed Issues

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 106
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 81
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 95
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 238
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 122
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 362
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 131
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 81
MEDIUM CSRF /src/Admin/AdminConsole/Controllers/OrganizationsController.cs: 372
MEDIUM CSRF /src/Api/Vault/Controllers/SyncController.cs: 69
MEDIUM CSRF /src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs: 77
MEDIUM CSRF /src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs: 163
LOW Log_Forging /src/Api/AdminConsole/Controllers/ProvidersController.cs: 72
LOW Log_Forging /src/Api/AdminConsole/Controllers/ProvidersController.cs: 72
LOW Log_Forging /src/Api/AdminConsole/Controllers/ProvidersController.cs: 72

@r-tome r-tome marked this pull request as ready for review November 14, 2024 12:42
@r-tome r-tome requested a review from a team as a code owner November 14, 2024 12:42
@r-tome r-tome requested a review from eliykat November 14, 2024 12:42
Comment on lines 117 to 120
if (managementStatus.TryGetValue(orgUser.Id, out var isManaged) && isManaged)
{
throw new BadRequestException("Managed members cannot be simply removed, their entire individual account must be deleted.");
}
Copy link
Member

Choose a reason for hiding this comment

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

This command is also used by SCIM which can continue to remove managed users (integrations are excluded from the delete behavior until we figure out how to do it safely). So there needs to be some conditionality here. Maybe stealing actingUser from Jared's PR would be useful so it can encapsulate deletingUserId or the SystemUser (and in that case you can exempt SCIM from this check).

I don't love it but I think my problem is with the diverging business logic. Handling it in the command like this seems reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have refactored this so that we don't check managed users when an EventSystemUser is passed.

@r-tome r-tome requested a review from eliykat November 21, 2024 16:06
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.

2 participants