Skip to content

Upstream Image Encryption Standardization #560

Open

Description

@josephineSei

Currently there is the possibility in Cinder to encrypt volumes and in Nova to use qcow2 encrypted images (still under development).
Both can lead to and use LUKS-encrpyted images, but those are different and not aligned:

  • qcow2 with LUKS in it for Nova
  • LUKS raw blocks for Cinder

@markus-hentsch also found out in #541 that uploading a LUKS-encrypted image (that was created from a volume) to another cloud in combination with setting a few parameteres (cinder_encryption_key, etc...) will result in an image that can be used to create an encrpyted and functional volume.

As a user it would be good to have a streamlined operation to use encrypted images in openstack for both volumes and ephemeral storage and to also allow interoperability between clouds.
Therefore we need and will propose standardized parameters to describe and detect an encrypted image, which might be similar to the parameters described here: https://specs.openstack.org/openstack/cinder-specs/specs/zed/image-encryption.html
But will use the LUKS encryption.
So those encrypted images could be natively mounted in Nova or just formed into a volume (raw LUKS images can be directly used, qcow images need to be flattened).

With such a way encrypted backup images can be easily downloaded and transferred to another cloud.

  • A spec has to be written for Glance (and maybe Cinder?)
  • Implementation in Glance to standardize image parameters
  • Implementation in OSC/SDK to encrypt while uploading and decrypt while downloading an image
  • Implementation in Cinder to align to new standard parameters
  • Implementation in Cinder to flatten encrypted qcow to raw volumes

This is a result from a lengthy discussion at the PTG with Nova, Cinder and Glance ( https://etherpad.opendev.org/p/dalmatian-ptg-cinder#L376 )

Followup tasks may be to implement re-encryption to fully change keys for LUKS volumes and images.

Activity

  1. added
    question
    on Apr 11, 2024
  2. added
    SCS-VP10
    standards
    on Apr 11, 2024
  3. josephineSei commented on Apr 11, 2024

    @josephineSei
    ContributorAuthor

    I have discussed and outlined the spec with @markus-hentsch and currently writing it.

  4. markus-hentsch commented on Apr 11, 2024

    @markus-hentsch
    Contributor

    On the user side we'd need to be able to create LUKS-encrypted files. Nova devs made us aware of the QEMU tooling being able to do so allegedly.

    Here is the Nova implementation:

    Here's a shortened example:

    echo "muchsecretsuchwow" > secret_file.key
    
    qemu-img convert -f raw -O luks --object secret,id=sec,file=secret_file.key -o key-secret=sec \
    -o cipher-alg=aes-256 -o cipher-mode=xts -o hash-alg=sha256 \
     -o ivgen-alg=plain64 -o ivgen-hash-alg=sha256 \
    $INPUT_FILE $OUTPUT_LUKS_FILE

    It works within a Docker container running Ubuntu LTS but interestingly it doesn't on my NixOS setup, failing with:

    qemu-img: output.luks: error while converting luks: Unsupported cipher mode xts
    

    Versions of qemu-img are 6.2.0 (Ubuntu) and 8.1.5 (NixOS) respectively. I wonder if there is another system dependency in play here or if it's the version difference. We should investigate because this impacts the ability to create images on the client side.

    EDIT:

    Tried it on ubuntu:noble image which ships qemu-img 8.2.1 and it still works. So no deprecation problem here in regards to the qemu-img version. I think we can safely ignore it as a NixOS-specific issue then.

  5. markus-hentsch commented on Apr 12, 2024

    @markus-hentsch
    Contributor

    As I was adding restore instructions to the user data backup guide in SovereignCloudStack/docs#176 I reproduced the process of creating volumes from previously encrypted (LUKS) images originating from Cinder itself on my DevStack and noticed that Cinder does not verify that the target volume actually has an encrypted type:

    $ file image.raw
    image.raw: LUKS encrypted file, ver 1 [aes, xts-plain64, sha256]
    
    $ file image.key
    image.key: data
    
    $ openstack secret store --algorithm aes --bit-length 256 --mode cbc \
      --secret-type symmetric --file image.key --name restored-image-key
      
    $ openstack secret list -f value -c "Secret href" -c "Name"
    http://10.0.1.116/key-manager/v1/secrets/6ea6b0a8-de50-45b8-90b7-9470c4dd201a restored-image-key
    
    $ export SECRET_ID=6ea6b0a8-de50-45b8-90b7-9470c4dd201a
    
    $ openstack image create --file image.raw \
      --property cinder_encryption_key_id=$SECRET_ID \
      --property cinder_encryption_key_deletion_policy=on_image_deletion \
      restored-image
    
    $ openstack volume create --size 1 \
      --image restored-image volume-restored-notype
    
    $ openstack volume show -f value -c type volume-restored-notype
    lvmdriver-1  # <- this is an *unencrypted* volume type! (which contains LUKS blocks now)
    
    $ openstack volume create --size 1 \
      --image restored-image --type lvmdriver-1-LUKS \
      volume-restored-lukstype
    
    $ openstack volume show -f value -c type volume-restored-lukstype
    lvmdriver-1-LUKS
    
    $ openstack server create \
      --volume volume-restored-notype \
      ... server-from-untyped-volume
      
    $ openstack server create \
      --volume volume-restored-lukstype \
      ... server-from-luks-volume

    This results in the server server-from-untyped-volume being stuck at "No bootable device found" on the virtual console. Only server-from-luks-volume where a LUKS volume type was explicitly chosen while restoring the LUKS image was bootable.

    It seems that this is an oversight in Cinder in its current implementation?

  6. josephineSei commented on Apr 12, 2024

    @josephineSei
    ContributorAuthor

    I tested this with a simple encrypted volume to encrypted image to volume:

    stack@devstack:~/devstack$ openstack image show encrypted-volume-image
    +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Field            | Value                                                                                                                                                                   |
    +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | checksum         | 4f0538390cb7728f6e02d6a58a824e11                                                                                                                                        |
    | container_format | bare                                                                                                                                                                    |
    | created_at       | 2024-04-11T13:09:08Z                                                                                                                                                    |
    | disk_format      | raw                                                                                                                                                                     |
    | file             | /v2/images/49febf2e-4f20-47f0-8230-660c2dcb19dc/file                                                                                                                    |
    | id               | 49febf2e-4f20-47f0-8230-660c2dcb19dc                                                                                                                                    |
    | min_disk         | 0                                                                                                                                                                       |
    | min_ram          | 0                                                                                                                                                                       |
    | name             | encrypted-volume-image                                                                                                                                                  |
    | owner            | 15f2ab0eaa5b4372b759bde609e86224                                                                                                                                        |
    | properties       | cinder_encryption_key_deletion_policy='on_image_deletion', cinder_encryption_key_id='286339bc-5484-4a27-b24a-816f89a2968c', hw_rng_model='virtio', locations='[{'url':  |
    |                  | 'rbd://adbc1d67-adf7-4a13-94b5-2a2570d41ed9/images/49febf2e-4f20-47f0-8230-660c2dcb19dc/snap', 'metadata': {}}]', os_hash_algo='sha512',                                |
    |                  | os_hash_value='7160b7451962496108194179757221dbbb5af7654b205a63cf6284a70dd1caed8ee289b98a56f0cb0d37e363adc18cc334d0f1bf6be937e1e9af9036009b0856', os_hidden='False',    |
    |                  | owner_specified.openstack.md5='', owner_specified.openstack.object='images/cirros-0.6.2-x86_64-disk', owner_specified.openstack.sha256='', signature_verified='False'   |
    | protected        | False                                                                                                                                                                   |
    | schema           | /v2/schemas/image                                                                                                                                                       |
    | size             | 3221225472                                                                                                                                                              |
    | status           | active                                                                                                                                                                  |
    | tags             |                                                                                                                                                                         |
    | updated_at       | 2024-04-11T13:11:31Z                                                                                                                                                    |
    | virtual_size     | 3221225472                                                                                                                                                              |
    | visibility       | shared                                                                                                                                                                  |
    +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    stack@devstack:~/devstack$ openstack volume create --size 3 --image encrypted-volume-image volume-from-LUKS-image
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | attachments         | []                                   |
    | availability_zone   | nova                                 |
    | bootable            | false                                |
    | consistencygroup_id | None                                 |
    | created_at          | 2024-04-12T11:23:52.246101           |
    | description         | None                                 |
    | encrypted           | False                                |
    | id                  | f790ecd4-eea6-4a8d-8cf6-d1a038c91d60 |
    | migration_status    | None                                 |
    | multiattach         | False                                |
    | name                | volume-from-LUKS-image               |
    | properties          |                                      |
    | replication_status  | None                                 |
    | size                | 3                                    |
    | snapshot_id         | None                                 |
    | source_volid        | None                                 |
    | status              | creating                             |
    | type                | ceph                                 |
    | updated_at          | None                                 |
    | user_id             | 6cf194afebb6469e8423f50500b5c3fc     |
    +---------------------+--------------------------------------+
    

    A seemingly unencrypted volume is created from the encrypted image. But as far as we know, there is no decrypting mechanism implemented in Cinder to go from such a Cinder-specific LUKS encryption in the image to an unencrypted volume.

    We should definitely file a bug in Cinder for this one.

  7. josephineSei commented on Apr 12, 2024

    @josephineSei
    ContributorAuthor

    How to test, if a server booted

    When creating a server from a volume, like my above case, it will be shown as active even though this cannot be true

    stack@devstack:~/devstack$ openstack server list
    +-----------------+-----------------+--------+-----------------+------------------+----------+
    | ID              | Name            | Status | Networks        | Image            | Flavor   |
    +-----------------+-----------------+--------+-----------------+------------------+----------+
    | 8ba1b529-d1d9-  | will-this-      | ACTIVE | private=10.0.0. | N/A (booted from | m1.small |
    | 4f5b-a97d-      | server-boot?    |        | 47, fd13:d046:e | volume)          |          |
    | 6756f61451e0    |                 |        | 727:0:f816:3eff |                  |          |
    |                 |                 |        | :feae:b8e1      |                  |          |
    | 66f8f821-ec26-  | my-new-server   | ACTIVE | private=10.0.0. | N/A (booted from | m1.small |
    | 4264-807e-      |                 |        | 41, fd13:d046:e | volume)          |          |
    | 36ec016d51f9    |                 |        | 727:0:f816:3eff |                  |          |
    |                 |                 |        | :fe98:3e70      |                  |          |
    +-----------------+-----------------+--------+-----------------+------------------+----------+
    

    To show the boot log of a server the following command can be used:

    stack@devstack:~/devstack$ openstack console log show my-new-server > other-server.log
    

    The log will then look something like:

    [    0.000000] Linux version 5.15.0-71-generic (buildd@lcy02-amd64-044) (gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0>
    [    0.000000] Command line: LABEL=cirros-rootfs ro console=tty1 console=ttyS0
    [    0.000000] KERNEL supported cpus:
    [    0.000000]   Intel GenuineIntel
    [    0.000000]   AMD AuthenticAMD
    [    0.000000]   Hygon HygonGenuine
    [    0.000000]   Centaur CentaurHauls
    [    0.000000]   zhaoxin   Shanghai
    [    0.000000] x86/fpu: x87 FPU will use FXSAVE
    [    0.000000] signal: max sigframe size: 1440
    [    0.000000] BIOS-provided physical RAM map:
    [    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
    [    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
    [    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
    [    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007ffdcfff] usable
    [    0.000000] BIOS-e820: [mem 0x000000007ffdd000-0x000000007fffffff] reserved
    [    0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
    [    0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
    .....
    

    But if created from a server with an unencrypted volume from an encrypted image the log file remains empty:

    stack@devstack:~/devstack$ openstack console log show 02d13a4c-a6a0-4b40-850c-9b7ddd13d4bb
         <- log output should be here
    stack@devstack:~/devstack$
    
  8. josephineSei commented on Apr 12, 2024

    @josephineSei
    ContributorAuthor
  9. josephineSei commented on Apr 12, 2024

    @josephineSei
    ContributorAuthor

    I reported the bug uncovered in #560 (comment) at https://bugs.launchpad.net/cinder/+bug/2061154

    I raised this in the IRC, the following was the answer:

    <Luzi> eharney, while trying some things with the LUKS-image we found this behavior: https://bugs.launchpad.net/cinder/+bug/2061154
    <Luzi> is this known?
    <eharney> Luzi: i think this is done on purpose because we didn't want to have users accidentally decrypting volume images, but it might still be useful to let them copy the data around (rather than failing)
    <eharney> it would make sense to document this behavior because it is kind of surprising in the standard use of volumes/images
    <eharney> generally, people should make sure they are using an encrypted volume type
    <Luzi> or maybe add a check for the a volume type with encryption type?
    <eharney> i think we didn't want it to fail because there are situations (copying data around to different places rather than booting instances) where it's useful to allow this
    
  10. added
    upstream
    on Apr 15, 2024
  11. josephineSei commented on Apr 25, 2024

    @josephineSei
    ContributorAuthor

    We currently evaluate whether we will also need a spec for Cinder. What we definitely need is a blueprint for Cinder to track all development. I have written a blueprint and tried to include all possible points, where there will be implementation needed in Cinder:
    https://blueprints.launchpad.net/cinder/+spec/standardize-image-encryption-metadata
    From my opinion there should be a spec, to at least show all use cases where encrypted images need to be considered.

  12. 51 remaining items

  13. markus-hentsch commented on Oct 28, 2024

    @markus-hentsch
    Contributor

    We took part in the PTG this week and we discussed with Cinder, Glance and some Nova people the impact of the CVEs on this topic.

    Just to complement this, here are my notes from the meeting about what we agreed on:

    1. Extend the existing disk_format=qcow2 with feature support for qcow2+luks encryption.
    2. Add new disk_format=luks for raw LUKS images. An OpenStack developer noted: this should be compatible with container_format=compressed.
    3. For both disk_format=qcow2 and disk_format=luks the image metadata property os_encrypt_key_id should be used to reference the key in Barbican.
    4. For both disk_format=qcow2 and disk_format=luks the image metadata property os_encrypt_format will specify the LUKS version used: luksv1 or luksv2. Support in the image inspector may be added to verify this via the qcow or LUKS header.
    5. When Cinder consumes a qcow2+luks image, it is converted to raw LUKS.
    6. Barbican keys representing LUKS passphrases (referenced by os_encrypt_key_id) are handled according to their secret type (if "passphrase" then skip hexlify else do hexlify), which is implemented by the already merged os-brick patch. We keep this approach.
  14. markus-hentsch commented on Oct 28, 2024

    @markus-hentsch
    Contributor

    I was just starting to work on dissecting the hex values of a LUKS header in order to add proper image inspector support in Glance when I happened to notice that the implementation was moved to oslo.utils in August 1.

    Furthermore, support for LUKSv1 header inspection for a luks disk_format was merged just a few days ago: openstack/oslo.utils@7ab82d4

    It seems that this is a direct result of the PTG session and one less thing to consider in our patchsets.
    I need to rebase the current patchsets first to catch all the latest changes though.

    Footnotes

    1. https://github.com/openstack/glance/commit/0be2737d66ea90b64270e09402ea5b088a28f415 ↩

  15. markus-hentsch commented on Oct 28, 2024

    @markus-hentsch
    Contributor

    I revised the patchsets for Glance and Cinder today. I added disk_format=luks support and the LUKSv1 / LUKSv2 handling for os_encrypt_format in Cinder.

    @josephineSei I removed os_encrypt_cipher from the implementation for now. We currently have two formats:

    • disk_format=qcow2 + os_encrypt_* metadata
    • disk_format=luks + os_encrypt_* metadata

    In both cases, the os_encrypt_format can either be LUKSv1 or LUKSv2. The cipher details (e.g. AES-256, XTS mode) are details of the LUKS encryption and encoded directly in the LUKS header. LUKS can handle the header without prior knowledge of the cipher. As such, any os_encrypt_cipher metadata would be purely cosmetic but serve no purpose in processing the images as LUKS/qcow will read the header themselves.

    As a result, I started wondering whether trying to properly identify the cipher used (either by inspecting the header in the OSC during user upload or trying to guess it from the Volume Type encryption metadata in case of Cinder's volume-to-image) is worth the risk of getting it wrong, considering it has no functional purpose and is just informational metadata at this point.

    I think we could keep things a bit more simple by dropping os_encrypt_cipher and let the LUKS tools do their job based on the LUKS header (which is the actual source of truth in this case), keeping only os_encrypt_format as a coarse differentiation for the image inspector.
    @josephineSei what's your opinion on this?

    Note: I still need to add os_decrypt_size support to Cinder.

  16. josephineSei commented on Nov 1, 2024

    @josephineSei
    ContributorAuthor

    I think you are correct, we do net loose information, when removing the os_encrypt_cipher. I adjust the spec accordingly.

    We still have the following metadata:

    • os_encrypt_format - the specific mechanism used, e.g. 'LUKSv1'
    • os_encrypt_key_id - reference to key in the key manager
    • os_encrypt_key_deletion_policy - on image deletion indicates whether the
      key should be deleted too
    • os_decrypt_container_format - format change, e.g. from compressed to
      bare
    • os_decrypt_format - the image format after decryption, when the
      disk_format is LUKS. It should be raw or gpt
    • os_decrypt_size - size after payload decryption

    The ones that MUST be set are:

    • os_encrypt_format - the specific mechanism used, e.g. 'LUKSv1'
    • os_encrypt_key_id - reference to key in the key manager
    • os_decrypt_size - size after payload decryption

    The other ones are:
    The os_encrypt_key_deletion_policy defaults to FALSE, when I am reading the docs in the MR correct.

    The os_decrypt_container_format may only be needed, when the container format is changed, e.g. for compressed.
    The os_decrypt_format is only required for the disk_format = LUKS.

    I think the decrypt format is needed, but it is also new (due to the disk_format being LUKS), and not added yet to the patches, right? @markus-hentsch do you want to discuss this point? Maybe it is not needed, because we only allow raw/gpt images in LUKS blocks... But I am not sure about this.

  17. josephineSei commented on Nov 8, 2024

    @josephineSei
    ContributorAuthor

    I try to get more attention to all of this and added reviewers to the patches.

  18. markus-hentsch commented on Nov 11, 2024

    @markus-hentsch
    Contributor

    I updated the Glance implementation patchset and addressed review comments by adding releases notes and unit test coverage for secret consumer exceptions.

  19. markus-hentsch commented on Nov 11, 2024

    @markus-hentsch
    Contributor

    I started testing the changed architecture and ran into a failing openstack image create --disk-format luks because now that we moved to introducing a new disk_format for raw LUKS images after all, we need to adjust the OSC code.

    For this purpose, I started a patchset for python-openstackclient, which I also labelled with the "LUKS-image-encryption" topic: https://review.opendev.org/c/openstack/python-openstackclient/+/934672

  20. josephineSei commented on Nov 12, 2024

    @josephineSei
    ContributorAuthor

    After our discussion About the 'os_decrypt_format' I removed the mention of this from the spec, and answered abhisheks comment on this. I also included, that we expect all luks-images to be 'raw' after encryption.

  21. markus-hentsch commented on Nov 12, 2024

    @markus-hentsch
    Contributor

    Cinder internally rewriting format detection from 'luks' to 'raw' for qemu-img conversions

    During testing of the changed implementation, I discovered that the shift in direction to actually introduce disk_format=luks has more repercussions in Cinder than I originally thought. Cinder makes extensive use of qemu-img for format detection and conversion.

    However, they use an override to treat images received from Glance that qemu-img detects as 'luks' as 'raw' instead because they expect those images to be originating from Cinder (former snapshots of LUKS volumes). The introduction of disk_format=luks now has side effects that will make Cinder erronously attempt conversion:

    • check_image_format() will erronously report a format mismatch because the image metadata states it is 'luks' but the aforementioned file detection override to 'raw' makes it look like raw
    • upload_to_image() (image from volume) will think that a conversion (encryption) from raw (volume) to luks (image) is necessary and attempts to encrypt the already encrypted data
    • fetch_to_volume_format() (volume from image) will think that a conversion from luks (image) to raw (volume) is necessary and attempts to decrypt the image data

    In all cases, we actually have the same format on both sides (luks) but Cinder treats its own LUKS data (e.g. volumes) as 'raw'. We don't want any encryption or conversion here but simply have the data copied over.

    At first I tried removing the override and let Cinder actually detect its own data as 'luks'. However, this led to some very tricky pitfalls because as soon as 'luks' is on some side of a qemu-img convert command (which Cinder uses a lot to automatically process necessary conversion between volumes and images) it will attempt encryption/decryption and fail because no passphrases are provided to method calls. There would have been numerous places in the code where special context-dependent handling would have been necessary to avoid qemu-img thinking it needs to encrypt/decrypt something.

    It turned out to be actually easier to keep treating Cinder's internal data as 'raw' and have isolated instances of function flags that allow overriding the qemu-img behavior to treat the data as raw and simply copy it over.
    I adjusted the Cinder patchset to implement that.

  22. markus-hentsch commented on Nov 12, 2024

    @markus-hentsch
    Contributor

    I adjusted unit tests and added release notes to the Cinder patchset. Regular pipelines look good but IBM and StorPool integration tests fail.

    @josephineSei I added the os_decrypt_format/gpt topic along with a regular update and pipeline questions to https://etherpad.opendev.org/p/cinder-epoxy-meetings for discussion tomorrow.

  23. markus-hentsch commented on Nov 19, 2024

    @markus-hentsch
    Contributor

    Compatibility with image compression (container_format=compressed)

    Since I stumbled upon a few spots referencing image compression while writing the patchset in Cinder, I had a closer look at the topic and tested it with the image encryption introduced by the patchset(s).

    NOTE: The OpenStack client does not allow to specify --container-format compressed neither for image create --file nor image create --volume. The use case for the image compression can only be triggered when interacting with the API directly, e.g., via curl! As such, it will be a niche use case but still should be checked for compatibility with the patchset.

    Compressed image from volume

    With the current patchset, Cinder will prevent volume to image with compressed flag:

    VOLUME_NAME=test-luks-img
    VOLUME_ID=$(openstack volume show -c id -f value $VOLUME_NAME)
    PROJECT_ID=$(openstack token issue -f value -c project_id)
    URL="http://192.168.144.111/volume/v3/$PROJECT_ID/volumes/$VOLUME_ID/action"
    TOKEN=$(openstack token issue -f value -c id)
    
    curl -X POST $URL -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" \
    -d '{"os-volume_upload_image": {"force": false, "image_name": "compressed-luks-test", "container_format": "compressed", "disk_format": "luks"}}'
    
      {"badRequest": {"code": 400, "message": "An encrypted volume uploaded as an image
       must use 'luks' disk_format and 'bare' container_format."}}

    Conclusion:
    As openstack image create --volume does not allow using the compressed container_format, the only way to trigger this is a direct API call.
    Furthermore, compressing an encrypted block device image will not yield any useful results as most encryptions will not achieve smaller file size when compressed after (!) encryption.
    As such, I think this is a non-issue and disallowing compression here is not problematic.

    Volume from commpressed image

    Since openstack image create --file cannot be used here, this is a bit more complicated to construct.
    We need to create an empty image metadata object and then upload the compressed data to it.

    # compress the image
    cat cirros.raw.luks | gzip > cirros.raw.luks.gzip
    file cirros.raw.luks.gzip
      cirros.raw.luks.gzip: gzip compressed data, from Unix, original size modulo 2^32 119508992
    
    # retrieve Barbican key ID of the encryption key
    SECRET_ID=$(openstack secret list -f value --name luks-image-passphrase \
        | head -n1 | cut -d' ' -f1 | rev | cut -d'/' -f1 | rev)
    TOKEN=$(openstack token issue -f value -c id)
    
    # create the empty image vessel with metadata
    curl -X POST http://192.168.144.111/image/v2/images \
    -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" \
    -d '{"disk_format": "luks", "name": "test-compressed-luks", "container_format": "compressed", "os_encrypt_key_id": "'$SECRET_ID'", "os_encrypt_key_deletion_policy": "none", "os_encrypt_format": "LUKSv1"}'
    IMAGE_ID=$(openstack image show test-compressed-luks -f value -c id)
    
    # upload the binary gzip-compressed data to the image vessel
    python3 -c "import requests; headers = {'Content-Type': 'application/octet-stream', 'X-Auth-Token': '$TOKEN'}; r = requests.put('http://192.168.144.111/image/v2/images/$IMAGE_ID/file', data=open('cirros.raw.luks.gzip', 'rb'), headers=headers); print(r.status_code, r.text)"
    
    # verify the data
    openstack image save --file downloaded-compressed-image.gzip $IMAGE_ID
    md5sum *.gzip
      366e855538951f13cd1ff40f28b17d65  cirros.raw.luks.gzip
      366e855538951f13cd1ff40f28b17d65  downloaded-compressed-image.gzip
    
    # create the volume
    openstack volume create --image $IMAGE_ID --size 1 --type lvmdriver-1-LUKS test-luks-gzip-img

    Note that for binary image data upload, both curl -X PUT --data-binary and curl -X PUT --upload-file ended up with a 500 internal server error ("OSError: timeout during read(8192) on wsgi.input"). That's why I had to resort to the Python command instead for uploading the compressed data.

    Compression disabled in Cinder

    If cinder.conf:allow_compression_on_image_upload was disabled (which is the default), the volume will enter error state and cinder-volume will print the following log message:

    cinder.exception.ImageUnacceptable: Image 058fdc89-8701-4581-a0ea-5e6be99dc4f2
    is unacceptable: Image compression disallowed, but container_format is compressed.
    

    Compression enabled in Cinder

    If cinder.conf contains

    allow_compression_on_image_upload = True
    compression_format = gzip

    ... then the created volume will eventually reach available state and can be used to create a succesfully booting VM in Nova:

    openstack server create --flavor m1.tiny --network admin-private \
        --volume test-luks-gzip-img --security-group admin-access-group \
        vm-luksgzipimg-vol
    
    openstack floating ip create --description "serverIPgzip" public
    FIPGZIP=$(openstack floating ip list --long -f value -c Description -c "Floating IP Address" \
        | grep "serverIPgzip" | cut -d ' ' -f1)
    openstack server add floating ip vm-luksgzipimg-vol $FIPGZIP
    echo $FIPGZIP
    ssh cirros@$FIPGZIP
      The authenticity of host '10.0.1.113 (10.0.1.113)' can't be established.
      ED25519 key fingerprint is SHA256:...
      This key is not known by any other names
      Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
      Warning: Permanently added '10.0.1.113' (ED25519) to the list of known hosts.
      [email protected]'s password:
      $ hostname
      vm-luksgzipimg-vol

    Conclusion:
    The current patchset seems compatible with gzip-compressed images without issues.

  24. markus-hentsch commented on Nov 19, 2024

    @markus-hentsch
    Contributor

    I did some QA to the Cinder patchset.
    I updated the patchset for Cinder and loosened the restriction on image-from-volume a bit: if the volume is encrypted, disk_format=raw is accepted at the API (like before) for the "os-volume_upload_image" action and the disk_format is internally rewritten to 'luks' automatically. This makes the API a bit more backwards compatible, as in disk_format=raw for "os-volume_upload_image" action will lead to LUKS-encrypted images just like before. It just adopts the new 'luks' disk_format when actually storing the image in Glance now to be in line with the standardization.

    I added a bunch of unit tests to cover the intricate parts of the patchset where we do special handling for the luks format internally. With that, test coverage of the new behaviors in Cinder should be quite good now.

  25. josephineSei commented on Nov 21, 2024

    @josephineSei
    ContributorAuthor

    I have looked into the zuul tests and found one failing unit test. I tried to fix it and also put the image encryption on the glance teams agenda to get more reviews and drive this forward.

  26. josephineSei commented on Nov 22, 2024

    @josephineSei
    ContributorAuthor

    We got reviews on the spec (with a +2 :)) and on the glance patch. We may need to split up the glance patch in smaller patches, but most of the comments were on smaller issues.

  27. josephineSei commented on Nov 25, 2024

    @josephineSei
    ContributorAuthor

    The patch set regarding the image encryption is in a good state:
    https://review.opendev.org/q/topic:%22LUKS-image-encryption%22
    We discussed several ways with upstream and in the last PTG we only redefined some details.
    The implementation mostly needs only reviews from the openstack development teams and the patches may need some minor updates according to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

SCS-VP10questionstandardsupstream

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions