Skip to content

db: encrypt userdata - #14589

Draft
DaanHoogland wants to merge 2 commits into
mainfrom
ghi14530-db-encrypt-userdata
Draft

DaanHoogland wants to merge 2 commits into
mainfrom
ghi14530-db-encrypt-userdata

Conversation

@DaanHoogland

@DaanHoogland DaanHoogland commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Userdata was stored as plain base64 in user_vm.user_data, user_data.user_data and autoscale_vmprofiles.user_data. It often contains cloud-init credentials, which anyone with DB read access could decode. Other secrets in the DB are already encrypted with the DB encryption key. This PR does the same for userdata.

  • @Encrypt on the user_data field of UserVmVO, UserDataVO, AutoScaleVmProfileVO, and on UserVmJoinVO, which reads the column through user_vm_view.
  • UserDataDaoImpl.findByUserData, used for the duplicate check in registerUserData, matched the content in SQL. Encryption is non-deterministic, so it now narrows the search by account and domain and compares the decrypted values.
  • Upgrade42300to2400.performDataMigration encrypts the existing rows in the three tables. The columns are mediumtext, which leaves room for encrypted values above the 1 MB userdata limit.

When DB encryption is not enabled, DBEncryptionUtil leaves values unchanged, so the behaviour is the same as before.

Related: #14530, #14588

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale

  • Major
  • Minor

How Has This Been Tested?

Unit tests:

  • UserDataDaoImplTest: the duplicate lookup matches on the decrypted value
  • DatabaseUpgradeCheckerTest still passes

To do before merge: upgrade a 4.23 DB with existing VMs, registered userdata and autoscale profiles. Then check that listVirtualMachines (details=all) and getVirtualMachineUserData return the original userdata, that config drive / VR metadata still serve it, and that registering duplicate userdata is still rejected.

How did you try to break this feature and the system with this change?

Searched for SQL that reads or matches user_data content. The only matches were the duplicate check (fixed here) and older upgrade steps, which run before this one. Readers in the management server go through the VOs, which decrypt the value.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 5.26316% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.78%. Comparing base (fb60564) to head (4087dde).

Files with missing lines Patch % Lines
...java/com/cloud/upgrade/dao/Upgrade42300to2400.java 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #14589   +/-   ##
=========================================
  Coverage     20.78%   20.78%           
- Complexity    21931    21934    +3     
=========================================
  Files          6496     6496           
  Lines        591657   591673   +16     
  Branches      72592    72593    +1     
=========================================
+ Hits         122966   122984   +18     
+ Misses       455346   455342    -4     
- Partials      13345    13347    +2     
Flag Coverage Δ
uitests 3.88% <ø> (ø)
unittests 22.09% <5.26%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🔴 Test Coverage Grade: D — Marginal

Metric Value
Line coverage 25.89%
Branch coverage 20.22%

Grade Scale

Grade Line Coverage Meaning
🟢 A ≥ 80% Excellent - this code sleeps well at night 😴
🟡 B 60-79% Good - almost there, don't stop now 😉
🟠 C 40-59% Acceptable - your code is wearing a seatbelt, but no airbags 😬
🔴 D 20-39% Marginal - boldly shipping where no test has gone before 🖖
⛔ F < 20% Failing - tests? what tests? 🔥

Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run

@DaanHoogland
DaanHoogland force-pushed the ghi14530-db-encrypt-userdata branch from 476dae2 to 4087dde Compare November 6, 2026 14:16
@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.4% Coverage on New Code (required ≥ 40%)
C Security Rating on New Code (required ≥ B)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Hardening] F-21: Base64-Encoded User Data Containing Plain Text Passwords in DB.

2 participants