Support generic Luks encryption
Subsystems (3)
RFC 4/8 Gluks: Introduce Gluks options
In reply to Hyman HuangSimilar to Luks, the Gluks format primarily recycles the Luks choices with the exception of the "size" option.
--- block/crypto.c | 4 ++-- block/generic-luks.c | 18 ++++++++++++++++++ block/generic-luks.h | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-)
block/crypto.c +2 -2
@@ -150,7 +150,7 @@ error: } -static QemuOptsList block_crypto_runtime_opts_luks = { +QemuOptsList block_crypto_runtime_opts_luks = { .name ="crypto" , .head =QTAILQ_HEAD_INITIALIZER (block_crypto_runtime_opts_luks.head), .desc = {
@@ -181,7 +181,7 @@ static QemuOptsList block_crypto_create_opts_luks = { }; -static QemuOptsList block_crypto_amend_opts_luks = { +QemuOptsList block_crypto_amend_opts_luks = { .name ="crypto" , .head =QTAILQ_HEAD_INITIALIZER (block_crypto_create_opts_luks.head), .desc = {
block/generic-luks.c +18 -0
@@ -35,6 +35,21 @@ typedef struct BDRVGLUKSState {uint64_t header_size;/* In bytes */ } BDRVGLUKSState; +static QemuOptsList gluks_create_opts_luks = { + .name ="crypto" , + .head =QTAILQ_HEAD_INITIALIZER (gluks_create_opts_luks.head), + .desc = { +BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET ("" ), +BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG ("" ), +BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE ("" ), +BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG ("" ), +BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG ("" ), +BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG ("" ), +BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME ("" ), + {/* end of list */ } + }, +}; +static int gluks_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
@@ -71,6 +86,9 @@ static BlockDriver bdrv_generic_luks = { .bdrv_co_create_opts = gluks_co_create_opts, .bdrv_child_perm = gluks_child_perms, .bdrv_co_getlength = gluks_co_getlength, + + .create_opts = &gluks_create_opts_luks, + .amend_opts = &block_crypto_amend_opts_luks, };static void block_generic_luks_init (void )
block/generic-luks.h +3 -0
@@ -23,4 +23,7 @@#ifndef GENERIC_LUKS_H #define GENERIC_LUKS_H +extern QemuOptsList block_crypto_runtime_opts_luks; +extern QemuOptsList block_crypto_amend_opts_luks; +#endif /* GENERIC_LUKS_H */
Signature · 1 line
2.39.1
cover Support generic Luks encryption
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/Crypto
The last chapter says we should "separate header volume":
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer encryption for any format that QEMU theoretically supports.
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device)
^
|
Gluks (format-like disk node)
/ \
file header (blockdev reference)
/ \
file file (protocol node)
| |disk data Luks data
We don't need to create a new disk format in order to use the Gluks to encrypt the disk; all we need to do is construct a Luks header, which we will refer to as the "Gluk" because it only contains Luks header data and no user data. The creation command, for instance, is nearly identical to Luks image:
$ qemu-img create --object secret,id=sec0,data=abc123 -f gluks -o cipher-alg=aes-256,cipher-mode=xts -o key-secret=sec0 cipher.gluks
As previously mentioned, the "size" option is not accepted during the generation of the Gluks format because it only contains the Luks header data.
To hot-add a raw disk with Gluks encryption, see the following steps:
1. add a protocol blockdev node of data disk
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-1-storage", "driver": "file",
"filename": "/path/to/test_disk.raw"}}'2. add a protocol blockdev node of Luks header
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-2-storage", "driver": "file",
"filename": "/path/to/cipher.gluks" }}'3. add the secret for decrypting the cipher stored in Gluks header
$ virsh qemu-monitor-command c81_node1 '{"execute":"object-add",
"arguments":{"qom-type": "secret", "id":
"libvirt-2-storage-secret0", "data": "abc123"}}'4. add the Gluks-drived blockdev to connect the user disk with Luks header, QEMU will use the cipher in the Luks header to encrypt/decrypt the disk data
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-1-format", "driver": "gluks", "file":
"libvirt-1-storage", "header": "libvirt-2-storage", "key-secret":
"libvirt-2-storage-secret0"}}' 5. add the device finally
$ virsh qemu-monitor-command vm '{"execute":"device_add",
"arguments": {"num-queues": "1", "driver": "virtio-blk-pci", "scsi":
"off", "drive": "libvirt-1-format", "id": "virtio-disk1"}}'Do the reverse to hot-del the raw disk.
To hot-add a qcow2 disk with Gluks encryption:
1. add a protocol blockdev node of data disk
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-1-storage", "driver": "file",
"filename": "/path/to/test_disk.qcow2"}}'2. add a protocol blockdev node of Luks header as above. block ref: libvirt-2-storage
3. add the secret for decrypting the cipher stored in Gluks header as above too
secret ref: libvirt-2-storage-secret0
4. add the qcow2-drived blockdev format node:
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-1-format", "driver": "qcow2",
"file": "libvirt-1-storage"}}'5. add the Gluks-drived blockdev to connect the qcow2 disk with Luks header
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-2-format", "driver": "gluks",
"file": "libvirt-1-format", "header": "libvirt-2-storage",
"key-secret": "libvirt-2-format-secret0"}}'6. add the device finally
$ virsh qemu-monitor-command vm '{"execute":"device_add",
"arguments": {"num-queues": "1", "driver": "virtio-blk-pci", "scsi":
"off", "drive": "libvirt-2-format", "id": "virtio-disk2"}}'In a virtual machine, several disk nodes are allowed to share a single Gluks header.
This patchset, as previously said, is a proof-of-concept; additional work may be required before productization. As the title suggests, we have uploaded it solely for comments. Additionally, a thorough test would be performed on the following version.
Any ideas and comments about this feature would be appreciated.
Thanks,
Yong
Best regared !
Hyman Huang (8):
crypto: Export util functions and structures
crypto: Introduce payload offset set function
Gluks: Add the basic framework
Gluks: Introduce Gluks options
qapi: Introduce Gluks types to qapi
crypto: Provide the Luks crypto driver to Gluks
Gluks: Implement the fundamental block layer driver hooks.
block: Support Gluks format image creation using qemu-img
block.c | 5 + block/crypto.c | 20 +--- block/crypto.h | 23 ++++ block/generic-luks.c | 250 +++++++++++++++++++++++++++++++++++++++++ block/generic-luks.h | 29 +++++ block/meson.build | 1 + crypto/block.c | 5 + include/crypto/block.h | 1 + qapi/block-core.json | 22 +++- qapi/crypto.json | 10 +- 10 files changed, 348 insertions(+), 18 deletions(-) create mode 100644 block/generic-luks.c create mode 100644 block/generic-luks.h
Signature · 1 line
2.39.1
RFC 8/8 block: Support Gluks format image creation using qemu-img
To create a Gluks header image, use the command as follows:
$ qemu-img create --object secret,id=sec0,data=abc123 -f gluks
Quoted 2 lines
-o cipher-alg=aes-256,cipher-mode=xts -o key-secret=sec0 cipher.gluks
--- block.c | 5 +++++ block/generic-luks.c | 53 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-)
block.c +5 -0
@@ -7517,6 +7517,11 @@ void bdrv_img_create(const char *filename, const char *fmt, goto out; } +if (!strcmp (fmt,"gluks" )) { +qemu_opt_set (opts,"size" ,"0M" , &local_err); + size =0 ; + } +if (size ==-1 ) {error_setg (errp,"Image creation needs a size parameter" ); goto out;
block/generic-luks.c +52 -1
59 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC 2/8 crypto: Introduce payload offset set function
In reply to Hyman HuangImplement the payload offset set function for Gluks.
--- crypto/block.c | 4 ++++ include/crypto/block.h | 1 + 2 files changed, 5 insertions(+)
crypto/block.c +4 -0
@@ -319,6 +319,10 @@ QCryptoHashAlgorithm qcrypto_block_get_kdf_hash(QCryptoBlock *block)return block->kdfhash; } +void qcrypto_block_set_payload_offset (QCryptoBlock *block,uint64_t offset) +{ + block->payload_offset = offset; +}uint64_t qcrypto_block_get_payload_offset (QCryptoBlock *block) {
include/crypto/block.h +1 -0
@@ -312,4 +312,5 @@ void qcrypto_block_free(QCryptoBlock *block); G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) +void qcrypto_block_set_payload_offset (QCryptoBlock *block,uint64_t offset);#endif /* QCRYPTO_BLOCK_H */
Signature · 1 line
2.39.1
RFC 5/8 qapi: Introduce Gluks types to qapi
In reply to Hyman HuangPrimarily using the Luks types again, Gluks adds an extra option called "header", which points to the Luks header node's description.
--- qapi/block-core.json | 22 +++++++++++++++++++++- qapi/crypto.json | 10 +++++++--- 2 files changed, 28 insertions(+), 4 deletions(-)
qapi/block-core.json +21 -1
@@ -3185,12 +3185,14 @@ # # @snapshot-access: Since 7.0 # +# @gluks: Since 9.0 +# # Since: 2.9 ## { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg', - 'file', 'snapshot-access', 'ftp', 'ftps', 'gluster', + 'file', 'snapshot-access', 'ftp', 'ftps', 'gluks', 'gluster', {'name': 'host_cdrom', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, {'name': 'host_device', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, 'http', 'https',
@@ -3957,6 +3959,23 @@ '*debug': 'int', '*logfile': 'str' } } +## +# @BlockdevOptionsGLUKS: +# +# Driver specific block device options for GLUKS. +# +# @header: reference to the definition of the luks header node. +# +# @key-secret: the ID of a QCryptoSecret object providing the +# decryption key. +# +# Since: 9.0 +## +{ 'struct': 'BlockdevOptionsGLUKS', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { 'header': 'BlockdevRef', + 'key-secret': 'str' } } + ## # @BlockdevOptionsIoUring: #
@@ -4680,6 +4699,7 @@ 'file': 'BlockdevOptionsFile', 'ftp': 'BlockdevOptionsCurlFtp', 'ftps': 'BlockdevOptionsCurlFtps', + 'gluks': 'BlockdevOptionsGLUKS', 'gluster': 'BlockdevOptionsGluster', 'host_cdrom': { 'type': 'BlockdevOptionsFile', 'if': 'HAVE_HOST_BLOCK_DEVICE' },
qapi/crypto.json +7 -3
@@ -154,11 +154,13 @@ # # @luks: LUKS encryption format. Recommended for new images # +# @gluks: generic LUKS encryption format. (since 9.0) +# # Since: 2.6 ## { 'enum': 'QCryptoBlockFormat', # 'prefix': 'QCRYPTO_BLOCK_FORMAT', - 'data': ['qcow', 'luks']} + 'data': ['qcow', 'luks', 'gluks']} ## # @QCryptoBlockOptionsBase:
@@ -246,7 +248,8 @@ 'base': 'QCryptoBlockOptionsBase', 'discriminator': 'format', 'data': { 'qcow': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockOptionsLUKS' } } + 'luks': 'QCryptoBlockOptionsLUKS', + 'gluks': 'QCryptoBlockOptionsLUKS' } } ## # @QCryptoBlockCreateOptions:
@@ -260,7 +263,8 @@ 'base': 'QCryptoBlockOptionsBase', 'discriminator': 'format', 'data': { 'qcow': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockCreateOptionsLUKS' } } + 'luks': 'QCryptoBlockCreateOptionsLUKS', + 'gluks': 'QCryptoBlockCreateOptionsLUKS' } } ## # @QCryptoBlockInfoBase:
Signature · 1 line
2.39.1
RFC 3/8 Gluks: Add the basic framework
In reply to Hyman HuangGluks would be a built-in format in the QEMU block layer.
--- block/generic-luks.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ block/generic-luks.h | 26 ++++++++++++++ block/meson.build | 1 + 3 files changed, 108 insertions(+) create mode 100644 block/generic-luks.c create mode 100644 block/generic-luks.h
block/generic-luks.c new file +81 -0
@@ -0,0 +1,81 @@ +/* +* QEMU block driver for the generic luks encryption +* +* Copyright (c) 2024 SmartX Inc +* +* Author: Hyman Huang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#include "qemu/osdep.h" + +#include "block/block_int.h" +#include "block/crypto.h" +#include "crypto/block.h" + +#include "generic-luks.h" + +/* BDRVGLUKSState holds the state of one generic LUKS instance */ +typedef struct BDRVGLUKSState { +BlockCrypto crypto; +BdrvChild *header;/* LUKS header node */ +uint64_t header_size;/* In bytes */ +}BDRVGLUKSState ; + +static int gluks_open (BlockDriverState *bs,QDict *options,int flags, +Error **errp) +{ +return 0 ; +} + +static int coroutine_fn GRAPH_UNLOCKED +gluks_co_create_opts (BlockDriver *drv,const char *filename, +QemuOpts *opts,Error **errp) +{ +return 0 ; +} + +static void +gluks_child_perms (BlockDriverState *bs,BdrvChild *c, +const BdrvChildRole role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared) +{ + +} + +static int64_t coroutine_fn GRAPH_RDLOCK +gluks_co_getlength (BlockDriverState *bs) +{ +return 0 ; +} + +static BlockDriver bdrv_generic_luks = { + .format_name ="gluks" , + .instance_size =sizeof (BDRVGLUKSState), + .bdrv_open = gluks_open, + .bdrv_co_create_opts = gluks_co_create_opts, + .bdrv_child_perm = gluks_child_perms, + .bdrv_co_getlength = gluks_co_getlength, +}; + +static void block_generic_luks_init (void ) +{ +bdrv_register (&bdrv_generic_luks); +} + +block_init (block_generic_luks_init);
block/generic-luks.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* QEMU block driver for the generic luks encryption +* +* Copyright (c) 2024 SmartX Inc +* +* Author: Hyman Huang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +* +*/ + +#ifndef GENERIC_LUKS_H +#define GENERIC_LUKS_H + +#endif /* GENERIC_LUKS_H */
block/meson.build +1 -0
@@ -39,6 +39,7 @@ block_ss.add(files( 'throttle.c', 'throttle-groups.c', 'write-threshold.c', + 'generic-luks.c', ), zstd, zlib, gnutls) system_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c'))
Signature · 1 line
2.39.1
RFC 1/8 crypto: Export util functions and structures
In reply to Hyman HuangLuks driver logic is primarily reused by Gluk, which, therefore, exports several pre-existing functions and structures.
--- block/crypto.c | 16 ++++------------ block/crypto.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-)
block/crypto.c +4 -12
@@ -34,14 +34,6 @@#include "qemu/memalign.h" #include "crypto.h" -typedef struct BlockCrypto BlockCrypto ; - -struct BlockCrypto { -QCryptoBlock *block; -bool updating_keys; -}; - - static int block_crypto_probe_generic(QCryptoBlockFormat format, const uint8_t *buf, int buf_size,
@@ -321,7 +313,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format, } -static int coroutine_fn GRAPH_UNLOCKED +int coroutine_fn GRAPH_UNLOCKEDblock_crypto_co_create_generic (BlockDriverState *bs,int64_t size,QCryptoBlockCreateOptions *opts,PreallocMode prealloc,Error **errp)
@@ -385,7 +377,7 @@ block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,return bdrv_co_truncate (bs->file, offset, exact, prealloc,0 , errp); } -static void block_crypto_close (BlockDriverState *bs) +void block_crypto_close (BlockDriverState *bs) {BlockCrypto *crypto = bs->opaque;qcrypto_block_free (crypto->block);
@@ -404,7 +396,7 @@ static int block_crypto_reopen_prepare(BDRVReopenState *state,*/ #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) -static int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_RDLOCKblock_crypto_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
@@ -466,7 +458,7 @@ block_crypto_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, } -static int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_RDLOCKblock_crypto_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes,QEMUIOVector *qiov,BdrvRequestFlags flags) {
block/crypto.h +23 -0
@@ -21,6 +21,8 @@#ifndef BLOCK_CRYPTO_H #define BLOCK_CRYPTO_H +#include "crypto/block.h" +#define BLOCK_CRYPTO_OPT_DEF_KEY_SECRET (prefix, helpstr) \ { \ .name = prefix BLOCK_CRYPTO_OPT_QCOW_KEY_SECRET, \
@@ -131,4 +133,25 @@ block_crypto_amend_opts_init(QDict *opts, Error **errp);QCryptoBlockOpenOptions *block_crypto_open_opts_init (QDict *opts,Error **errp); +typedef struct BlockCrypto BlockCrypto ; + +struct BlockCrypto { +QCryptoBlock *block; +bool updating_keys; +}; + +int coroutine_fn GRAPH_UNLOCKED +block_crypto_co_create_generic (BlockDriverState *bs,int64_t size, +QCryptoBlockCreateOptions *opts, +PreallocMode prealloc,Error **errp); + +int coroutine_fn GRAPH_RDLOCK +block_crypto_co_preadv (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags); + +int coroutine_fn GRAPH_RDLOCK +block_crypto_co_pwritev (BlockDriverState *bs,int64_t offset,int64_t bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags); + +void block_crypto_close (BlockDriverState *bs);#endif /* BLOCK_CRYPTO_H */
Signature · 1 line
2.39.1
RFC 7/8 Gluks: Implement the fundamental block layer driver hooks
In reply to Hyman Huang--- block/generic-luks.c | 104 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-)
block/generic-luks.c +102 -2
@@ -23,8 +23,14 @@#include "qemu/osdep.h" #include "block/block_int.h" +#include "block/block-io.h" #include "block/crypto.h" +#include "block/qdict.h" #include "crypto/block.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "qemu/option.h" #include "generic-luks.h"
@@ -50,10 +56,89 @@ static QemuOptsList gluks_create_opts_luks = { }, }; +static int gluks_read_func (QCryptoBlock *block, +size_t offset, +uint8_t *buf, +size_t buflen, +void *opaque, +Error **errp) +{ + +BlockDriverState *bs = opaque; +BDRVGLUKSState *s = bs->opaque; +ssize_t ret; + +GLOBAL_STATE_CODE (); +GRAPH_RDLOCK_GUARD_MAINLOOP (); + + ret =bdrv_pread (s->header, offset, buflen, buf,0 ); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Could not read generic luks header" ); +return ret; + } +return 0 ; +} +static int gluks_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { -return 0 ; +BDRVGLUKSState *s = bs->opaque; +QemuOpts *opts =NULL ; +QCryptoBlockOpenOptions *open_opts =NULL ; +QDict *cryptoopts =NULL ; +unsigned int cflags =0 ; +int ret; + +GLOBAL_STATE_CODE (); + +if (!bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, + (BDRV_CHILD_DATA |BDRV_CHILD_PRIMARY ), false, errp)) { +return -EINVAL ; + } + s->header =bdrv_open_child (NULL , options,"header" , bs, + &child_of_bds,BDRV_CHILD_METADATA , false, + errp); +if (!s->header) { +return -EINVAL ; + } + +GRAPH_RDLOCK_GUARD_MAINLOOP (); + + opts =qemu_opts_create (&block_crypto_runtime_opts_luks, +NULL ,0 , &error_abort); +if (!qemu_opts_absorb_qdict (opts, options, errp)) { + ret = -EINVAL ; + goto cleanup; + } + + cryptoopts =qemu_opts_to_qdict (opts,NULL ); +qdict_put_str (cryptoopts,"format" , +QCryptoBlockFormat_str (Q_CRYPTO_BLOCK_FORMAT_GLUKS )); + + open_opts =block_crypto_open_opts_init (cryptoopts, errp); +if (!open_opts) { + goto cleanup; + } + + s->crypto.block =qcrypto_block_open (open_opts,NULL , + gluks_read_func, + bs, + cflags, +1 , + errp); +if (!s->crypto.block) { + ret = -EIO ; + goto cleanup; + } + + s->header_size =qcrypto_block_get_payload_offset (s->crypto.block); +qcrypto_block_set_payload_offset (s->crypto.block,0 ); + + ret =0 ; + cleanup: +qobject_unref (cryptoopts); +qapi_free_QCryptoBlockOpenOptions (open_opts); +return ret; } static int coroutine_fn GRAPH_UNLOCKED
@@ -70,13 +155,24 @@ gluks_child_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { + if (role & BDRV_CHILD_METADATA) { +/* assign read permission only */ + perm |= BLK_PERM_CONSISTENT_READ; +/* share all permissions */ + shared |=BLK_PERM_ALL ; + *nperm = perm; + *nshared = shared; +return ; + } + +bdrv_default_perms (bs, c, role, reopen_queue, perm, shared, nperm, nshared); } static int64_t coroutine_fn GRAPH_RDLOCKgluks_co_getlength (BlockDriverState *bs) { - return 0; +return bdrv_co_getlength (bs->file->bs); } static BlockDriver bdrv_generic_luks = {
@@ -87,8 +183,12 @@ static BlockDriver bdrv_generic_luks = { .bdrv_child_perm = gluks_child_perms, .bdrv_co_getlength = gluks_co_getlength, + .bdrv_close = block_crypto_close, + .bdrv_co_preadv = block_crypto_co_preadv, + .bdrv_co_pwritev = block_crypto_co_pwritev, .create_opts = &gluks_create_opts_luks, .amend_opts = &block_crypto_amend_opts_luks, + .is_format = false, };static void block_generic_luks_init (void )
Signature · 1 line
2.39.1
RFC 6/8 crypto: Provide the Luks crypto driver to Gluks
In reply to Hyman HuangHooks up the Luks crypto driver for Gluks.
--- crypto/block.c | 1 + 1 file changed, 1 insertion(+)
crypto/block.c +1 -0
@@ -27,6 +27,7 @@static const QCryptoBlockDriver *qcrypto_block_drivers[] = { [Q_CRYPTO_BLOCK_FORMAT_QCOW ] = &qcrypto_block_driver_qcow, [Q_CRYPTO_BLOCK_FORMAT_LUKS ] = &qcrypto_block_driver_luks, + [Q_CRYPTO_BLOCK_FORMAT_GLUKS ] = &qcrypto_block_driver_luks, };
Signature · 1 line
2.39.1
Quoted 6 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoThe last chapter says we should "separate header volume":
Quoted 7 lines
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer encryption for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19 -5
@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:
@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)
@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 11 lines · Daniel P. Berrangé
Quoted 10 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoThe last chapter says we should "separate header volume":
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
Quoted 6 lines
Quoted 3 lines
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer encryption for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
Indeed, this definitely makes things simple. The next version would do that !
Quoted 59 lines
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19
-5@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##
Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
Yes, most of the logic reuse the pre-existing Luks driver.
Quoted 11 lines
With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|
Signature · 1 line
Best regards
Quoted 75 lines · Daniel P. Berrangé
Quoted 6 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoThe last chapter says we should "separate header volume":
Quoted 7 lines
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer encryption for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19
-5@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##
Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
How about the design and usage, could it be simpler? Any advice? :)
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device)
^
|
Gluks (format-like disk node)
/ \
file header (blockdev reference)
/ \
file file (protocol node)
| |disk data Luks data
Quoted 12 lines
With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|
Signature · 1 line
Best regards
Quoted 97 lines · Yong Huang
Quoted 75 lines · Daniel P. Berrangé
Quoted 6 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoThe last chapter says we should "separate header volume":
Quoted 7 lines
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer encryption for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19
-5@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
How about the design and usage, could it be simpler? Any advice? :)
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device) ^ | Gluks (format-like disk node) / \ file header (blockdev reference) / \ file file (protocol node) | |
Quoted 1 line
disk data Luks data
What I suggested above ends up with the exact same block driver graph, unless I'm missing something.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 101 lines · Daniel P. Berrangé
Quoted 8 lines · Yong Huang
Quoted 5 lines · Daniel P. Berrangé
Quoted 4 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
The last chapter says we should "separate header volume":
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer
encryption
Quoted 81 lines
Quoted 62 lines
Quoted 1 line
for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19
-5@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
How about the design and usage, could it be simpler? Any advice? :)
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device) ^ | Gluks (format-like disk node) / \ file header (blockdev reference) / \ file file (protocol node) | |Quoted 1 line
disk data Luks data
Quoted 3 lines
What I suggested above ends up with the exact same block driver graph, unless I'm missing something.
I could overlook something or fail to adequately convey the goal of the patchset. :(
Indeed, utilizing the same block driver might be effective if our only goal is to divide the header volume, giving us an additional way to use Luks.
While supporting encryption for any disk format that QEMU is capable of supporting is another feature of this patchset. This implies that we might link the Luks header to other blockdev references, which might alter how the Luks are used and make them incompatible with it. It's not user-friendly in my opinion, and I'm not aware of a more elegant solution.
Quoted 11 lines
With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|
Signature · 1 line
Best regards
Quoted 111 lines · Yong Huang
Quoted 101 lines · Daniel P. Berrangé
Quoted 8 lines · Yong Huang
Quoted 5 lines · Daniel P. Berrangé
Quoted 4 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
The last chapter says we should "separate header volume":
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer
encryption
Quoted 81 lines
Quoted 62 lines
Quoted 1 line
for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19
-5@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
How about the design and usage, could it be simpler? Any advice? :)
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device) ^ | Gluks (format-like disk node) / \ file header (blockdev reference) / \ file file (protocol node) | |Quoted 1 line
disk data Luks data
Quoted 3 lines
What I suggested above ends up with the exact same block driver graph, unless I'm missing something.
I could overlook something or fail to adequately convey the goal of the patchset. :(
Quoted 8 lines
Indeed, utilizing the same block driver might be effective if our only goal is to divide the header volume, giving us an additional way to use Luks.
While supporting encryption for any disk format that QEMU is capable of supporting is another feature of this patchset. This implies that we might link the Luks header to other blockdev references, which might alter how the Luks are used and make them incompatible with it. It's not user-friendly in my opinion, and I'm not aware of a more elegant solution.
That existing LUKS driver can already be used in combination with any QEMU block driver, and in the case of disk formats, can be used either above or below the format, depending on whether you want to encrypt just the image payload, or the payload and metadata ie.
We can do
luks -> qcow2 -> file (qcow2 header and qcow2 payload protected)
or
qcow2 -> luks -> file (only qcow2 payload protected)
And in the qcow2 case, we also have support for LUKS integrated natively into the qcow2 format, which is similar to the 2nd case, with the benefit that we're explicit that the image requires encryption.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 129 lines · Daniel P. Berrangé
Quoted 5 lines · Yong Huang
Quoted 2 lines · Daniel P. Berrangé
Quoted 1 line · Yong Huang
On Tue, Dec 5, 2023 at 12:24 AM Daniel P. Berrangé <
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines · wrote:
Quoted 7 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoThe last chapter says we should "separate header volume":
The LUKS format has ability to store the header in a separate
volume
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
from the payload. We should extend the LUKS driver in QEMU to
support
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
this use case.
As a proof-of-concept, I've created this patchset, which I've
named
Quoted 42 lines
Quoted 42 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
the Gluks: generic luks. As their name suggests, they offer
encryption
Quoted 40 lines
Quoted 40 lines
Quoted 1 line
for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +10
-3@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified usingQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
qapi/block-core.json
Quoted 8 lines
qapi/block-core.json +6
-0+# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since:4.2)
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 14 lines
qapi/block-core.json +3
-2# (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
How about the design and usage, could it be simpler? Any advice? :)
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device) ^ | Gluks (format-like disk node) / \ file header (blockdev reference) / \ file file (protocol node) | |disk data Luks data
Quoted 8 lines
Quoted 3 lines
What I suggested above ends up with the exact same block driver graph, unless I'm missing something.
I could overlook something or fail to adequately convey the goal of the patchset. :(
Indeed, utilizing the same block driver might be effective if our only
goal
Quoted 4 lines
is to divide the header volume, giving us an additional way to use Luks.
While supporting encryption for any disk format that QEMU is capable of supporting is another feature of this patchset. This implies that we
might
Quoted 3 lines
link the Luks header to other blockdev references, which might alter how the Luks are used and make them incompatible with it. It's not user-friendly in my opinion, and I'm not aware of a more elegant
solution.
Quoted 9 lines
That existing LUKS driver can already be used in combination with any QEMU block driver, and in the case of disk formats, can be used either above or below the format, depending on whether you want to encrypt just the image payload, or the payload and metadata ie.
We can do
luks -> qcow2 -> file (qcow2 header and qcow2 payload protected)
OK, I prefer this solution so that we can support any format implemented by the QEMU block driver.
Quoted 19 lines
or
qcow2 -> luks -> file (only qcow2 payload protected)
And in the qcow2 case, we also have support for LUKS integrated natively into the qcow2 format, which is similar to the 2nd case, with the benefit that we're explicit that the image requires encryption.
With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|
Quoted 1 line
Let me make a conclusion about our discussion, if i
misunderstand something,
point that out please:
1. To achieve the generic encryption, extending the pre-existing LUKS QEMU block driver is suggested in practice.
2. Introducing a optional field called "header-file" that store the LUKS header
independently, and once "header-file" was specified, we should use it to encrypt/decrypt the blockdev node referenced by the "file" field.
The blockdev tree is like:
virtio-blk/vhost-user-blk...(frontend device)
^
|
LUKS
/ \
file header-file
/ \data protocol node LUKS header protocol node
3. The usage of the generic LUKS is like:
Take the qcow2 as an example:
1. add a protocol blockdev node of data disk
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-1-storage", "driver": "file",
"filename": "/path/to/test_disk.qcow2"}}'2. add a protocol blockdev node of Luks header as above.
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-2-storage", "driver": "file",
"filename": "/path/to/cipher.gluks" }}'3. add the secret for decrypting the cipher stored in Gluks header as above
$ virsh qemu-monitor-command vm '{"execute":"object-add",
"arguments":{"qom-type": "secret", "id":
"libvirt-2-storage-secret0", "data": "abc123"}}'4. add the qcow2-drived blockdev format node:
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-1-format", "driver": "qcow2",
"file": "libvirt-1-storage"}}'5. add the luks-drived blockdev to connect the qcow2 disk with Luks header by specifying the field "header-file"
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add",
"arguments":{"node-name": "libvirt-2-format", "driver": "luks",
"file": "libvirt-1-format", "header-file": "libvirt-2-storage",
"key-secret": "libvirt-2-format-secret0"}}'6. add the device finally
$ virsh qemu-monitor-command vm '{"execute":"device_add",
"arguments": {"num-queues": "1", "driver": "virtio-blk-pci", "scsi":
"off", "drive": "libvirt-2-format", "id": "virtio-disk2"}}'Anyway, thanks for the comments.
Yong.
Signature · 1 line
Best regards
Am 04.12.2023 um 18:43 hat Daniel P. Berrangé geschrieben:
Quoted 126 lines · Yong Huang
Quoted 111 lines
Quoted 101 lines · Daniel P. Berrangé
Quoted 8 lines · Yong Huang
Quoted 5 lines · Daniel P. Berrangé
Quoted 4 lines · Hyman Huang
This functionality was motivated by the following to-do list seen in crypto documents:
https://wiki.qemu.org/Features/Block/CryptoQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
The last chapter says we should "separate header volume":
The LUKS format has ability to store the header in a separate volume from the payload. We should extend the LUKS driver in QEMU to support this use case.
As a proof-of-concept, I've created this patchset, which I've named the Gluks: generic luks. As their name suggests, they offer
encryption
Quoted 81 lines
Quoted 62 lines
Quoted 1 line
for any format that QEMU theoretically supports.
I don't see the point in creating a new driver.
I would expect detached header support to be implemented via an optional new 'header' field in the existing driver. ie
qapi/block-core.json +19
-5@@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + "*header-file': 'BlockdevRef'} } ## # @BlockdevOptionsGenericCOWFormat:@@ -4941,9 +4945,18 @@ # # Driver specific image creation options for LUKS. # -# @file: Node to create the image format on +# @file: Node to create the image format on. Mandatory +# unless a detached header file is specified using +# @header. # -# @size: Size of the virtual disk in bytes +# @size: Size of the virtual disk in bytes. Mandatory +# unless a detached header file is specified using +# @header. +# +# @header: optional reference to the location of a blockdev +# storing a detached LUKS heaer. The @file option is +# is optional when this is given, unless it is desired +# to perform pre-allocation # # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full)@@ -4952,8 +4965,9 @@ ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', - 'data': { 'file': 'BlockdevRef', - 'size': 'size', + 'data': { '*file': 'BlockdevRef', + '*size': 'size', + '*header': 'BlockdevRef' '*preallocation': 'PreallocMode' } } ##Quoted 3 lines
It ends up giving basicallly the same workflow as you outline, without needing the new block driver
How about the design and usage, could it be simpler? Any advice? :)
As you can see below, the Gluks format block layer driver's design is quite simple.
virtio-blk/vhost-user-blk...(front-end device) ^ | Gluks (format-like disk node) / \ file header (blockdev reference) / \ file file (protocol node) | |Quoted 1 line
disk data Luks data
Quoted 3 lines
What I suggested above ends up with the exact same block driver graph, unless I'm missing something.
I could overlook something or fail to adequately convey the goal of the patchset. :(
Quoted 8 lines
Indeed, utilizing the same block driver might be effective if our only goal is to divide the header volume, giving us an additional way to use Luks.
While supporting encryption for any disk format that QEMU is capable of supporting is another feature of this patchset. This implies that we might link the Luks header to other blockdev references, which might alter how the Luks are used and make them incompatible with it. It's not user-friendly in my opinion, and I'm not aware of a more elegant solution.
That existing LUKS driver can already be used in combination with any QEMU block driver, and in the case of disk formats, can be used either above or below the format, depending on whether you want to encrypt just the image payload, or the payload and metadata ie.
Quoted 7 lines
We can do
luks -> qcow2 -> file (qcow2 header and qcow2 payload protected)
or
qcow2 -> luks -> file (only qcow2 payload protected)
The other way around actually. If you want to have qcow2 metadata encrypted, you need to put luks between qcow2 and file so that it sees the metadata I/O done by the qcow2 driver. If you have luks above qcow2, then qcow2 will see only encrypted data, but will access the metadata as usual without going through encryption.
Kevin
Quoted 11 lines
And in the qcow2 case, we also have support for LUKS integrated natively into the qcow2 format, which is similar to the 2nd case, with the benefit that we're explicit that the image requires encryption.
With regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 6 lines · Yong Huang
Let me make a conclusion about our discussion, if i misunderstand something,
point that out please:1. To achieve the generic encryption, extending the pre-existing LUKS QEMU block driver is suggested in practice.
yes
Quoted 5 lines
2. Introducing a optional field called "header-file" that store the LUKS header
independently, and once "header-file" was specified, we should use it to encrypt/decrypt the blockdev node referenced by the "file" field.
Yes.
Quoted 10 lines
The blockdev tree is like:
virtio-blk/vhost-user-blk...(frontend device) ^ | LUKS / \ file header-file / \data protocol node LUKS header protocol node
That is one possible blockdev tree, but there are many possible variations.
Quoted 32 lines
3. The usage of the generic LUKS is like:
Take the qcow2 as an example:
1. add a protocol blockdev node of data disk
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add", "arguments":{"node-name": "libvirt-1-storage", "driver": "file", "filename": "/path/to/test_disk.qcow2"}}'2. add a protocol blockdev node of Luks header as above.
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add", "arguments":{"node-name": "libvirt-2-storage", "driver": "file", "filename": "/path/to/cipher.gluks" }}'3. add the secret for decrypting the cipher stored in Gluks header as above
$ virsh qemu-monitor-command vm '{"execute":"object-add", "arguments":{"qom-type": "secret", "id": "libvirt-2-storage-secret0", "data": "abc123"}}'4. add the qcow2-drived blockdev format node:
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add", "arguments":{"node-name": "libvirt-1-format", "driver": "qcow2", "file": "libvirt-1-storage"}}'5. add the luks-drived blockdev to connect the qcow2 disk with Luks header by specifying the field "header-file"
$ virsh qemu-monitor-command vm '{"execute":"blockdev-add", "arguments":{"node-name": "libvirt-2-format", "driver": "luks", "file": "libvirt-1-format", "header-file": "libvirt-2-storage", "key-secret": "libvirt-2-format-secret0"}}'
Quoted 4 lines
6. add the device finally
$ virsh qemu-monitor-command vm '{"execute":"device_add", "arguments": {"num-queues": "1", "driver": "virtio-blk-pci", "scsi": "off", "drive": "libvirt-2-format", "id": "virtio-disk2"}}'
Yes, that looks like a valid sequence of steps.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|