mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
qemu: add librbd encryption engine
rbd encryption is new in qemu 6.1.0. This commit adds a new encryption engine property which allows the user to use this new encryption engine. Signed-off-by: Or Ozeri <oro@il.ibm.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
ab1d46d612
commit
59090adf63
@ -27,7 +27,16 @@
|
||||
The <code>encryption</code> tag supports an optional <code>engine</code>
|
||||
tag, which allows selecting which component actually handles
|
||||
the encryption. Currently defined values of <code>engine</code> are
|
||||
<code>qemu</code>.
|
||||
<code>qemu</code> and <code>librbd</code>.
|
||||
Both <code>qemu</code> and <code>librbd</code> require using the qemu
|
||||
driver.
|
||||
The <code>librbd</code> engine requires qemu version >= 6.1.0,
|
||||
and is only applicable for RBD network disks.
|
||||
If the engine tag is not specified, the <code>qemu</code> engine will be
|
||||
used by default (assuming the qemu driver is used).
|
||||
Note that <code>librbd</code> engine is currently only supported by the
|
||||
qemu VM driver, and is not supported by the storage driver. Furthermore,
|
||||
the storage driver currently ignores the <code>engine</code> tag.
|
||||
</p>
|
||||
<p>
|
||||
The <code>encryption</code> tag can currently contain a sequence of
|
||||
|
@ -19,6 +19,7 @@
|
||||
<attribute name="engine">
|
||||
<choice>
|
||||
<value>qemu</value>
|
||||
<value>librbd</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
</optional>
|
||||
|
@ -49,7 +49,7 @@ VIR_ENUM_IMPL(virStorageEncryptionFormat,
|
||||
|
||||
VIR_ENUM_IMPL(virStorageEncryptionEngine,
|
||||
VIR_STORAGE_ENCRYPTION_ENGINE_LAST,
|
||||
"default", "qemu",
|
||||
"default", "qemu", "librbd",
|
||||
);
|
||||
|
||||
static void
|
||||
|
@ -54,6 +54,7 @@ struct _virStorageEncryptionInfoDef {
|
||||
typedef enum {
|
||||
VIR_STORAGE_ENCRYPTION_ENGINE_DEFAULT = 0,
|
||||
VIR_STORAGE_ENCRYPTION_ENGINE_QEMU,
|
||||
VIR_STORAGE_ENCRYPTION_ENGINE_LIBRBD,
|
||||
|
||||
VIR_STORAGE_ENCRYPTION_ENGINE_LAST,
|
||||
} virStorageEncryptionEngine;
|
||||
|
@ -875,6 +875,8 @@ qemuBlockStorageSourceGetRBDProps(virStorageSource *src,
|
||||
qemuDomainStorageSourcePrivate *srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
|
||||
g_autoptr(virJSONValue) servers = NULL;
|
||||
virJSONValue *ret = NULL;
|
||||
g_autoptr(virJSONValue) encrypt = NULL;
|
||||
const char *encformat;
|
||||
const char *username = NULL;
|
||||
g_autoptr(virJSONValue) authmodes = NULL;
|
||||
g_autoptr(virJSONValue) mode = NULL;
|
||||
@ -899,12 +901,40 @@ qemuBlockStorageSourceGetRBDProps(virStorageSource *src,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (src->encryption &&
|
||||
src->encryption->engine == VIR_STORAGE_ENCRYPTION_ENGINE_LIBRBD) {
|
||||
switch ((virStorageEncryptionFormatType) src->encryption->format) {
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_LUKS:
|
||||
encformat = "luks";
|
||||
break;
|
||||
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_QCOW:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("librbd encryption engine only supports luks/luks2 formats"));
|
||||
return NULL;
|
||||
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT:
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virStorageEncryptionFormatType,
|
||||
src->encryption->format);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectCreate(&encrypt,
|
||||
"s:format", encformat,
|
||||
"s:key-secret", srcPriv->encinfo->alias,
|
||||
NULL) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectCreate(&ret,
|
||||
"s:pool", src->volume,
|
||||
"s:image", src->path,
|
||||
"S:snapshot", src->snapshot,
|
||||
"S:conf", src->configFile,
|
||||
"A:server", &servers,
|
||||
"A:encrypt", &encrypt,
|
||||
"S:user", username,
|
||||
"A:auth-client-required", &authmodes,
|
||||
"S:key-secret", keysecret,
|
||||
|
@ -4773,6 +4773,44 @@ qemuDomainValidateStorageSource(virStorageSource *src,
|
||||
if (src->encryption) {
|
||||
switch (src->encryption->engine) {
|
||||
case VIR_STORAGE_ENCRYPTION_ENGINE_QEMU:
|
||||
switch ((virStorageEncryptionFormatType) src->encryption->format) {
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_LUKS:
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_QCOW:
|
||||
break;
|
||||
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT:
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virStorageEncryptionFormatType,
|
||||
src->encryption->format);
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case VIR_STORAGE_ENCRYPTION_ENGINE_LIBRBD:
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_RBD_ENCRYPTION)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("librbd encryption is not supported by this QEMU binary"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch ((virStorageEncryptionFormatType) src->encryption->format) {
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_LUKS:
|
||||
break;
|
||||
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_QCOW:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("librbd encryption engine only supports luks/luks2 formats"));
|
||||
return -1;
|
||||
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT:
|
||||
case VIR_STORAGE_ENCRYPTION_FORMAT_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virStorageEncryptionFormatType,
|
||||
src->encryption->format);
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case VIR_STORAGE_ENCRYPTION_ENGINE_DEFAULT:
|
||||
case VIR_STORAGE_ENCRYPTION_ENGINE_LAST:
|
||||
|
@ -0,0 +1 @@
|
||||
unsupported configuration: librbd encryption is not supported by this QEMU binary
|
@ -0,0 +1,45 @@
|
||||
LC_ALL=C \
|
||||
PATH=/bin \
|
||||
HOME=/tmp/lib/domain--1-encryptdisk \
|
||||
USER=test \
|
||||
LOGNAME=test \
|
||||
XDG_DATA_HOME=/tmp/lib/domain--1-encryptdisk/.local/share \
|
||||
XDG_CACHE_HOME=/tmp/lib/domain--1-encryptdisk/.cache \
|
||||
XDG_CONFIG_HOME=/tmp/lib/domain--1-encryptdisk/.config \
|
||||
/usr/bin/qemu-system-x86_64 \
|
||||
-name guest=encryptdisk,debug-threads=on \
|
||||
-S \
|
||||
-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-encryptdisk/master-key.aes"}' \
|
||||
-machine pc-i440fx-2.1,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \
|
||||
-cpu qemu64 \
|
||||
-m 1024 \
|
||||
-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}' \
|
||||
-overcommit mem-lock=off \
|
||||
-smp 1,sockets=1,cores=1,threads=1 \
|
||||
-uuid 496898a6-e6ff-f7c8-5dc2-3cf410945ee9 \
|
||||
-display none \
|
||||
-no-user-config \
|
||||
-nodefaults \
|
||||
-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
|
||||
-mon chardev=charmonitor,id=monitor,mode=control \
|
||||
-rtc base=utc \
|
||||
-no-shutdown \
|
||||
-no-acpi \
|
||||
-boot strict=on \
|
||||
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
|
||||
-object '{"qom-type":"secret","id":"libvirt-3-format-encryption-secret0","data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw==","format":"base64"}' \
|
||||
-blockdev '{"driver":"rbd","pool":"pool","image":"image","server":[{"host":"mon1.example.org","port":"6321"},{"host":"mon2.example.org","port":"6322"},{"host":"mon3.example.org","port":"6322"}],"node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \
|
||||
-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"luks","key-secret":"libvirt-3-format-encryption-secret0","file":"libvirt-3-storage"}' \
|
||||
-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"libvirt-3-format","id":"virtio-disk0","bootindex":1}' \
|
||||
-object '{"qom-type":"secret","id":"libvirt-2-format-encryption-secret0","data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw==","format":"base64"}' \
|
||||
-blockdev '{"driver":"rbd","pool":"pool","image":"image","server":[{"host":"mon1.example.org","port":"6321"},{"host":"mon2.example.org","port":"6322"},{"host":"mon3.example.org","port":"6322"}],"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
|
||||
-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"luks","key-secret":"libvirt-2-format-encryption-secret0","file":"libvirt-2-storage"}' \
|
||||
-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"libvirt-2-format","id":"virtio-disk1"}' \
|
||||
-object '{"qom-type":"secret","id":"libvirt-1-format-encryption-secret0","data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw==","format":"base64"}' \
|
||||
-blockdev '{"driver":"rbd","pool":"pool","image":"image","server":[{"host":"mon1.example.org","port":"6321"},{"host":"mon2.example.org","port":"6322"},{"host":"mon3.example.org","port":"6322"}],"encrypt":{"format":"luks","key-secret":"libvirt-1-format-encryption-secret0"},"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
|
||||
-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
|
||||
-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x5","drive":"libvirt-1-format","id":"virtio-disk2"}' \
|
||||
-audiodev id=audio1,driver=none \
|
||||
-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x3"}' \
|
||||
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
|
||||
-msg timestamp=on
|
63
tests/qemuxml2argvdata/disk-network-rbd-encryption.xml
Normal file
63
tests/qemuxml2argvdata/disk-network-rbd-encryption.xml
Normal file
@ -0,0 +1,63 @@
|
||||
<domain type='qemu'>
|
||||
<name>encryptdisk</name>
|
||||
<uuid>496898a6-e6ff-f7c8-5dc2-3cf410945ee9</uuid>
|
||||
<memory unit='KiB'>1048576</memory>
|
||||
<currentMemory unit='KiB'>524288</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='network' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source protocol='rbd' name='pool/image'>
|
||||
<host name='mon1.example.org' port='6321'/>
|
||||
<host name='mon2.example.org' port='6322'/>
|
||||
<host name='mon3.example.org' port='6322'/>
|
||||
<encryption format='luks'>
|
||||
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80fb0'/>
|
||||
</encryption>
|
||||
</source>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
</disk>
|
||||
<disk type='network' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source protocol='rbd' name='pool/image'>
|
||||
<host name='mon1.example.org' port='6321'/>
|
||||
<host name='mon2.example.org' port='6322'/>
|
||||
<host name='mon3.example.org' port='6322'/>
|
||||
<encryption format='luks' engine='qemu'>
|
||||
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80fb0'/>
|
||||
</encryption>
|
||||
</source>
|
||||
<target dev='vdb' bus='virtio'/>
|
||||
</disk>
|
||||
<disk type='network' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source protocol='rbd' name='pool/image'>
|
||||
<host name='mon1.example.org' port='6321'/>
|
||||
<host name='mon2.example.org' port='6322'/>
|
||||
<host name='mon3.example.org' port='6322'/>
|
||||
<encryption format='luks' engine='librbd'>
|
||||
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80fb0'/>
|
||||
</encryption>
|
||||
</source>
|
||||
<target dev='vdc' bus='virtio'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
@ -1344,6 +1344,8 @@ mymain(void)
|
||||
DO_TEST_CAPS_LATEST("disk-network-gluster");
|
||||
DO_TEST_CAPS_VER("disk-network-rbd", "2.12.0");
|
||||
DO_TEST_CAPS_LATEST("disk-network-rbd");
|
||||
DO_TEST_CAPS_VER_PARSE_ERROR("disk-network-rbd-encryption", "6.0.0");
|
||||
DO_TEST_CAPS_LATEST("disk-network-rbd-encryption");
|
||||
DO_TEST_CAPS_VER_FAILURE("disk-network-rbd-no-colon", "4.1.0");
|
||||
DO_TEST_CAPS_LATEST("disk-network-rbd-no-colon");
|
||||
DO_TEST_CAPS_VER("disk-network-sheepdog", "2.12.0");
|
||||
|
@ -0,0 +1,70 @@
|
||||
<domain type='qemu'>
|
||||
<name>encryptdisk</name>
|
||||
<uuid>496898a6-e6ff-f7c8-5dc2-3cf410945ee9</uuid>
|
||||
<memory unit='KiB'>1048576</memory>
|
||||
<currentMemory unit='KiB'>524288</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<cpu mode='custom' match='exact' check='none'>
|
||||
<model fallback='forbid'>qemu64</model>
|
||||
</cpu>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='network' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source protocol='rbd' name='pool/image'>
|
||||
<host name='mon1.example.org' port='6321'/>
|
||||
<host name='mon2.example.org' port='6322'/>
|
||||
<host name='mon3.example.org' port='6322'/>
|
||||
<encryption format='luks' engine='qemu'>
|
||||
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80fb0'/>
|
||||
</encryption>
|
||||
</source>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</disk>
|
||||
<disk type='network' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source protocol='rbd' name='pool/image'>
|
||||
<host name='mon1.example.org' port='6321'/>
|
||||
<host name='mon2.example.org' port='6322'/>
|
||||
<host name='mon3.example.org' port='6322'/>
|
||||
<encryption format='luks' engine='qemu'>
|
||||
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80fb0'/>
|
||||
</encryption>
|
||||
</source>
|
||||
<target dev='vdb' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</disk>
|
||||
<disk type='network' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source protocol='rbd' name='pool/image'>
|
||||
<host name='mon1.example.org' port='6321'/>
|
||||
<host name='mon2.example.org' port='6322'/>
|
||||
<host name='mon3.example.org' port='6322'/>
|
||||
<encryption format='luks' engine='librbd'>
|
||||
<secret type='passphrase' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80fb0'/>
|
||||
</encryption>
|
||||
</source>
|
||||
<target dev='vdc' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='piix3-uhci'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<audio id='1' type='none'/>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
@ -315,6 +315,7 @@ mymain(void)
|
||||
QEMU_CAPS_SCSI_BLOCK);
|
||||
DO_TEST_NOCAPS("disk-network-gluster");
|
||||
DO_TEST_NOCAPS("disk-network-rbd");
|
||||
DO_TEST_CAPS_LATEST("disk-network-rbd-encryption");
|
||||
DO_TEST_NOCAPS("disk-network-source-auth");
|
||||
DO_TEST_NOCAPS("disk-network-sheepdog");
|
||||
DO_TEST_NOCAPS("disk-network-vxhs");
|
||||
|
Loading…
Reference in New Issue
Block a user