Repository navigation
Allow offline migration of encrypted volumes between KVM file pools - #8
Merged
Merged
Conversation
LibvirtStorageAdaptor.copyPhysicalDisk has declared srcPassphrase and dstPassphrase since encryption was introduced, but never read them: it created the destination disk unencrypted and ran a bare qemu-img convert. Everything above it already carries the passphrase - KVMStorageProcessor sets LUKS and passes both, KVMStoragePoolManager plumbs them through - so an encrypted volume copied between two file-based pools landed on the destination as plaintext-headed garbage. Open a KeyFile for each passphrase, hand the destination passphrase to createPhysicalDisk, and pass the source secret as sec0 (via image options, so it stays out of the destination -o options) and the destination secret as sec1 with encrypt.format=luks. This mirrors ScaleIOStorageAdaptor. The qcow2 "cp -f" fast path is skipped when either side is encrypted, since a file copy cannot re-encrypt. --bitmaps is dropped for an encrypted source. Copies to or from RBD, and TAR/DIR sources, are rejected outright rather than silently losing the encryption. With both passphrases null the qemu-img command is unchanged: the empty options map and object list render identically to the nulls they replace. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…e pools migrateVolume refused any encrypted volume unless both ends were StorPool or the source was PowerFlex. Now that the KVM storage adaptor re-encrypts during the convert, the file-based pool types can do this too. Allow it for KVM when both the source and destination pool are one of NetworkFilesystem, Filesystem or SharedMountPoint and the volume is not being live migrated. Everything else still throws. The destination pool is otherwise only resolved below this check, so look it up the same way the live-migration branch above already does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ssphrase cleanUpVolumesForFailedMigrations removed the passphrase row outright, but VolumeServiceImpl.duplicateVolumeOnAnotherStorage gives the destination volume the *same* passphrase_id as the source. Removing it would leave the live source volume permanently undecryptable. Check for remaining references before removing, the way VolumeObject.deletePassphrase already does: the destination's own reference is cleared first, so a non-empty result means the source still needs the key. 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.
Why
Encrypted volumes cannot be migrated between storage pools at all.
VolumeApiServiceImplrefuses unless both ends are StorPool or the source is PowerFlex, so on NFS/local pools every attempt fails with "Migration of encrypted volumes is unsupported".This blocks us-central1: every production root volume there is LUKS-encrypted on NFS, so moving them to local primary storage is impossible and the region would otherwise have to be rebuilt VM-by-VM rather than migrated.
What was actually broken
One unimplemented method.
LibvirtStorageAdaptor.copyPhysicalDisk(...)declaressrcPassphrase/dstPassphraseand never reads them — the destination is created unencrypted andqemu-img convertis invoked with no--object secretand noencrypt.*options.Everything above it already works:
KVMStorageProcessor.copyVolumeFromPrimaryToPrimarysetsQemuEncryptFormat.LUKSand passes both passphrases,KVMStoragePoolManagerplumbs them through, andAncientDataMotionStrategyalready selects an encryption-capable endpoint.Upstream acknowledges this gap verbatim in apache#14453: "offline storage migration of an encrypted volume on NFS/local storage fails because
LibvirtStorageAdaptor.copyPhysicalDiskignores the passphrases."ScaleIOStorageAdaptor.copyPhysicalDiskalready implements the identical signature correctly and is the pattern followed here.Approach
qemu-img convertwith a secret for each side (sec0source,sec1destination). The same passphrase bytes are used on both —duplicateVolumeOnAnotherStoragecopiespassphrase_id— so this re-wraps the master key under the same user passphrase and the DB relationship is unchanged.Verified beforehand on real volumes that encrypted roots are qcow2 overlays with a template backing file:
The backing file does not exist on the destination pool, so a header-preserving file copy is not viable — a flattening convert is required, which this does as a side effect.
Scope
Offline (stopped VM) only, KVM, between
NetworkFilesystem/Filesystem/SharedMountPoint. Live volume migration is untouched: KVM already refuses it for these pool types independently of encryption, and that path uses the TO-lessMigrateVolumeCommand, which carries no passphrase at all.Also fixed
DataMotionServiceImpl.cleanUpVolumesForFailedMigrationsremoved the destination volume's passphrase unconditionally — but source and destination sharepassphrase_id. Had it fired it would have left the live source volume permanently undecryptable. Now refcount-checked, mirroringVolumeObject.deletePassphrase.Tests
Unencrypted copies assert argument-level equivalence with the previous call, so the existing path is unchanged.
Note for rebasing
apache#14426 (draft) touches the same four files for online and offline encrypted migration. The diff here is deliberately kept to distinct hunks with no reindentation to keep that rebase cheap.
🤖 Generated with Claude Code