-
Notifications
You must be signed in to change notification settings - Fork 1.4k
storage: KVM - enable RBD/Ceph volume encryption support #13556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
calvix
wants to merge
10
commits into
apache:main
Choose a base branch
from
calvix:feature_rbd_encryption
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a908fd3
storage: enable RBD/Ceph volume encryption support (shared base)
8c692ca
kvm: Ceph-native LUKS2 encryption for RBD volumes (engine='librbd')
e547f86
kvm: gate host encryption probe on librbd support for RBD
864731c
kvm: resize support for librbd-encrypted RBD volumes (#5)
a8de6a7
kvm: route online resize of encrypted RBD through virsh blockresize
3b68ab7
kvm: encrypted RBD root disks (thin CoW clone + full-copy fallback)
fc60197
kvm: harden and align librbd-encrypted RBD volume code
ef726a0
kvm: add RbdEncryption unit tests
a17b777
kvm: refuse encrypted RBD hot-plug on libvirt < 10.1.0
ad357f5
docs: add PendingReleaseNotes entry for librbd-encrypted RBD volumes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; | ||
| import org.apache.cloudstack.utils.qemu.QemuImgException; | ||
| import org.apache.cloudstack.utils.qemu.QemuObject; | ||
| import org.apache.cloudstack.utils.rbd.RbdEncryption; | ||
| import org.libvirt.Connect; | ||
| import org.libvirt.Domain; | ||
| import org.libvirt.DomainInfo; | ||
|
|
@@ -93,6 +94,13 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR | |
| final String path = vol.getPath(); | ||
| String type = notifyOnlyType; | ||
|
|
||
| // Encrypted RBD volumes are encrypted natively by librbd; they must be resized via | ||
| // `rbd resize --encryption-passphrase-file` so librbd grows the encrypted payload and keeps | ||
| // the LUKS header consistent. The libvirt/qemu-img resize paths below are for qemu-native | ||
| // encryption and would not handle the librbd LUKS2 layout. | ||
| final boolean rbdEncrypted = pool.getType() == StoragePoolType.RBD | ||
| && command.getPassphrase() != null && command.getPassphrase().length > 0; | ||
|
|
||
| if (spool.getType().equals(StoragePoolType.PowerFlex) && vol.getFormat().equals(PhysicalDiskFormat.QCOW2)) { | ||
| // PowerFlex QCOW2 sizing needs to consider overhead. | ||
| newSize = ScaleIOStorageAdaptor.getUsableBytesFromRawBytes(newSize); | ||
|
|
@@ -115,7 +123,7 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR | |
| /* libvirt doesn't support resizing (C)LVM devices, and corrupts QCOW2 in some scenarios, so we have to do these via qemu-img */ | ||
| if (pool.getType() != StoragePoolType.CLVM && pool.getType() != StoragePoolType.CLVM_NG | ||
| && pool.getType() != StoragePoolType.Linstor && pool.getType() != StoragePoolType.PowerFlex | ||
| && vol.getFormat() != PhysicalDiskFormat.QCOW2) { | ||
| && vol.getFormat() != PhysicalDiskFormat.QCOW2 && !rbdEncrypted) { | ||
| logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume."); | ||
| try { | ||
| final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); | ||
|
|
@@ -139,11 +147,15 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR | |
|
|
||
| boolean vmIsRunning = isVmRunning(vmInstanceName, libvirtComputingResource); | ||
|
|
||
| /* when VM is offline, we use qemu-img directly to resize encrypted volumes. | ||
| If VM is online, the existing resize script will call virsh blockresize which works | ||
| with both encrypted and non-encrypted volumes. | ||
| /* when VM is offline, we use qemu-img (or rbd, for librbd-encrypted RBD) directly to resize | ||
| encrypted volumes. If VM is online, the existing resize script calls virsh blockresize, | ||
| which for an librbd-encrypted RBD disk lets qemu/librbd grow the encrypted payload and | ||
| notify the guest in one step (no passphrase needed, qemu already has the secret loaded). | ||
| */ | ||
| if (!vmIsRunning && command.getPassphrase() != null && command.getPassphrase().length > 0 ) { | ||
| if (rbdEncrypted && !vmIsRunning) { | ||
| logger.debug("Invoking rbd to resize an offline, encrypted (librbd) RBD volume"); | ||
| resizeRbdEncryptedVolume(pool, vol, newSize, shrinkOk, command.getPassphrase()); | ||
| } else if (!vmIsRunning && command.getPassphrase() != null && command.getPassphrase().length > 0 ) { | ||
| logger.debug("Invoking qemu-img to resize an offline, encrypted volume"); | ||
| QemuObject.EncryptFormat encryptFormat = QemuObject.EncryptFormat.enumValue(command.getEncryptFormat()); | ||
| resizeEncryptedQcowFile(vol, encryptFormat,newSize, command.getPassphrase(), libvirtComputingResource); | ||
|
|
@@ -213,6 +225,16 @@ private void resizeEncryptedQcowFile(final KVMPhysicalDisk vol, final QemuObject | |
| } | ||
| } | ||
|
|
||
| private void resizeRbdEncryptedVolume(final KVMStoragePool pool, final KVMPhysicalDisk vol, long newSize, | ||
| boolean shrinkOk, byte[] passphrase) throws CloudRuntimeException { | ||
| try { | ||
| new RbdEncryption().resize(pool.getSourceHost(), pool.getSourcePort(), pool.getAuthUserName(), | ||
| pool.getAuthSecret(), pool.getSourceDir(), vol.getName(), newSize, shrinkOk, passphrase); | ||
| } finally { | ||
| Arrays.fill(passphrase, (byte) 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this needed? |
||
| } | ||
| } | ||
|
|
||
| private Answer handleMultipathSCSIResize(ResizeVolumeCommand command, KVMStoragePool pool) { | ||
| ((MultipathSCSIPool)pool).resize(command.getPath(), command.getInstanceName(), command.getNewSize()); | ||
| return new ResizeVolumeAnswer(command, true, ""); | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I do not think this is a huge issue, I think it would be best if we could differentiate the two kinds of encryption support. Maybe we could have a flag that is specific to RBD encryption.