Skip to contentSkip to conversation

reencryption with multi keyslots in batch mode

DISCUSSION Frederic Hoerni 2 participants 3 messages Jun 3 – Dec 3

lore
Share & tools
lore
#0 lore raw

Hello,

If we want to reencrypt a disk that has several keyslots (main and recovery keyslots), I believe the only way is to do it in interactive mode.

But in some cases, we would like to do this in batch mode. We could imagine a scenario like this:

1. Setup of the use case (no modification of cryptsetup needed so far)

# Initialize LUKS container
dd if=/dev/zero count=200 of=disk.img bs=1M

echo 0000 | sudo cryptsetup luksFormat --keyfile-size 4 \
                                       --key-file - \
                                       disk.img
# Add two keyslots
echo -n 0000x111111 | cryptsetup luksAddKey --key-file - \
                                            --keyfile-size 4 \
                                            disk.img
echo -n 0000222     | cryptsetup luksAddKey --key-file - \
                                            --keyfile-size 4 \
                                            disk.img

2. Reencryption (this step needs modification of cryptsetup)

echo -n 0000x111111222 | \
    sudo cryptsetup reencrypt --key-file - \
                              --keypipe-sizes "4,7,3" \
                              --batch-mode \
                              --force-offline-reencrypt \
                              disk.img

3. Verify all keyslots

for passphrase in 0000 x111111 222; do

    echo -n $passphrase | cryptsetup open disk.img --test-passphrase \
                                                   --key-file -

done

Do you have any on-going work in this direction?
Are you open to contribution for that? (I already have a proof of concept for the above scenario) Do you have any particular caveat about developing this feature?

Thank you
Frederic

#1 lore raw

Hi,

Quoted 4 lines · Frederic Hoerni

Hello,

If we want to reencrypt a disk that has several keyslots (main and recovery keyslots), I believe the only way is to do it in interactive mode.

Correct.

Quoted 29 lines

But in some cases, we would like to do this in batch mode. We could imagine a scenario like this:

1. Setup of the use case (no modification of cryptsetup needed so far)

# Initialize LUKS container
dd if=/dev/zero count=200 of=disk.img bs=1M

echo 0000 | sudo cryptsetup luksFormat --keyfile-size 4 \
                                         --key-file - \
                                         disk.img
# Add two keyslots
echo -n 0000x111111 | cryptsetup luksAddKey --key-file - \
                                              --keyfile-size 4 \
                                              disk.img
echo -n 0000222     | cryptsetup luksAddKey --key-file - \
                                              --keyfile-size 4 \
                                              disk.img

2. Reencryption (this step needs modification of cryptsetup)

echo -n 0000x111111222 | \
      sudo cryptsetup reencrypt --key-file - \
                                --keypipe-sizes "4,7,3" \
                                --batch-mode \
                                --force-offline-reencrypt \
                                disk.img
Quoted 8 lines

3. Verify all keyslots

for passphrase in 0000 x111111 222; do

      echo -n $passphrase | cryptsetup open disk.img --test-passphrase \
                                                     --key-file -

done

Do you have any on-going work in this direction?

No, currently I do not have any plans.

Quoted 2 lines

Are you open to contribution for that? (I already have a proof of concept for the above scenario)

Of course! As with any other open source project feel free to contribute via a merge request in https://gitlab.com/cryptsetup/cryptsetup

Quoted 1 line

Do you have any particular caveat about developing this feature?

Me personally, I'd probably go with dropping the additional keyslots for the time of reencryption. The reencryption performance is more or less dependent on a free space in LUKS2 header keyslots area. The only exception from this rule is reencryption with datashift (reencrypt --encrypt --reduce-device-size XXX command for example).

And you can recreate additional (or recovery?) keyslots after the reencryption operation is completed.

With kind regards
O. Kozina

#2 lore raw

Hi,

I'm answering on the mailing list to Ondrej's comment on my merge request:
https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests/958#note_4366192260
as the format might be more suitable here.

Quoted 6 lines · Ondrej

Wouldn't it be easier to run the reencryption against a single LUKS2 keyslot — cryptsetup reencrypt -S <specific_keyslot_id> /dev/device — and re-create the additional keyslots once the operation has finished? Is there a particular use case I'm missing that genuinely requires multiple LUKS2 keyslots to stay active for the duration of the reencryption?

There are some use cases where re-creating keyslots after re-encryption can be an issue.

Use case 1: Volumes with keyslots held by different parties, typically the user's own passphrase, and a recovery key held by an organization's escrow. If re-encryption needs to drop the organization's recovery key first, then the process of adding it back after re-encryption can add extra work for the user, and a gap in availability.

Use case 2: Unattended re-encryption on remote servers, with a passphrase sealed with a TPM and a recovery key. If the TPM-backed keyslot is dropped before re-encryption, any power outage during that time would require human attendance and would cause unavailability.

We would like to support these use cases in Ubuntu, where we have a middleware that calls cryptsetup, and the user in not directly using cryptsetup.

Quoted 3 lines

[...] we can discuss a different approach — most likely built around a repeatable --key-file option, which is already supported (in tcrypt type).

I agree that my initial patch might not be very elegant and we can do better. I'll be happy to rework the patch and follow your directions.

I'm also thinking of another way to achieve the same feature with possibly less modifications and that would benefit to more than just
re-encryption: add a kind of --key-encoding base64|hex option, where the keys are provided in base64 (or hex) and cryptsetup would unwrap them to the binary value. This would work well with newline-separated passphrases, which are already well supported.

Kind regards,
Frederic