diff mbox

[v7,12/20] qcow2: extend specification to cover LUKS encryption

Message ID 20170525163851.8047-13-berrange@redhat.com
State New
Headers show

Commit Message

Daniel P. Berrangé May 25, 2017, 4:38 p.m. UTC
Update the qcow2 specification to describe how the LUKS header is
placed inside a qcow2 file, when using LUKS encryption for the
qcow2 payload instead of the legacy AES-CBC encryption

Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 docs/specs/qcow2.txt | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

Comments

Eric Blake May 25, 2017, 7:39 p.m. UTC | #1
On 05/25/2017 11:38 AM, Daniel P. Berrange wrote:
> Update the qcow2 specification to describe how the LUKS header is
> placed inside a qcow2 file, when using LUKS encryption for the
> qcow2 payload instead of the legacy AES-CBC encryption
> 
> Reviewed-by: Alberto Garcia <berto@igalia.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  docs/specs/qcow2.txt | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 96 insertions(+)
> 

> +
> +The first 592 bytes of the header clusters will contain the LUKS
> +partition header. This is then followed by the key material data areas.
> +The size of the key material data areas is determined by the number of
> +stripes in the key slot and key size. Refer to the LUKS format
> +specification ('docs/on-disk-format.pdf' in the cryptsetup source
> +package) for details of the LUKS partition header format.
> +
> +In the LUKS partition header, the "payload-offset" field will be
> +calculated as normal for the LUKS spec. ie the size of the LUKS
> +header, plus key material regions, plus padding, relative to the
> +start of the LUKS header. Its value is never used in the context
> +of qcow2, however, since the qcow2 file format itself defines where
> +the real payload offset is.

Is it possible/valid for the LUKS payload-offset field to NOT be
qcow2-cluster-aligned?  (I'm guessing yes, for example, if we have 2M
clusters; and that we don't care, because you documented that we don't
actually use that offset).  Is it worth documenting this?

> +== Data encryption ==
> +
> +When an encryption method is requested in the header, the image payload
> +data must be encrypted/decrypted on every write/read. The image headers
> +and metadata is never encrypted.

s/is/are/

> +
> +The algorithms used for encryption vary depending on the method
> +
> + - AES:
> +
> +   The AES cipher, in CBC mode, with 256 bit keys.
> +
> +   Initialization vectors generated using plain64 method, with
> +   the virtual disk sector as the input tweak.

Worth documenting that implementations should avoid creating new images
with this encryption (ie. make it officially part of the spec that this
is not recommended, but merely documented for back-compat data
liberation purposes)?

Reviewed-by: Eric Blake <eblake@redhat.com>
Daniel P. Berrangé May 26, 2017, 1:57 p.m. UTC | #2
On Thu, May 25, 2017 at 02:39:56PM -0500, Eric Blake wrote:
> On 05/25/2017 11:38 AM, Daniel P. Berrange wrote:
> > Update the qcow2 specification to describe how the LUKS header is
> > placed inside a qcow2 file, when using LUKS encryption for the
> > qcow2 payload instead of the legacy AES-CBC encryption
> > 
> > Reviewed-by: Alberto Garcia <berto@igalia.com>
> > Reviewed-by: Max Reitz <mreitz@redhat.com>
> > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> > ---
> >  docs/specs/qcow2.txt | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 96 insertions(+)
> > 
> 
> > +
> > +The first 592 bytes of the header clusters will contain the LUKS
> > +partition header. This is then followed by the key material data areas.
> > +The size of the key material data areas is determined by the number of
> > +stripes in the key slot and key size. Refer to the LUKS format
> > +specification ('docs/on-disk-format.pdf' in the cryptsetup source
> > +package) for details of the LUKS partition header format.
> > +
> > +In the LUKS partition header, the "payload-offset" field will be
> > +calculated as normal for the LUKS spec. ie the size of the LUKS
> > +header, plus key material regions, plus padding, relative to the
> > +start of the LUKS header. Its value is never used in the context
> > +of qcow2, however, since the qcow2 file format itself defines where
> > +the real payload offset is.
> 
> Is it possible/valid for the LUKS payload-offset field to NOT be
> qcow2-cluster-aligned?  (I'm guessing yes, for example, if we have 2M
> clusters; and that we don't care, because you documented that we don't
> actually use that offset).  Is it worth documenting this?

Yeah, it is not required to be cluster aligned, and that doesn't
matter because we don't use it in context of qcow2.

Essentially the only time it would be used if is we had some
optimized way in future to convert from qcow2 w/ luks over to
file w/ luks, without having to decrypt+reencrypt the payload.
ie we could just copy out the entire luks header as-is, and
then copy out the qcow2 payload after it.

> > +== Data encryption ==
> > +
> > +When an encryption method is requested in the header, the image payload
> > +data must be encrypted/decrypted on every write/read. The image headers
> > +and metadata is never encrypted.
> 
> s/is/are/
> 
> > +
> > +The algorithms used for encryption vary depending on the method
> > +
> > + - AES:
> > +
> > +   The AES cipher, in CBC mode, with 256 bit keys.
> > +
> > +   Initialization vectors generated using plain64 method, with
> > +   the virtual disk sector as the input tweak.
> 
> Worth documenting that implementations should avoid creating new images
> with this encryption (ie. make it officially part of the spec that this
> is not recommended, but merely documented for back-compat data
> liberation purposes)?

I guess I could document that here too - I did add such a note to
the qemu-doc.texi at the end of this series.

> 
> Reviewed-by: Eric Blake <eblake@redhat.com>


Regards,
Daniel
diff mbox

Patch

diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt
index 80cdfd0..6509b91 100644
--- a/docs/specs/qcow2.txt
+++ b/docs/specs/qcow2.txt
@@ -45,6 +45,7 @@  The first cluster of a qcow2 image contains the file header:
          32 - 35:   crypt_method
                     0 for no encryption
                     1 for AES encryption
+                    2 for LUKS encryption
 
          36 - 39:   l1_size
                     Number of entries in the active L1 table
@@ -135,6 +136,7 @@  be stored. Each extension has a structure like the following:
                         0xE2792ACA - Backing file format name
                         0x6803f857 - Feature name table
                         0x23852875 - Bitmaps extension
+                        0x0537be77 - Full disk encryption header pointer
                         other      - Unknown header extension, can be safely
                                      ignored
 
@@ -207,6 +209,100 @@  The fields of the bitmaps extension are:
                    Offset into the image file at which the bitmap directory
                    starts. Must be aligned to a cluster boundary.
 
+== Full disk encryption header pointer ==
+
+The full disk encryption header must be present if, and only if, the
+'crypt_method' header requires metadata. Currently this is only true
+of the 'LUKS' crypt method. The header extension must be absent for
+other methods.
+
+This header provides the offset at which the crypt method can store
+its additional data, as well as the length of such data.
+
+    Byte  0 -  7:   Offset into the image file at which the encryption
+                    header starts in bytes. Must be aligned to a cluster
+                    boundary.
+    Byte  8 - 15:   Length of the written encryption header in bytes.
+                    Note actual space allocated in the qcow2 file may
+                    be larger than this value, since it will be rounded
+                    to the nearest multiple of the cluster size. Any
+                    unused bytes in the allocated space will be initialized
+                    to 0.
+
+For the LUKS crypt method, the encryption header works as follows.
+
+The first 592 bytes of the header clusters will contain the LUKS
+partition header. This is then followed by the key material data areas.
+The size of the key material data areas is determined by the number of
+stripes in the key slot and key size. Refer to the LUKS format
+specification ('docs/on-disk-format.pdf' in the cryptsetup source
+package) for details of the LUKS partition header format.
+
+In the LUKS partition header, the "payload-offset" field will be
+calculated as normal for the LUKS spec. ie the size of the LUKS
+header, plus key material regions, plus padding, relative to the
+start of the LUKS header. Its value is never used in the context
+of qcow2, however, since the qcow2 file format itself defines where
+the real payload offset is.
+
+In the LUKS key slots header, the "key-material-offset" is relative
+to the start of the LUKS header clusters in the qcow2 container,
+not the start of the qcow2 file.
+
+Logically the layout looks like
+
+  +-----------------------------+
+  | QCow2 header                |
+  | QCow2 header extension X    |
+  | QCow2 header extension FDE  |
+  | QCow2 header extension ...  |
+  | QCow2 header extension Z    |
+  +-----------------------------+
+  | ....other QCow2 tables....  |
+  .                             .
+  .                             .
+  +-----------------------------+
+  | +-------------------------+ |
+  | | LUKS partition header   | |
+  | +-------------------------+ |
+  | | LUKS key material 1     | |
+  | +-------------------------+ |
+  | | LUKS key material 2     | |
+  | +-------------------------+ |
+  | | LUKS key material ...   | |
+  | +-------------------------+ |
+  | | LUKS key material 8     | |
+  | +-------------------------+ |
+  +-----------------------------+
+  | QCow2 cluster payload       |
+  .                             .
+  .                             .
+  .                             .
+  |                             |
+  +-----------------------------+
+
+== Data encryption ==
+
+When an encryption method is requested in the header, the image payload
+data must be encrypted/decrypted on every write/read. The image headers
+and metadata is never encrypted.
+
+The algorithms used for encryption vary depending on the method
+
+ - AES:
+
+   The AES cipher, in CBC mode, with 256 bit keys.
+
+   Initialization vectors generated using plain64 method, with
+   the virtual disk sector as the input tweak.
+
+ - LUKS:
+
+   The algorithms are specified in the LUKS header.
+
+   Initialization vectors generated using the method specified
+   in the LUKS header, with the physical disk sector as the
+   input tweak.
 
 == Host cluster management ==