Skip to content

LUKS volumes need configurable password and/or recovery keys #477

Open

Description

@jmpolom

See problems described in #476 and #421 for context.

The bootc install to-disk --block-setup tpm2-luks feature needs to provision either a systemd-cryptenroll recovery key or a default/backup password for the root LUKS volume. This is a necessity to ensure systems can be booted and users are not locked out when TPM PCR hashes change (they can and will change over time as the system is maintained).

Sometimes TPM PCR hashes change -- this is an expected and intended thing that happens on any system used over a period of time since they measure aspects of the system (which can change over time). Solely relying on the TPM to unlock root volumes is risky and exposes users to a lockout/non bootable situation without a recovery key or password. A bad and completely avoidable experience.

Activity

  1. added
    area/install
    on Apr 22, 2024
  2. added 2 commits that reference this issue on Nov 5, 2024
  3. andrewdunndev commented on Mar 22, 2026

    @andrewdunndev
    Contributor

    We spent time trying to fix this and #476 together. Here's what we found.

    The core problem

    bootc install to-disk --block-setup tpm2-luks runs systemd-cryptenroll --tpm2-device=auto inside a container. The TPM2 PCR values inside the container differ from the values at real boot. This means:

    1. TPM2 enrollment succeeds (binds to container's PCR values)
    2. cryptsetup luksOpen hangs because TPM2 unsealing fails (PCR mismatch) and falls back to interactive passphrase prompt (no terminal)
    3. The install never completes

    This is the same issue from #421. The --wipe-slot=all workaround just made luksOpen fail fast by removing all keyslots, but the installed system can't boot with TPM2 unlock either -- the enrolled PCR values are wrong.

    We verified this on GCP Shielded VMs with vTPM across multiple attempts. The luksOpen hang reproduces consistently inside podman run --privileged --pid=host. The same commands work fine on the host.

    What does work

    We validated that recovery key enrollment and configurable PCR selection work correctly during install:

    Enrolling recovery key
    > systemd-cryptenroll --recovery-key --unlock-key-file /tmp/.tmpFV9ELo /dev/sdb4
    vcrcgrcc-kjvhfeng-lbbdtgfb-vdfenivt-igcfdbiu-nrrvubjh-rrgbkbgd-eiutffvh
    New recovery key enrolled as key slot 1.
    
    Enrolling root device with TPM
    > systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7+14 --unlock-key-file /tmp/.tmpFV9ELo /dev/sdb4
    New TPM2 token enrolled as key slot 2.
    

    The LUKS header shows the right structure (3 keyslots: passphrase, recovery, TPM2 with PCR 7+14). The install just can't proceed past luksOpen.

    Proposed approach: two-stage enrollment

    Instead of trying to do TPM2 enrollment during install to-disk (which can't work due to PCR mismatch), split it into two stages:

    Stage 1 (during install): Create LUKS with a temporary passphrase + recovery key. No TPM2 enrollment. luksOpen uses the passphrase to continue the install. The system boots with passphrase unlock.

    Stage 2 (after first boot): A new command like bootc luks enroll-tpm2 runs on the real hardware where PCR values are correct. It enrolls TPM2, optionally wipes the temporary passphrase, and the system reboots with TPM2 auto-unlock.

    This matches the approach described by @jmpolom in the original issues -- install first, enroll after boot. It just formalizes it as a bootc command instead of manual systemd-cryptenroll invocation.

    The --tpm2-pcrs flag (#476) and recovery key (#477) would apply to the stage 2 command.

    We can build and test this

    We have a GCP-based test harness with Shielded VMs (vTPM), automated build-from-source, and guest-attribute-based result reporting. We validated the recovery key and PCR config changes across 12+ VM iterations. Happy to implement the two-stage approach and verify it end-to-end on this harness if the direction looks right.

    Test environment

    • GCP Shielded VM with vTPM (e2-standard-8)
    • Fedora 42 host, CentOS Stream 10 bootc image
    • bootc built from source with recovery key + PCR config changes
    • 12+ VM iterations testing different approaches
  4. andrewdunndev commented on Mar 24, 2026

    @andrewdunndev
    Contributor

    We previously commented here attributing the tpm2-luks install hang to TPM2 token behavior. After deeper investigation, we need to correct that analysis.

    Corrected root cause

    The hang at cryptsetup luksOpen during bootc install to-disk --block-setup tpm2-luks is caused by a libdevmapper udev cookie semaphore deadlock, not by the TPM2 token plugin.

    libdevmapper uses SysV semaphores to synchronize device-mapper operations with udevd. The container's default IPC namespace is isolated from the host, so udevd (on the host) can't see the semaphore. luksOpen blocks forever on semop().

    Kernel stack trace of the hanging cryptsetup process:

    [<0>] __do_semtimedop+0x3a8/0xd50
    [<0>] do_semtimedop+0x15e/0x1a0
    

    This affects ALL cryptsetup luksOpen calls inside bootc's execution context, regardless of whether TPM2 tokens are present. We confirmed this by testing with a passphrase-only LUKS volume (no tokens) -- same hang.

    Users who passed --ipc=host to podman would have bypassed this entirely, which may explain why some reports focused on TPM2/PCR issues without mentioning the install hang.

    Confirmation (3 tests, fresh VM each time)

    Condition Result
    Stock bootc, default podman flags HANG
    Stock bootc + DM_DISABLE_UDEV=1 PASS -- install completes
    Stock bootc + --ipc=host PASS -- install completes

    What DM_DISABLE_UDEV=1 does

    Tells libdevmapper to skip udev cookie semaphore synchronization for dm operations. The kernel still creates /dev/mapper/root via devtmpfs. What you lose is udev rules firing for dm events -- /dev/disk/by-uuid/ and /dev/disk/by-id/dm-uuid-* symlinks for the dm-crypt device are not created during install. bootc uses /dev/mapper/root directly and never references udev symlinks for the dm device, so this has no functional impact during installation. The installed system's boot-time behavior is unaffected -- the env var only exists in the install container's environment.

    Partition device nodes and udev_settle() for partition discovery are completely unaffected.

    Fix

    DM_DISABLE_UDEV=1 set in the Tpm2Luks code path in baseline.rs. Filed as #2089, PR at #2090.

    Note on #477 specifically

    The issues raised here (recovery keys, configurable passwords) are still valid and important for boot-time resilience. They are separate from the install-time hang. With the semaphore fix, the install completes, but the current code still wipes the temp passphrase (--wipe-slot=all) and sets headless=true, leaving no fallback if TPM2 unlock fails on first boot.

    Note on systemd 258

    Separately, systemd-cryptenroll changed its default --tpm2-pcrs from PCR 7 (systemd <=257) to no PCRs (systemd >=258, commit 4b840414). bootc calls systemd-cryptenroll --tpm2-device=auto without specifying --tpm2-pcrs, so the PCR binding depends on which systemd version is in the container image. This is worth tracking as the ecosystem moves to systemd 258+.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/install

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions