DaanHoogland opened a new pull request, #14589: URL: https://github.com/apache/cloudstack/pull/14589
### 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, #<PR 1> ### 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) - [x] 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 - [x] 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](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
