Skip to content

[PM-19801] Clear device keys on deactivate #5592

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

Merged
merged 4 commits into from
Apr 7, 2025
Merged

Conversation

quexten
Copy link
Contributor

@quexten quexten commented Apr 2, 2025

🎟️ Tracking

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

📔 Objective

Encryption keys need to be removed from the device table once a device is deactivated, because the user expects to have revoked access, but e.g. key rotation and other operation will continuously re-share the new encryption keys to the devices.

📸 Screenshots

⏰ 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

@quexten quexten requested a review from a team as a code owner April 2, 2025 10:16
@quexten quexten changed the title Clear device keys on deactivate [PM-19801] Clear device keys on deactivate Apr 2, 2025
@quexten quexten requested a review from a team April 2, 2025 10:16
Copy link
Contributor

github-actions bot commented Apr 2, 2025

Logo
Checkmarx One – Scan Summary & Details39d0a942-b812-409e-8944-53fc9c363c67

Great job, no security vulnerabilities found in this Pull Request

Copy link

codecov bot commented Apr 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 44.99%. Comparing base (f90bcd4) to head (3b60c35).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
src/Core/Services/Implementations/DeviceService.cs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5592      +/-   ##
==========================================
+ Coverage   44.90%   44.99%   +0.08%     
==========================================
  Files        1559     1563       +4     
  Lines       71160    71595     +435     
  Branches     6357     6407      +50     
==========================================
+ Hits        31957    32213     +256     
- Misses      37851    38015     +164     
- Partials     1352     1367      +15     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

EncryptedPublicKey IS NOT NULL OR
EncryptedPrivateKey IS NOT NULL
);
GO;
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Newline at end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@quexten quexten requested a review from withinfocus April 2, 2025 12:55
withinfocus
withinfocus previously approved these changes Apr 2, 2025
Copy link
Contributor

@withinfocus withinfocus left a comment

Choose a reason for hiding this comment

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

Works for me, as long as device deactivation solely runs through this service method; my understanding is the use of the new-ish active bit is in progress.

@quexten quexten requested review from a team and Patrick-Pimentel-Bitwarden and removed request for a team April 2, 2025 13:30
@quexten
Copy link
Contributor Author

quexten commented Apr 2, 2025

Added auth as reviewer since they own the device management feature (even if they don't own this service).

Copy link
Contributor

@ike-kottlowski ike-kottlowski Apr 2, 2025

Choose a reason for hiding this comment

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

💭 : This script will need to be translated to the other database providers that we support PostgreSQL, SQLite, and MySQL (MariaDb) and ran using the entity framework migrator. For example

Should be easy enough to translate, you just have to create an empty Entity Framework migration (just run the migrator script IIRC) then edit the migration file to run the script, like the one I linked. You'll need to place the script in the HelperScripts directory of the migrator project.

A gotcha is postgreSQL uses the .psql file extension.

Since this is data deletion, I would be very careful to test it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked with the Auth Team and we aren't sure that there are any devices now that are in a state where device.active = false and device.<keys> != null. Because the de-active feature isn't live yet.

@rkac-bw do we have any devices today that meet this criteria?

# Psudo
SELECT COUNT(*)
FROM dbo.devices d
WHERE d.active = 0
  AND d.EnryptedPrivateKey IS NOT NULL;

If there are no devices that meet that criteria then there is no need for the script since we have modified the service to remove the keys when device.Active = false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed the migration for now. If these users do happen to exist we can always add a migration later.

@Patrick-Pimentel-Bitwarden Patrick-Pimentel-Bitwarden removed their request for review April 2, 2025 18:52
Copy link

sonarqubecloud bot commented Apr 3, 2025

@quexten quexten merged commit 7c76edd into main Apr 7, 2025
54 checks passed
@quexten quexten deleted the km/delete-clear-device-keys branch April 7, 2025 12:35
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