Skip to content

install to-disk with LUKS + TPM broken #421

Open

Description

@jmpolom

Does bootc install to-disk --block-setup tpm2-luks /dev/diskX actually work? I tried this in a qemu virtual machine with emulated TPM (via swtpm) and while it installed successfully, upon rebooting the VM into the freshly installed OS the systemd-cryptsetup units failed to decrypt the LUKS volume. Has this actually been tested or otherwise known to work? I will try on real hardware but this has me concerned this feature is not really in a functional state.

I tested with vanilla Fedora 39 Server to try and rule out this being related to the use of a virtual machine with emulated TPM. After installing tpm2-tools, adding the tpm2-tss dracut modules, and running systemd-cryptenroll for the LUKS volume I had an installation that repeatedly would unlock automatically via the TPM at boot (no password and no failures). Also tried with Fedora 39 Silverblue (added modules to initrd and enabled custom initramfs generation with rpm-ostree) -- same results. In both cases the LUKS volume was enrolled after the installed OS was provisioned and booted for the first time although I really doubt that has any effect on anything. I do not believe the test setup (IE: emulated TPM) is the problem here though.

Eventually dracut times out and drops into a rescue shell in the initrd. The cryptsetup unit faied with a Current policy digest does not match stored policy digest, cancelling TPM2 authentication attempt. error. Further, an error of No passphrase or recovery key registered is also printed. I don't think this is a PCR issue.

Some observations:

  • The latter of these issues (lack of failover way to unlock) is most certainly a bug in this install path. If the means for unlocking the LUKS volume will be the TPM, a recovery key must be set to allow the system to boot in the event PCRs change. Alternatively, allow the user to provide a normal password. One or both of these failover methods needs to be supported at install time (not after).
  • It is not clear from the documentation or CLI interface what PCRs the volume gets bound to in the TPM. The defaults should be documented and also user configurable. Right now based on reading the source, it looks like the LUKS volume binds to no PCR so it will always unlock as long as the TPM is present PCR 7, the systemd-cryptenroll default.

Activity

  1. changed the title [-]install to-disk with LUKS + TPM[/-] [+]install to-disk with LUKS + TPM broken[/+] on Mar 24, 2024
  2. jmpolom commented on Mar 24, 2024

    @jmpolom
    Author

    I am able to unlock the LUKS volume via TPM on a live system (FCOS) booted on the same VM I used to perform the bootc install to-disk --block-setup tpm2-luks from. It looks like the TPM2 binding on the volume is valid.

    I think my proposal is if it remains possible to install to a block device and into a LUKS volume, a user supplied password ought to be an option (it appears this would be a straightforward modification). The LUKS password can be changed or removed later on once the system is installed. If a user opts in to foregoing a password by not specifying one, then you would get the current behavior with no means of recovery. This would necessitate dropping the headless karg which should not be default either as it could severely hinder developmental debugging. Perhaps a second improvement would be to support a recovery key method but I see that as completely secondary to supporting a means to setup the volume with a plain ol password.

  3. added
    area/install
    triaged
    on Mar 25, 2024
  4. jmpolom commented on Mar 25, 2024

    @jmpolom
    Author

    Looks like this was observed with bootc 0.1.7 on an image created from the treefile configuration at this point that resulted in this container image

  5. cgwalters commented on Mar 25, 2024

    @cgwalters
    Member

    Thanks for filing this, indeed we have a CI gap on this here.

    (The integration of bootc install needs to be at least partly owned by the particular OS you're using; we will try to be generic where we can of course).

  6. jmpolom commented on Mar 25, 2024

    @jmpolom
    Author

    There needs to be a failover way to unlock any LUKS volumes bound to tokens at install time. Right now bootc actually creates a temp password and then discards it. At a very basic level this could just be output to the console as a very crude method to provide a way in if the TPM method isn't working. This is a basic issue with the to-disk install path. There really should be some user configurable options though.

    Unless the thought is bootc will only handle the bottom half of the logic (installing to a pre-made filesystem) and to-disk install path gets removed??

    The integration of bootc install needs to be at least partly owned by the particular OS you're using

    This was tested with Fedora 39 which has plenty of ostree based releases so I don't think that is necessarily the issue. Are there specific additional integrations needed (link to docs please)?

    Based on my detailed and exhaustive review of the existing state of the art (IE: everything here), I'm really coming up short for why this specific configuration isn't working. Looking at how the LUKS configuration is passed to the initrd via kargs and my double checking that the necessary libs are present in the initrd, the failure to unlock really doesn't make sense.

    Are any modifications beyond adding a few dracut modules needed to support TPM2 based unlocking with systemd-cryptsetup in the initrd? This is about what I'd expect to need to do to preconfigure an initrd with the proper libs. I've done this before on Debian and prior versions of Fedora successfully.

    Hazard a guess at what else should be checked here?

  7. cgwalters commented on Mar 25, 2024

    @cgwalters
    Member

    There needs to be a failover way to unlock any LUKS volumes bound to tokens at install time.

    For some use cases, all data on disk is effectively a cache, and having a failover adds risk and management overhead - questions around how is the failover secret rotated, etc.

    Unless the thought is bootc will only handle the bottom half of the logic (installing to a pre-made filesystem) and to-disk install path gets removed??

    There is some strong inherent tension here but the overall thought on the design is that to-disk is designed for the simple cases (obviously, "plain filesystem" is very simple), and the current tpm2-luks is arguably on the bounds of "simple" - and you can use to-filesystem to set things up however you want for all the other cases.

  8. jmpolom commented on Mar 26, 2024

    @jmpolom
    Author

    There needs to be a failover way to unlock any LUKS volumes bound to tokens at install time.

    For some use cases, all data on disk is effectively a cache, and having a failover adds risk and management overhead - questions around how is the failover secret rotated, etc.

    Valid concern for that specific case but that has got to be one hell of an edge case. Even if that is a main use case it creates a situation that is so unnecessarily difficult to debug that there needs to be an alternative to enable basic development. Such behavior that discards/skips/doesn't support a manual failover mechanism needs to be explicitly opted into by the user. Or the silly default must have an opt out. Right now it is forced opt in which is a problem.

    and the current tpm2-luks is arguably on the bounds of "simple"

    I'd encourage you to review all the logic in the supporting libraries and systemd itself for this to work. It is anything but simple and it increases the dependency footprint substantially (proper libs need to end up in the initrd, for instance). Far more complex than a password.

  9. jmpolom commented on Mar 26, 2024

    @jmpolom
    Author

    Tried to bootc install to-disk --block-setup tpm2-luks with the latest centos-bootc fedora-eln image (sha256: 174fb00e242e7aaa2d9c5f34056caea7fd726433949c0dedd12158aa5e6b1d0f) and it fails to unlock the root volume upon reboot. Failed systemd-cryptsetup unit trying to unlock via TPM2.

    I tried the build from last week previously, and it successfully unlocked the LUKS root volume on reboot (sha256:1c5e91ab395665ca11e2c1a17df18beec39d63fd2948f15add9fd95e45c0c85b). Clearly there have been some package changes in the past few days that broke this??

    While waiting for this update, I also tried both F39 and F40/next based builds with the latest bootc from the copr. Same story with those -- failed systemd-cryptsetup units trying to unlock via TPM.

  10. cgwalters commented on Mar 26, 2024

    @cgwalters
    Member

    Thanks Jon, this is very valid feedback and thanks for looking at this.

    Valid concern for that specific case but that has got to be one hell of an edge case.

    For example in cloud environments I may want to enable LUKS to be very sure my data is encrypted, and binding to the virtualized TPM2 is a generic baseline for that that at least helps ensure that if e.g. someone gets access somehow to an underlying block store they can't read the data. I am sure some people want a fallback password even in cloud, but it's not very "cloud native" to log in interactively on a console in an IaaS.

    Even if that is a main use case it creates a situation that is so unnecessarily difficult to debug that there needs to be an alternative to enable basic development. Such behavior that discards/skips/doesn't support a manual failover mechanism needs to be explicitly opted into by the user.

    Yes, fair enough.

    OK so I think what my inclination here is to make tpm2-luks require a flag in the install config in the container image. This way, the OS container image creator must opt-in to saying they support it (e.g. they have the required components in the initramfs, etc.)

    Then in parallel of course, we should:

    • Make this work
    • Expand on doing things like this via bootc install to-filesystem to be clear that arbitrarily complex storage setups can be owned by codebases other than bootc
  11. jmpolom commented on Mar 26, 2024

    @jmpolom
    Author

    For example in cloud environments I may want to enable LUKS to be very sure my data is encrypted, and binding to the virtualized TPM2 is a generic baseline for that that at least helps ensure that if e.g. someone gets access somehow to an underlying block store they can't read the data. I am sure some people want a fallback password even in cloud, but it's not very "cloud native" to log in interactively on a console in an IaaS.

    A great use for the recovery key option. If bootc could cleanly output the recovery key a secondary process could store it in a secrets vault. You really cannot have a TPM2 only binding. Even systems like Windows will provide recovery keys for when the PCRs change (as they are designed to do). Some deployments will want to bind to a lot more than PCR 7 and some of those PCRs may change even on OS update.

    OK so I think what my inclination here is to make tpm2-luks require a flag in the install config in the container image. This way, the OS container image creator must opt-in to saying they support it (e.g. they have the required components in the initramfs, etc.)

    There would also need to be a flag that could either have the system create and provide at install time a temp password or enroll a recovery key. Ideally both should be supported (recovery keys are lengthy and would be particularly obnoxious to deal with for repetitive early stage testing) at the user or image builders discretion.

    Specifically as to the initramfs components, the requirements need to be documented somewhere. Just having other works (like the centos-bootc) to reference isn't a great experience. It isn't entirely straightforward exactly what dracut modules should be added in. It's a bit different configuring the initramfs here because the image is being composed off board from the system it will run on, so any auto detection of things isn't going to work.

    Expand on doing things like this via bootc install to-filesystem to be clear that arbitrarily complex storage setups can be owned by codebases other than bootc

    Personally I would perhaps consider just removing the to-disk workflow. I'm not sure what value it brings if it can only handle trivially simple deployments. Is the juice from the added complexity actually worth it? I think it might be hard to avoid feature/complexity creep on what looks like a bare metal installer feature.

    Might be easier to just document a bit better how to use to-filesystem with an external workflow to prepare the disks and have a reference shell script that can be included in an image build to do this. Something to think about.

  12. cgwalters commented on Mar 26, 2024

    @cgwalters
    Member

    #445 will effectively turn this off by default for now.

    Personally I would perhaps consider just removing the to-disk workflow.

    I find it extremely useful as it provides a generic baseline, allowing a container image to self-install onto a block device without any other externally versioned infrastructure. (It also tries hard to force configuration to come from the container image by default).

    Now, I did also file #440 which would make it much easier for containers to configure things in arbitrary ways.

  13. jmpolom commented on Mar 27, 2024

    @jmpolom
    Author

    Looks like between tags eln-1710868505 and eln-1711401621 the fedora-bootc image began exhibiting the same failures with the systemd-cryptsetup units on boot after install. Any ideas what changes may have caused this? I saw the same issue with a pretty plain F39 based image.

  14. 6 remaining items

  15. cgwalters commented on Apr 18, 2024

    @cgwalters
    Member

    I also don't think they intend for their default PCR selection to be a "production ready" "universal" configuration everyone should run. It's a default because they needed one and it is relatively unoffensive,

    "relatively unoffensive" is definitely a hinge point here.

    but as I have shown here, not always workable. Only binding a LUKS volume to TPM 7 affords little in the way of actual security since a lot can change before that PCR hash changes.

    Yes. I had thought PCR7 wouldn't be a problem but basically it doesn't provide much value, and only causes problems in practice.

    There is scant documentation on how one might employ installing to filesystem with a LUKS root volume.

    Yes, we will work to improve the to-filesystem examples. However, part of the bigger picture here is that bootc is also intended to be a lower level backend for higher level existing distribution installers. For example, Anaconda today can install bootc-compatible containers via the ostreecontainer verb, and has a rich array of partitioning support, including LUKS (but as you know, not via systemd-cryptenroll). Anaconda doesn't technically use bootc install to-filesystem though, yet.

  16. jmpolom commented on Apr 18, 2024

    @jmpolom
    Author

    I had thought PCR7 wouldn't be a problem but basically it doesn't provide much value, and only causes problems in practice.

    There is systemd-pcrlock coming that appears to address some of the inherent issues when binding to plain PCRs. Ultimately any type of policy driven thing would need to be user configurable as well.

    I've created issues for the enhancements install to-disk needs in #476 and #477.

  17. andrewdunndev commented on Mar 24, 2026

    @andrewdunndev
    Contributor

    The hang described in this issue has been identified. It is a libdevmapper udev cookie semaphore deadlock in the container's IPC namespace, not a TPM2/PCR issue. See #2089 for the full analysis and fix (#2090).

    Users who passed --ipc=host to podman (or equivalent namespace sharing) would have bypassed this deadlock and gone straight to the TPM2/PCR issues discussed here. The PCR 7 / shim version mismatch is a separate, real issue that affects boot-time TPM2 unlock (not the install-time hang). That concern is tracked in #561.

  18. cgwalters commented on Mar 25, 2026

    @cgwalters
    Member

    In general, but especially in cases where there's skew between the host installation environment and target we really need to move the LUKS setup to first boot.

    This is already done by e.g. Ignition.

    Now this is a complex topic because there's also two fundamentally different cases: in a case where one is targeting a bare metal machine that one wants to "prepare" at a factory, we really do want to do encryption before the device gets deployed, in a distinct way any dynamic environment first boot configuration.

    Whereas in cloud, it's often maximally convenient to have a generic disk image and choose dynamically on boot whether to full disk encrypt or not - as is done by e.g. Ignition today.

    Now, there is a kind of sub-thread here in that the "dual partition os in /usr create / dynamically" naturally supports creating an encrypted / and the rootfs at the same time...but the storage model for bootc is to have an object store in / - which can itself be encrypted as a whole (including the operating system content, which some people really want).

    What I'm looking at here now is to change our default partitioning with to-disk so that we reserve enough space for a LUKS header to be inserted dynamically on boot. This would allow a flow like Ignition's to be maximally efficient in the case where we don't want to dynamically rewrite the filesystem type (which is relatively common).

    It's not just LUKS of course - based on some research here I think the "reserve a bit of space" will work for supporting dynamically converting to LVM for example.


    OK after some more research this is very similar to systemd/systemd#29731

  19. andrewdunndev commented on Mar 25, 2026

    @andrewdunndev
    Contributor

    Thanks for the detailed thinking here. The first-boot encryption direction makes a lot of sense -- it sidesteps both the IPC namespace deadlock (#2089) and the shim/PCR mismatch problem in one move, since TPM2 binding happens on real hardware with real firmware state.

    I've been looking at the openSUSE disk-encryption-tool which does exactly this today: runs cryptsetup reencrypt --encrypt --reduce-device-size=32m in the initrd before mounting rootfs. It's ~300 lines of bash, handles btrfs/swap/ext4, is idempotent, and handles interrupted encryption (cryptsetup's reencrypt journal makes it resumable). It's been shipping in production.

    I see two approaches for bootc:

    Option A: Reserve space at install time (your preference)

    • install to-disk creates the root FS 32MB smaller than the partition
    • First-boot initrd service calls cryptsetup reencrypt --encrypt --reduce-device-size=32m
    • No FS shrink needed, no data movement beyond the in-place encryption
    • Fastest first-boot path

    Option B: Full-size FS + shrink on first boot (openSUSE approach)

    • install to-disk creates a normal full-size root partition
    • First-boot service shrinks FS by 32MB, encrypts, grows back
    • More portable (works regardless of how the image was built)
    • Adds 30-60s latency from the shrink/grow cycle

    I'd lean toward Option A since you've been clear about avoiding unnecessary first-boot latency. The 32MB gap at the end of the partition is negligible.

    For the signaling mechanism (how the initrd knows to encrypt), I was thinking a kernel command line argument set during install (e.g. bootc.luks.encrypt=tpm2) that the first-boot service checks and removes after encryption completes. Similar to how Ignition signals first-boot provisioning.

    I'm happy to prototype this and put up a PR. Would you want this as a modification to the existing tpm2-luks block setup, or as a new variant? And any preference on the initrd integration -- dracut module, systemd generator, or something else?

    (I'll also update #2090 per your review feedback -- move the env var to global_init() and note --ipc=host as the recommended container invocation fix. That can serve as the short-term fix while first-boot LUKS develops.)

  20. andrewdunndev commented on Jul 10, 2026

    @andrewdunndev
    Contributor

    Following up my March comment with fabrication-workflow receipts, since this failure mode is what a CI-built image hits every time. I built an install to-disk --block-setup tpm2-luks disk on one machine (Fedora 44, systemd 259.7, bootc 1.16.3) and examined the enrollment:

    • A single keyslot (the TPM2 enrollment); no recovery passphrase. cryptsetup luksDump shows only keyslot 1 and token 0 (systemd-tpm2, tpm2-hash-pcrs: empty, tpm2-pubkey: (null), tpm2-pcrlock: false).

    • The exported token records no PCR binding at all, consistent with the post-v258 systemd default (cryptenroll/repart/creds: no longer default to binding against litera… systemd/systemd#36200); abridged:

      {
        "type": "systemd-tpm2",
        "keyslots": ["1"],
        "tpm2-pcrs": [],
        "tpm2-primary-alg": "ecc",
        "tpm2-policy-hash": "0000000000000000000000000000000000000000000000000000000000000000"
      }

      So the unlock condition is possession of the build machine's TPM, in any boot state.

    • There is no fallback: the TPM2 enrollment is the only keyslot, so possession of the build machine's TPM is the only unlock path. A disk image fabricated on one machine and deployed to another has nothing that can unlock it.

    If a short install-host caveat near the --block-setup tpm2-luks mention in the install docs would be useful, I'm happy to send it as a one-paragraph MR. The first-boot enrollment direction from the earlier discussion is the shape we're building on the image side.

  21. jmpolom commented on Jul 10, 2026

    @jmpolom
    Author

    ...shouldn't this be expected behavior and exactly the point of binding unlock to a TPM at all? The old pop the disk out and throw it another device should explicitly not work at all, regardless of bound PCRs. PCR binding is meant to detect tampering/"side loading" kind of issues. I'd imagine this is likely due to the fact that whatever next device this gets deployed to completely lacks the key at all in its TPM because it never was loaded. I could be off my rocker but the description above reads like entirely expected behavior in this instance. Also I am not sure what the use case is for deploying an already LUKS encrypted disk image to (multiple?) systems. They'd all have the same LUKS key. Seems like a security issue.

  22. andrewdunndev commented on Jul 10, 2026

    @andrewdunndev
    Contributor

    Apologies for the framing there: a disk that only unlocks on the machine that enrolled it is TPM sealing working as intended, not a failure mode, and agreed that deploying a pre-encrypted image to multiple systems has no good use case (shared volume key). On the tamper side, the receipt is really about the legitimate workflow rather than the CI one: when enrollment runs on the machine that keeps the disk, the current default binds no PCRs (empty mask, zeroed policy hash in the token dump above), so the TPM unseals in any boot state and the protection is limited to the disk being separated from its machine; a tampered boot chain on the same machine still auto-unlocks. That plus the single keyslot with no recovery path is what the docs caveat I offered would cover.

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/installarea/osintegrationtriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions