Repository navigation
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDoing
Activity
josephineSei commentedon Apr 11, 2024
I have discussed and outlined the spec with @markus-hentsch and currently writing it.
markus-hentsch commentedon Apr 11, 2024
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:
It works within a Docker container running Ubuntu LTS but interestingly it doesn't on my NixOS setup, failing with:
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:nobleimage 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.markus-hentsch commentedon Apr 12, 2024
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:
This results in the server
server-from-untyped-volumebeing stuck at "No bootable device found" on the virtual console. Onlyserver-from-luks-volumewhere 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?
josephineSei commentedon Apr 12, 2024
I tested this with a simple encrypted volume to encrypted image to volume:
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.
josephineSei commentedon Apr 12, 2024
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
To show the boot log of a server the following command can be used:
The log will then look something like:
But if created from a server with an unencrypted volume from an encrypted image the log file remains empty:
josephineSei commentedon Apr 12, 2024
I uploaded the new spec to gerrit: https://review.opendev.org/c/openstack/glance-specs/+/915726
markus-hentsch commentedon Apr 12, 2024
I reported the bug uncovered in #560 (comment) at https://bugs.launchpad.net/cinder/+bug/2061154
josephineSei commentedon Apr 12, 2024
I raised this in the IRC, the following was the answer:
josephineSei commentedon Apr 25, 2024
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.
51 remaining items
markus-hentsch commentedon Oct 28, 2024
Just to complement this, here are my notes from the meeting about what we agreed on:
disk_format=qcow2with feature support for qcow2+luks encryption.disk_format=luksfor raw LUKS images. An OpenStack developer noted: this should be compatible withcontainer_format=compressed.disk_format=qcow2anddisk_format=luksthe image metadata propertyos_encrypt_key_idshould be used to reference the key in Barbican.disk_format=qcow2anddisk_format=luksthe image metadata propertyos_encrypt_formatwill specify the LUKS version used:luksv1orluksv2. Support in the image inspector may be added to verify this via the qcow or LUKS header.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.markus-hentsch commentedon Oct 28, 2024
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
luksdisk_formatwas merged just a few days ago: openstack/oslo.utils@7ab82d4It 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
https://github.com/openstack/glance/commit/0be2737d66ea90b64270e09402ea5b088a28f415 ↩
markus-hentsch commentedon Oct 28, 2024
I revised the patchsets for Glance and Cinder today. I added
disk_format=lukssupport and theLUKSv1/LUKSv2handling foros_encrypt_formatin Cinder.@josephineSei I removed
os_encrypt_cipherfrom the implementation for now. We currently have two formats:disk_format=qcow2+os_encrypt_*metadatadisk_format=luks+os_encrypt_*metadataIn both cases, the
os_encrypt_formatcan either beLUKSv1orLUKSv2. 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, anyos_encrypt_ciphermetadata 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_cipherand let the LUKS tools do their job based on the LUKS header (which is the actual source of truth in this case), keeping onlyos_encrypt_formatas a coarse differentiation for the image inspector.@josephineSei what's your opinion on this?
Note: I still need to add
os_decrypt_sizesupport to Cinder.josephineSei commentedon Nov 1, 2024
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 manageros_encrypt_key_deletion_policy- on image deletion indicates whether thekey should be deleted too
os_decrypt_container_format- format change, e.g. fromcompressedtobareos_decrypt_format- the image format after decryption, when thedisk_formatisLUKS. It should beraworgptos_decrypt_size- size after payload decryptionThe 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 manageros_decrypt_size- size after payload decryptionThe other ones are:
The
os_encrypt_key_deletion_policydefaults to FALSE, when I am reading the docs in the MR correct.The
os_decrypt_container_formatmay only be needed, when the container format is changed, e.g. forcompressed.The
os_decrypt_formatis only required for thedisk_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.
josephineSei commentedon Nov 8, 2024
I try to get more attention to all of this and added reviewers to the patches.
markus-hentsch commentedon Nov 11, 2024
I updated the Glance implementation patchset and addressed review comments by adding releases notes and unit test coverage for secret consumer exceptions.
markus-hentsch commentedon Nov 11, 2024
I started testing the changed architecture and ran into a failing
openstack image create --disk-format luksbecause now that we moved to introducing a newdisk_formatfor 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
josephineSei commentedon Nov 12, 2024
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.
markus-hentsch commentedon Nov 12, 2024
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=lukshas more repercussions in Cinder than I originally thought. Cinder makes extensive use ofqemu-imgfor format detection and conversion.However, they use an override to treat images received from Glance that
qemu-imgdetects as 'luks' as 'raw' instead because they expect those images to be originating from Cinder (former snapshots of LUKS volumes). The introduction ofdisk_format=luksnow 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 rawupload_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 datafetch_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 dataIn 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 convertcommand (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 avoidqemu-imgthinking 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-imgbehavior to treat the data as raw and simply copy it over.I adjusted the Cinder patchset to implement that.
markus-hentsch commentedon Nov 12, 2024
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.
markus-hentsch commentedon Nov 19, 2024
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 compressedneither forimage create --filenorimage create --volume. The use case for the image compression can only be triggered when interacting with the API directly, e.g., viacurl! 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:
Conclusion:
As
openstack image create --volumedoes 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 --filecannot 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.
Note that for binary image data upload, both
curl -X PUT --data-binaryandcurl -X PUT --upload-fileended 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_uploadwas disabled (which is the default), the volume will enter error state and cinder-volume will print the following log message:Compression enabled in Cinder
If
cinder.confcontains... 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-volConclusion:
The current patchset seems compatible with gzip-compressed images without issues.
markus-hentsch commentedon Nov 19, 2024
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.
josephineSei commentedon Nov 21, 2024
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.
josephineSei commentedon Nov 22, 2024
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.
josephineSei commentedon Nov 25, 2024
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.