Chapter 4. Image encryption As a storage administrator, you can set a secret key that is used to encrypt a specific RBD image. Image level encryption is handled internally by RBD clients. Note The krbd module does not support image level encryption. Note You can use external tools such as dm-crypt or QEMU to encrypt an RBD image. Prerequisites A running Red Hat Ceph Storage 8 cluster. root level permissions. 4.1. Encryption format RBD images are not encrypted by default. You can encrypt an RBD image by formatting to one of the supported encryption formats. The format operation persists the encryption metadata to the RBD image. The encryption metadata includes information such as the encryption format and version, cipher algorithm and mode specifications, as well as the information used to secure the encryption key. The encryption key is protected by a user kept secret that is a passphrase, which is never stored as persistent data in the RBD image. The encryption format operation requires you to specify the encryption format, cipher algorithm, and mode specification as well as a passphrase. The encryption metadata is stored in the RBD image, currently as an encryption header that is written at the start of the raw image. This means that the effective image size of the encrypted image would be lower than the raw image size. Note Unless explicitly (re-)formatted, clones of an encrypted image are inherently encrypted using the same format and secret. Note Any data written to the RBD image before formatting might become unreadable, even though it might still occupy storage resources. RBD images with the journal feature enabled cannot be encrypted. 4.2. Encryption load By default, all RBD APIs treat encrypted RBD images the same way as unencrypted RBD images. You can read or write raw data anywhere in the image. Writing raw data into the image might risk the integrity of the encryption format. For example, the raw data could override the encryption metadata located at the beginning of the image. To safely perform encrypted Input/Output(I/O) or maintenance operations on the encrypted RBD image, an additional encryption load operation must be applied immediately after opening the image. The encryption load operation requires you to specify the encryption format and a passphrase for unlocking the encryption key for the image itself and each of its explicitly formatted ancestor images. All I/Os for the opened RBD image are encrypted or decrypted, for a cloned RBD image, this includes IOs for the parent images. The encryption key is stored in memory by the RBD client until the image is closed. Note Once the encryption is loaded on the RBD image, no other encryption load or format operation can be applied. Additionally, API calls for retrieving the RBD image size and the parent overlap using the opened image context returns the effective image size and the effective parent overlap respectively. The encryption is loaded automatically when mapping the RBD images as block devices through rbd-nbd . Note API calls for retrieving the image size and the parent overlap using the opened image context returns the effective image size and the effective parent overlap. Note If a clone of an encrypted image is explicitly formatted, flattening or shrinking of the cloned image ceases to be transparent since the parent data must be re-encrypted according to the cloned image format as it is copied from the parent snapshot. If encryption is not loaded before the flatten operation is issued, any parent data that was previously accessible in the cloned image might become unreadable. Note If a clone of an encrypted image is explicitly formatted, the operation of shrinking the cloned image ceases to be transparent. This is because, in scenarios such as the cloned image containing snapshots or the cloned image being shrunk to a size that is not aligned with the object size, the action of copying some data from the parent snapshot, similar to flattening is involved. If encryption is not loaded before the shrink operation is issued, any parent data that was previously accessible in the cloned image might become unreadable. 4.3. Supported formats Both Linux Unified Key Setup (LUKS) 1 and 2 are supported. The data layout is fully compliant with the LUKS specification. External LUKS compatible tools such as dm-crypt or QEMU can safely perform encrypted Input/Output (I/O) on encrypted RBD images. Additionally, you can import existing LUKS images created by external tools, by copying the raw LUKS data into the RBD image. Currently, only Advanced Encryption Standards (AES) 128 and 256 encryption algorithms are supported. xts-plain64 is currently the only supported encryption mode. To use the LUKS format, format the RBD image with the following command: Note You need to create a file named passphrase.txt and enter a passphrase. You can randomly generate the passphrase, which might contain NULL characters. If the passphrase ends with a newline character, it is stripped off. Syntax Example Note You can select either luks1 or luks encryption format. The encryption format operation generates a LUKS header and writes it at the start of the RBD image. A single keyslot is appended to the header. The keyslot holds a randomly generated encryption key, and is protected by the passphrase read from the passphrase file. By default, AES-256 in xts-plain64 mode, which is the current recommended mode and the default for other LUKS tools, is used. Adding or removing additional passphrases is currently not supported natively, but can be achieved using LUKS tools such as cryptsetup . The LUKS header size can vary that is upto 136MiB in LUKS, but it is usually upto 16MiB, dependent on the version of libcryptsetup installed. For optimal performance, the encryption format sets the data offset to be aligned with the image object size. For example, expect a minimum overhead of 8MiB if using an image configured with an 8MiB object size. In LUKS1, sectors, which are the minimal encryption units, are fixed at 512 bytes. LUKS2 supports larger sectors, and for better performance, the default sector size is set to the maximum of 4KiB. Writes which are either smaller than a sector, or are not aligned to a sector start, trigger a guarded read-modify-write chain on the client, with a considerable latency penalty. A batch of such unaligned writes can lead to I/O races which further deteriorates performance. Red Hat recommends to avoid using RBD encryption in cases where incoming writes cannot be guaranteed to be LUKS sector aligned. To map a LUKS encrypted image, run the following command: Syntax Example Note You can select either luks1 or luks2 encryption format. Note For security reasons, both the encryption format and encryption load operations are CPU-intensive, and might take a few seconds to complete. For encrypted I/O, assuming AES-NI is enabled, a relatively small microseconds latency might be added, as well as a small increase in CPU utilization. 4.4. Adding encryption format to images and clones Layered-client-side encryption is supported. The cloned images can be encrypted with their own format and passphrase, potentially different from that of the parent image. Add encryption format to images and clones with the rbd encryption format command. Given a LUKS2-formatted image, you can create both a LUKS2-formatted clone and a LUKS1-formatted clone. Prerequisites A running Red Hat Ceph Storage cluster with Block Device (RBD) configured. Root-level access to the node. Procedure Create a LUKS2-formatted image: Syntax Example The rbd resize command grows the image to compensate for the overhead associated with the LUKS2 header. With the LUKS2-formatted image, create a LUKS2-formatted clone with the same effective size: Syntax Example With the LUKS2-formatted image, create a LUKS1-formatted clone with the same effective size: Syntax Example Since LUKS1 header is usually smaller than LUKS2 header, the rbd resize command at the end shrinks the cloned image to get rid of unwanted space allowance. With the LUKS-1-formatted image, create a LUKS2-formatted clone with the same effective size: Syntax Example Since LUKS2 header is usually bigger than LUKS1 header, the rbd resize command at the beginning temporarily grows the parent image to reserve some extra space in the parent snapshot and consequently the cloned image. This is necessary to make all parent data accessible in the cloned image. The rbd resize command at the end shrinks the parent image back to its original size and does not impact the parent snapshot and the cloned image to get rid of the unused reserved space The same applies to creating a formatted clone of an unformatted image, since an unformatted image does not have a header at all. Additional Resources See the Configuring Ansible inventory location section in the Red Hat Ceph Storage Installation Guide for more details on adding clients to the cephadm-ansible inventory.

Commands:
rbd encryption format POOL_NAME / LUKS_IMAGE luks1|luks2 PASSPHRASE_FILE
rbd encryption format pool1/luksimage1 luks1 passphrase.bin
rbd device map -t nbd -o encryption-format=luks1|luks2,encryption-passphrase-file=passphrase.txt POOL_NAME / LUKS_IMAGE
rbd device map -t nbd -o encryption-format=luks1,encryption-passphrase-file=passphrase.txt pool1/luksimage1
rbd create --size SIZE POOL_NAME / LUKS_IMAGE rbd encryption format POOL_NAME / LUKS_IMAGE luks1|luks2 PASSPHRASE_FILE rbd resize --size 50G --encryption-passphrase-file PASSPHRASE_FILE POOL_NAME / LUKS_IMAGE
rbd create --size 50G mypool/myimage rbd encryption format mypool/myimage luks2 passphrase.txt rbd resize --size 50G --encryption-passphrase-file passphrase.txt mypool/myimage
rbd snap create POOL_NAME / IMAGE_NAME @ SNAP_NAME rbd snap protect POOL_NAME / IMAGE_NAME @ SNAP_NAME rbd clone POOL_NAME / IMAGE_NAME @ SNAP_NAME POOL_NAME / CLONE_NAME rbd encryption format POOL_NAME / CLONE_NAME luks1 CLONE_PASSPHRASE_FILE
rbd snap create mypool/myimage@snap rbd snap protect mypool/myimage@snap rbd clone mypool/myimage@snap mypool/myclone rbd encryption format mypool/myclone luks1 clone-passphrase.bin
rbd snap create POOL_NAME / IMAGE_NAME @ SNAP_NAME rbd snap protect POOL_NAME / IMAGE_NAME @ SNAP_NAME rbd clone POOL_NAME / IMAGE_NAME @ SNAP_NAME POOL_NAME / CLONE_NAME rbd encryption format POOL_NAME / CLONE_NAME luks1 CLONE_PASSPHRASE_FILE rbd resize --size SIZE --allow-shrink --encryption-passphrase-file CLONE_PASSPHRASE_FILE --encryption-passphrase-file PASSPHRASE_FILE POOL_NAME / CLONE_NAME
rbd snap create mypool/myimage@snap rbd snap protect mypool/myimage@snap rbd clone mypool/myimage@snap mypool/myclone rbd encryption format mypool/myclone luks1 clone-passphrase.bin rbd resize --size 50G --allow-shrink --encryption-passphrase-file clone-passphrase.bin --encryption-passphrase-file passphrase.bin mypool/myclone
rbd resize --size SIZE POOL_NAME / LUKS_IMAGE rbd snap create POOL_NAME / IMAGE_NAME @ SNAP_NAME rbd snap protect POOL_NAME / IMAGE_NAME @ SNAP_NAME rbd clone POOL_NAME / IMAGE_NAME @ SNAP_NAME POOL_NAME / CLONE_NAME rbd encryption format POOL_NAME / CLONE_NAME luks2 CLONE_PASSPHRASE_FILE rbd resize --size SIZE --allow-shrink --encryption-passphrase-file PASSPHRASE_FILE POOL_NAME / LUKS_IMAGE rbd resize --size SIZE --allow-shrink --encryption-passphrase-file CLONE_PASSPHRASE_FILE --encryption-passphrase-file PASSPHRASE_FILE POOL_NAME_/ CLONE_NAME
rbd resize --size 51G mypool/myimage rbd snap create mypool/myimage@snap rbd snap protect mypool/myimage@snap rbd clone mypool/my-image@snap mypool/myclone rbd encryption format mypool/myclone luks2 clone-passphrase.bin rbd resize --size 50G --allow-shrink --encryption-passphrase-file passphrase.bin mypool/myimage rbd resize --size 50G --allow-shrink --encryption-passphrase-file clone-passphrase.bin --encryption-passphrase-file passphrase.bin mypool/myclone