qemu/include/crypto
Hyman Huang 9ad5c4e7ee crypto: Support LUKS volume with detached header
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".

Signed-off-by: Hyman Huang <yong.huang@smartx.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-02-09 12:50:33 +00:00
..
aes-round.h crypto: Add aesdec_ISB_ISR_AK_IMC 2023-07-08 07:30:17 +01:00
aes.h target/riscv: Use existing lookup tables for MixColumns 2023-09-11 11:45:54 +10:00
afsplit.h Don't talk about the LGPL if the file is licensed under the GPL 2019-01-30 10:51:20 +01:00
akcipher.h include/: spelling fixes 2023-09-08 13:08:52 +03:00
block.h crypto: Support LUKS volume with detached header 2024-02-09 12:50:33 +00:00
cipher.h crypto: Allocate QCryptoCipher with the subclass 2020-09-10 11:02:23 +01:00
clmul.h crypto: Add generic 64-bit carry-less multiply routine 2023-09-15 13:57:00 +00:00
desrfb.h replace TABs with spaces 2023-03-20 12:43:50 +01:00
hash.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00
hmac.h crypto: define cleanup functions for use with g_autoptr 2019-08-22 10:47:12 +01:00
init.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00
ivgen.h include/: spelling fixes 2023-09-08 13:08:52 +03:00
pbkdf.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00
random.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00
secret_common.h bulk: Do not declare function prototypes using 'extern' keyword 2023-08-31 19:47:43 +02:00
secret_keyring.h qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros 2020-09-18 14:12:32 -04:00
secret.h Use DECLARE_*CHECKER* macros 2020-09-09 09:27:09 -04:00
sm4.h crypto: Add SM4 constant parameter CK 2023-09-11 11:45:55 +10:00
tls-cipher-suites.h Clean up header guards that don't match their file name 2022-05-11 16:49:06 +02:00
tlscreds.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlscredsanon.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlscredspsk.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlscredsx509.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlssession.h crypto: TLS: introduce check_pending 2023-02-15 11:01:03 -05:00
xts.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00