Repository navigation
storage: make migrateVolume honour, or refuse, a change of encryption - #9
Conversation
The adaptor already handles a source and a destination that disagree about encryption, but the only cases under test were both passphrases set and neither set. Those two are what a migration that changes encryption relies on, and they are the ones that fail silently rather than loudly: a destination written without a LUKS header still looks like a successful copy. The empty array, not null, is what the management server sends for a volume with no passphrase, so the tests use that. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
copyVolume has always handed the destination volume the source's passphrase, so a copy could only ever come out in the same encryption state it went in. The KVM storage adaptor can re-encrypt during the convert, but nothing above it could ask for that. Carry an encryptDestination flag from VolumeOrchestrationService.migrateVolume down to duplicateVolumeOnAnotherStorage. Encrypting means a key of the copy's own rather than the source's, because the source keeps its plaintext bytes until the migration succeeds and the two must not be confused; decrypting means no key and no encrypt format, so that nothing left behind claims the copy is encrypted once it is not. The null case persists exactly what it did before. The copy routes that cannot re-encrypt - to and from secondary storage, and into managed storage - refuse the flag outright instead of ignoring it. A key minted for a copy that then fails has nothing to decrypt, so drop it along the synchronous failure path; the asynchronous ones already reach VolumeObject.deletePassphrase or cleanUpVolumesForFailedMigrations, both of which count references first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
migrateVolume accepted a newdiskofferingid whose encrypt flag disagreed with the volume, moved the bytes untouched and then relabelled the volume with the new offering. A plaintext volume could come out of the migration reporting an encrypted disk offering, with no LUKS header, no encryption element in its libvirt XML and no passphrase needed to read it. The guard that catches this, validateChangeDiskOfferingEncryptionType, only ever ran on the resize path. Derive the requested change from the volume's passphrase rather than from the encrypt flag of the offering it carries, since those two can already disagree and only the passphrase says anything about the bytes. Where the change can be carried out - offline KVM between the file-based pool types - pass it down so the destination copy is written in the requested state. Everywhere else throw, naming the reason: the hypervisor, the running instance or the pool type that cannot do it. The hypervisor is checked before live migration because a stopped VMware instance also takes the live migration path, and telling its operator to stop it would send them nowhere. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
| * @param encryptDestination whether the volume is to be encrypted on the destination pool; {@code null} leaves it | ||
| * with the encryption state it already has. | ||
| */ | ||
| Volume migrateVolume(Volume volume, StoragePool destPool, Boolean encryptDestination) throws StorageUnavailableException; |
There was a problem hiding this comment.
hm, I'm not sure that introducing the third argument is a good architecture decision. I mean, if src is encrypted, and dst is encrypted, the volume migrates as encrypted already, without the third argument. we should re-use the same method, but at some point we need to create a passphrase, on the place where we would copy it from the original one. I'm not sure how the exact copying is done, but assuming that the destination volume will be with passphrase_id in the db, wouldn't it respect it? this would make the PR as non-obtrusive as possible
There was a problem hiding this comment.
You're right — the third argument is gone.
Your assumption holds literally. VolumeObjectTO is built from the row's passphrase_id (VolumeObjectTO.java:126 → VolumeObject.java:934-939), copyVolumeFromPrimaryToPrimary hands destVol.getPassphrase() straight to the adaptor as dstPassphrase (KVMStorageProcessor.java:3183), and LibvirtStorageAdaptor creates the image and the qemu-img convert secret from it (LibvirtStorageAdaptor.java:1680, 1733-1736), each side guarded by KeyFile.isSet() — so both asymmetric directions already worked. One addition: the agent echoes destVol.getEncryptFormat() back in the answer (KVMStorageProcessor.java:3212), so the destination row needs encrypt_format set up front as well, not just passphrase_id.
The only thing in the way was ordering: updateDiskOffering ran after migrateVolume returned, so at copy time the volume still carried the old offering. The destination row is new VolumeVO(volume), which copies disk_offering_id (VolumeVO.java:278), so moving the offering onto the volume before the copy — with the previous one restored in a finally if the migration doesn't complete — makes the destination inherit the right offering, and duplicateVolumeOnAnotherStorage just reads getEncrypt() off it. diskOfferingDao was already injected there.
Both interface overloads and the tri-state Boolean are dropped; VolumeOrchestrationService, VolumeService and VolumeOrchestrator are no longer touched by this PR at all. validateEncryptionChangeForVolumeMigration is unchanged and still refuses anything but offline KVM between NFS/Filesystem/SharedMountPoint; those pool types never reach copyManagedVolume, so the lower-level rejectEncryptionChange guards went with the argument.
Two notes worth flagging:
- the offering lookup uses
findByIdIncludingRemoved, since a removed offering would otherwise read as "not encrypted" and silently decrypt the copy; - the offering now drives every copy, so a row whose
passphrase_iddisagreed with its offering would flip. Not reachable as far as I can tell: resize refuses to cross the encryption boundary (VolumeApiServiceImpl.java:1286), the passphrase is minted at create time for encrypted offerings, andallocateDuplicateVolumeVOpreserves the pairing — but it is the assumption this design rests on, so worth a second opinion.
The earlier commit that added the parameter is largely reverted by the new one rather than rewritten, so the history shows both steps.
Threading the wanted encryption state down through VolumeOrchestrationService and VolumeService added an argument to two public interfaces for something the copy already reads out of the database. VolumeObjectTO carries whatever passphrase the destination volume row holds, and the KVM adaptor converts the image into exactly that state, so the decision only has to be made where the destination row is built. The destination row inherits the volume's disk offering, so migrateVolume now moves the volume onto its new offering before the copy and puts the old one back if the copy does not happen; a volume must never be left labelled encrypted while its bytes are plaintext. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
| return volDao.persist(newVol); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
I don't believe we need these comments. consider to delete or squash to one-liners
migrateVolume volumeid=X storageid=Y newdiskofferingid=Z, where Z hasencrypt=trueand the volume is plaintext, succeeded with no error, relabelled the volume to the encrypted offering, and left the data in plaintext. Verified on a live deployment: the destination qcow2 had no LUKS header, noencrypted:line inqemu-img info, libvirt attached it with no<encryption>block, and the file mounted from the hypervisor with no passphrase, every sha256 matching the pre-migration manifest. A volume could report an encrypted disk offering while its bytes were plaintext, which makes an audit by offering name worthless.The guard that catches this,
validateChangeDiskOfferingEncryptionType, only ever ran on the resize path. The migrate path validated size, storage type and tags, then relabelled the volume with the new offering once the bytes had been moved untouched.Honour it where it can be done. #8 taught the KVM storage adaptor to re-encrypt during
qemu-img convertwhen the source and destination passphrases differ. What was missing above it was a destination volume with a passphrase of its own.copyVolumeandVolumeOrchestrationService.migrateVolumenow take anencryptDestinationflag down toduplicateVolumeOnAnotherStorage, which allocates a new passphrase for the copy when the new offering asks for encryption, and gives it neither passphrase nor encrypt format when the new offering asks for plaintext. The source keeps its own key throughout, so a failed migration leaves it readable. Both directions work offline on KVM between the file-based pool types.Refuse it everywhere else, with a message that says why rather than "not supported": live migration cannot rewrite an image underneath a running instance; non-KVM hypervisors have no re-encrypting copy; and pool types outside
NetworkFilesystem,FilesystemandSharedMountPointhave no path that carries an asymmetric secret pair. PowerFlex and StorPool are refused for now even though they reportEncryptionSupport.Hypervisor, because their adaptors were not part of #8 and are unverified here.The requested change is derived from the volume's
passphrase_id, not from the encrypt flag of the offering it carries, because those two can already disagree on any volume affected by this bug and only the passphrase says anything about the bytes on disk.A passphrase minted for a copy that then fails is dropped along the synchronous failure path; the asynchronous ones already reach
VolumeObject.deletePassphraseorcleanUpVolumesForFailedMigrations, both of which count references first.No agent-side change was required:
KVMStorageProcessoralready forwards both volumes' passphrases for every ROOT/DATADISK primary-to-primary copy. The asymmetric cases it relies on are now covered inLibvirtStorageAdaptorTest, which previously only exercised "both set" and "neither set".Testing
Full affected-module suites green: engine/api 11, engine/orchestration 223, engine/storage/volume 61, engine/storage/datamotion 62, server 3103 (17 pre-existing skips), plugins/hypervisors/kvm 698 (3 pre-existing skips).
Known gaps
storagePoolHasEnoughSpaceis still computed from the source volume'sDiskProfile. Pre-existing shape of the migrate path, but newly reachable in a case where the size genuinely changes.🤖 Generated with Claude Code