Repository navigation
Conversation
A CopyCmdAnswer that says nothing about encryption was taken to mean the volume is no longer encrypted. updateVolumeInfo wrote the answer's encryptFormat over the stored one unconditionally, while the size and the format assigned next to it are only written when the answer actually carries a value. Only copyVolumeFromPrimaryToPrimary sets it. The two-leg copy through secondary storage ends in copyVolumeFromImageCacheToPrimary, which builds its answer out of a path and a format alone, so a volume that took the staged path came back with volumes.encrypt_format NULL while its qcow2 on disk still carried a LUKS header and the volume still held its passphrase. Nothing can open it after that: qemu-img asks for encrypt.key-secret and libvirt never supplies one, because no encryption element is written into the domain XML of a volume that claims to be plaintext, and the guest will not start. An absent encrypt format now leaves the stored one alone. The destination row of a migration that is meant to decrypt is built by duplicateVolumeOnAnotherStorage with no encrypt format to begin with - the VolumeVO copy constructor carries over neither the passphrase nor the format - so that path has nothing to clear and is unaffected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
duplicateVolumeOnAnotherStorage builds the destination row from the VolumeVO copy constructor, which carries over neither passphraseId nor encryptFormat, and sets both only when the destination disk offering encrypts. A copy that a migration is decrypting therefore ended up with a NULL encrypt format by omission rather than by intent. That omission is also what makes the guard in updateVolumeInfo safe. An answer carrying no encrypt format now leaves the stored value alone, and on the decrypt path there is no stored value to leave. Were the copy constructor ever taught to carry the two columns across - it already copies most of the others - the destination row would start out claiming LUKS over plaintext bytes and nothing would clear it again, which is the same defect mirrored, with nothing in either file to warn whoever made the change. Set both fields to null explicitly when the offering does not encrypt, so the row's encryption is stated by the migration code rather than inherited from whichever columns a shared constructor happens to skip. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
storage: keep a volume's encrypt format when the copy answer omits it
Symptom
Migrating an encrypted volume between two host-scoped primary storage pools
completes without an error, but silently sets
cloud.volumes.encrypt_formatto NULL. The qcow2 on disk is still LUKS-encrypted and
passphrase_idisstill set, so the row now claims the volume is plaintext while its bytes are
not.
Nothing can open the volume after that. The disk is attached without an
<encryption>element in the domain XML, no secret is handed to qemu, andthe guest fails to start with:
Confirmed on a live system.
Mechanism
AncientDataMotionStrategy.canDirectlyCopyBetweenDataStoreScopes(
engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java:501-531)has cases for two scopes that are the same, for HOST↔CLUSTER and for
HOST↔ZONE, but no case for HOST→HOST. Two distinct host-local pools
are not the same scope, match none of the cross-scope cases and fall through
to
return false.The copy therefore takes the staged two-leg path through secondary storage
rather than a direct primary-to-primary
CopyCommand.Leg 2 is
KVMStorageProcessor.copyVolumeFromImageCacheToPrimary(
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java:623-628).It builds its
VolumeObjectTOout of a format and a path and never callssetEncryptFormat, so the answer carries a null encrypt format. ContrastcopyVolumeFromPrimaryToPrimary, which does set it(
KVMStorageProcessor.java:3212): that is the only copy route in the KVMprocessor that reports the destination's encryption back to the management
server.
VolumeObject.updateVolumeInfo(
engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java:695)then copies that absent value over the good one, unguarded:
The size and format assignments either side of it are guarded against
exactly this —
newVolumeSize != null && setVolumeSizefor the size, andsetVolumeFormatcheckingnewVolume.getFormat() != nullfor the format —so an answer that says nothing about a field leaves that field alone
everywhere except for encryption.
Why upstream never hits it
Upstream refuses encrypted-volume migration outright at
VolumeApiServiceImpl.java:3515-3517:An encrypted volume therefore never reaches
AncientDataMotionStrategyon anon-StorPool, non-PowerFlex pool at all, and the unguarded assignment is never
reached with a LUKS volume on the other side of it. This fork relaxes that
precondition to admit offline KVM file-based encrypted migration
(
isOfflineKvmFileBasedEncryptedVolumeMigration,VolumeApiServiceImpl.java:3702),which is what exposes the latent bug. The defect itself is upstream's and the
fix below stands on its own against upstream.
The fix
Treat an absent encrypt format on the answer as "unchanged", matching how the
size and the format beside it are already handled:
No copy route in the tree ever sets a
VolumeObjectTO's encrypt format tonull deliberately to signal that a volume has been decrypted. The three
producers —
KVMStorageProcessor.java:538,:1766and:3212, plusStorPool's
StorPoolSetVolumeEncryptionCommandWrapper— only ever write anon-null value, and only when the disk actually is encrypted. "Absent" has
never carried meaning on this field, so reading it as "unchanged" is correct.
Safety for the fork's decrypt-on-migration path
A migration that is meant to decrypt a volume does not rely on the answer to
clear
encrypt_format, so the guard changes nothing for it.The destination row is created by
VolumeServiceImpl.duplicateVolumeOnAnotherStorage(
engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java:1742).It starts from
new VolumeVO(volume), andpassphraseId/encryptFormatare set inside the
isEncryptedByItsDiskOffering(newVol, volume)branch. Whenthe destination disk offering is unencrypted that branch does not run, and the
row is persisted with
encrypt_formatNULL.updateVolumeInfoacts on the destination volume —copyVolumecallsdestVolume.processEvent(...)on theVolumeInfobuilt from that row(
VolumeServiceImpl.java:1969-1977) — so on the decrypt path there is nothingfor the assignment to clear.
Second commit: make that safety explicit
Until now the NULL on the decrypt path came from an omission rather than from
a decision. The
VolumeVOcopy constructor(
engine/schema/src/main/java/com/cloud/storage/VolumeVO.java:257-288) copiesmost of a volume's columns but happens to carry over neither
passphraseIdnor
encryptFormat, and with noelsebranch the destination row simplyinherited that gap. The guard above was therefore safe only for as long as
that constructor stayed as it is.
Teaching the copy constructor to carry the two columns — a plausible-looking
change, and one its other callers might even want — would have been enough to
reintroduce the same class of bug from the other side: a destination row left
claiming
encrypt_format = 'LUKS'over plaintext bytes, with the guard nowdeclining to clear it. Nothing in either file said so.
The non-encrypted branch now states the destination's encryption itself:
The behaviour is unchanged today; what changes is that it is decided by the
migration code instead of inherited from a shared constructor, and that a
future change to
VolumeVO(Volume)cannot silently alter it. The copyconstructor itself is deliberately left alone — it has many other callers and
widening it is a separate decision.
Follow-ups (deliberately not in this PR)
Both are real and were found while root-causing this, but each is a separate
change and neither is needed to stop the data-integrity bug:
The API-level precondition does not check scope.
isOfflineKvmFileBasedEncryptedVolumeMigration(VolumeApiServiceImpl.java:3702-3708)admits an encrypted migration on hypervisor, liveness and pool type alone.
It never asks whether the two pools' scopes permit a direct
primary-to-primary copy, so a HOST→HOST pair passes the precondition at
the API and only runs into trouble much further down. The precondition
should refuse what the data motion layer cannot carry out.
copyVolumeFromPrimaryToSecondarydiscards thecopyPhysicalDiskreturnvalue. At
KVMStorageProcessor.java:672the call is made for its sideeffect and the answer is then built from the names the method guessed
beforehand, rather than from the
KVMPhysicalDiskthat was actuallywritten.
copyVolumeFromImageCacheToPrimarydoes it correctly atKVMStorageProcessor.java:619(final KVMPhysicalDisk newDisk = ...).Testing
VolumeObjectTestalready coversupdateVolumeInfo's guarded size handling.Two cases were added alongside those, in the same style:
validateUpdateVolumeInfoEncryptFormatNullDoNotSetEncryptFormat— a nullencrypt format on the answer leaves the stored value untouched.
validateUpdateVolumeInfoEncryptFormatNotNullSetEncryptFormat— a non-nullone is still written through.
The first fails on the unfixed code and passes with the fix.
The second commit needs no new test.
VolumeServiceTestalready pins theinvariant it makes explicit —
duplicateVolumeOnAnotherStorageLeavesADecryptedCopyWithoutAPassphraseassertsa null passphrase and a null encrypt format on the destination of a decrypting
migration, and
duplicateVolumeOnAnotherStorageFallsBackToTheSourceWhenTheDiskOfferingIsGoneasserts the same for a plaintext source whose offering has been removed. Those
assertions are exactly what would start failing if
VolumeVO(Volume)ever grewthe two fields without the explicit
else, so the guard against thatregression is already in place; a further test would only duplicate it.
Full module run on both commits:
Tests run: 64, Failures: 0, Errors: 0, Skipped: 0(VolumeObjectTest37,VolumeServiceTest24).🤖 Generated with Claude Code