Repository navigation
Database encryption engine migration script fails #9979
Description
Activity
Thanks for opening your first issue here! Be sure to follow the issue template!
@detaras
thanks for reporting the issue, I will have a lookReacted by detaras and luganoferI have found a workaround for this issue.
I took a look at the code of the EncryptionSecretKeyChanger class (located at framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java) and found an error in the query created at lines 656-659:String sqlTemplateDeployAsIsDetails = "SELECT template_deploy_as_is_details.value " + "FROM template_deploy_as_is_details JOIN vm_instance " + "WHERE template_deploy_as_is_details.template_id = vm_instance.vm_template_id " + "vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";If we run the created query in MySQL CLI we get an error and that's because the last line shoud have a connector at the beginning (I think an 'AND' is needed there). After adding that connector and building ACS again, the migration script ended successfully.
The modified code I used is this:
String sqlTemplateDeployAsIsDetails = "SELECT template_deploy_as_is_details.value " + "FROM template_deploy_as_is_details JOIN vm_instance " + "WHERE template_deploy_as_is_details.template_id = vm_instance.vm_template_id " + "AND vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";Reacted by luganofer and Wei ZhouI have found a workaround for this issue. I took a look at the code of the EncryptionSecretKeyChanger class (located at framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java) and found an error in the query created at lines 656-659:
String sqlTemplateDeployAsIsDetails = "SELECT template_deploy_as_is_details.value " + "FROM template_deploy_as_is_details JOIN vm_instance " + "WHERE template_deploy_as_is_details.template_id = vm_instance.vm_template_id " + "vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";If we run the created query in MySQL CLI we get an error and that's because the last line shoud have a connector at the beginning (I think an 'AND' is needed there). After adding that connector and building ACS again, the migration script ended successfully.
The modified code I used is this:
String sqlTemplateDeployAsIsDetails = "SELECT template_deploy_as_is_details.value " + "FROM template_deploy_as_is_details JOIN vm_instance " + "WHERE template_deploy_as_is_details.template_id = vm_instance.vm_template_id " + "AND vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";good finding @detaras
it should be my mistake.can you create a pull request against 4.18 or 4.19 branch ?
- linked a pull request that will close this issuecloudstack-migrate-databases: sql AND added #10033
on Dec 4, 2024 fixed by #10033
Reacted by luganofer
ISSUE TYPE
COMPONENT NAME
Database encryption engine migration script
CLOUDSTACK VERSION
4.18.2.3
CONFIGURATION
Database with legacy cryptographic cipher (MD5/DES)
OS / ENVIRONMENT
Centos 7
SUMMARY
When migrating from the old database encryption scheme (MD5/DES 56-bit) to the new one (AES-GCM 256-bit) using the supplied script (/usr/bin/cloudstack-migrate-databases) from any of the managers; the migration process starts, but suddenly, when working on on the 'user_vm_deploy_as_is_details' table, we get an error and the process fails.
STEPS TO REPRODUCE
EXPECTED RESULTS
The script should end without error. The database content is migrated using the new cipher and the configuration files are updated as needed.
ACTUAL RESULTS
The database and configuration files remains untouched, the migration script fails with the following error: