From: Hyman Huang <yong.hu...@smartx.com> Sorry for the late post of version 4. The modifications are as follows:
v4: - Rebase on master - squash [PATCH v3 02/10] to [PATCH v3 01/10] - refactor the logic of block_crypto_open_generic in [PATCH v3 02/10] as Daniel suggestted: a. drop the invalid parameter check for "header" option and use the ERRP_GUARD to probe the error of bdrv_open_child instead. b. add a new emum entry to QCryptoBlockOpenFlags to instruct the process of LUKS volume open skip the payload overlap check instead of using the macro INVALID_SECTOR_OFFSET. - drop the detached_header_size field and use local variable instead in [PATCH v3 04/10] - drop the detached-header option in [PATCH v3 04/10] - drop the commit [PATCH v3 05/10]: crypto: Mark the payload_offset_sector invalid for detached LUKS header - introduce QCryptoBlockCreateFlags to instruct the creation process to set the payload_offset_sector to 0 in [PATCH v4 03/7] - refactor the logic of block_crypto_co_create_luks in [PATCH v3 06/10]: a. fix the compile failure b. use the existing 'fail:' label to handle the error logic - refine the comment in qapi suggested by Markus. - modify the test case to accommodate the new implementation. Thanks for commenting on this series, please review. Best regared, Yong v3: - Rebase on master - Add a test case for detached LUKS header - Adjust the design to honour preallocation of the payload device - Adjust the design to honour the payload offset from the header, even when detached - Support detached LUKS header creation using qemu-img - Support detached LUKS header querying - Do some code clean v2: - Simplify the design by reusing the LUKS driver to implement the generic Luks encryption, thank Daniel for the insightful advice. - rebase on master. 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. By enhancing the LUKS driver, it is possible to implement the LUKS volume with a detached header. Normally a LUKS volume has a layout: disk: | header | key material | disk payload data | With a detached LUKS header, you need 2 disks so getting: disk1: | header | key material | disk2: | disk payload data | There are a variety of benefits to doing this: * Secrecy - the disk2 cannot be identified as containing LUKS volume since there's no header * Control - if access to the disk1 is restricted, then even if someone has access to disk2 they can't unlock it. Might be useful if you have disks on NFS but want to restrict which host can launch a VM instance from it, by dynamically providing access to the header to a designated host * Flexibility - your application data volume may be a given size and it is inconvenient to resize it to add encryption.You can store the LUKS header separately and use the existing storage volume for payload * Recovery - corruption of a bit in the header may make the entire payload inaccessible. It might be convenient to take backups of the header. If your primary disk header becomes corrupt, you can unlock the data still by pointing to the backup detached header Take the raw-format image as an example to introduce the usage of the LUKS volume with a detached header: 1. prepare detached LUKS header images $ dd if=/dev/zero of=test-header.img bs=1M count=32 $ dd if=/dev/zero of=test-payload.img bs=1M count=1000 $ cryptsetup luksFormat --header test-header.img test-payload.img > --force-password --type luks1 2. block-add a protocol blockdev node of payload image $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-1-storage", "driver":"file", > "filename":"test-payload.img"}}' 3. block-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": "test-header.img" }}' 4. object-add the secret for decrypting the cipher stored in LUKS header above $ virsh qemu-monitor-command vm '{"execute":"object-add", > "arguments":{"qom-type":"secret", "id": > "libvirt-2-storage-secret0", "data":"abc123"}}' 5. block-add the raw-drived blockdev format node $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-1-format", "driver":"raw", > "file":"libvirt-1-storage"}}' 6. block-add the luks-drived blockdev to link the raw disk with the LUKS header by specifying the field "header" $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-2-format", "driver":"luks", > "file":"libvirt-1-format", "header":"libvirt-2-storage", > "key-secret":"libvirt-2-format-secret0"}}' 7. hot-plug the virtio-blk device finally $ virsh qemu-monitor-command vm '{"execute":"device_add", > "arguments": {"num-queues":"1", "driver":"virtio-blk-pci", > "drive": "libvirt-2-format", "id":"virtio-disk2"}}' Starting a VM with a LUKS volume with detached header is somewhat similar to hot-plug in that both maintaining the same json command while the starting VM changes the "blockdev-add/device_add" parameters to "blockdev/device". Hyman Huang (7): crypto: Support LUKS volume with detached header qapi: Make parameter 'file' optional for BlockdevCreateOptionsLUKS crypto: Modify the qcrypto_block_create to support creation flags block: Support detached LUKS header creation using blockdev-create block: Support detached LUKS header creation using qemu-img crypto: Introduce 'detached-header' field in QCryptoBlockInfoLUKS tests: Add case for LUKS volume with detached header MAINTAINERS | 5 + block.c | 5 +- block/crypto.c | 144 ++++++++++-- block/crypto.h | 8 + block/qcow.c | 2 +- block/qcow2.c | 2 +- crypto/block-luks.c | 41 +++- crypto/block.c | 4 +- crypto/blockpriv.h | 2 + include/crypto/block.h | 16 ++ qapi/block-core.json | 13 +- qapi/crypto.json | 8 +- tests/qemu-iotests/210.out | 4 + tests/qemu-iotests/tests/luks-detached-header | 218 ++++++++++++++++++ .../tests/luks-detached-header.out | 5 + tests/unit/test-crypto-block.c | 2 + 16 files changed, 447 insertions(+), 32 deletions(-) create mode 100755 tests/qemu-iotests/tests/luks-detached-header create mode 100644 tests/qemu-iotests/tests/luks-detached-header.out -- 2.31.1