r/archlinux • • 25d ago

SUPPORT Setup for unlocking LUKS with TPM

I know auto unlocking of LUKS based FDE with the TPM is a decisive, lets ignore the dislike and just focus on making it as secure as possible. In particular I want to prevent

https://wiki.archlinux.org/title/Systemd-cryptenroll#Trusted_Platform_Module:

Only binding to PCRs measured pre-boot (PCRs 0-7) opens a vulnerability from rogue operating systems. A rogue partition with metadata copied from the real root filesystem (such as partition UUID) can mimic the original partition. Then, initramfs will attempt to mount the rogue partition as the root filesystem (decryption failure will fall back to password entry), leaving pre-boot PCRs unchanged. The rogue root filesystem with files controlled by an attacker is still able to receive the decryption key for the real root partition. See Brave New Trusted Boot World and BitLocker documentation for additional information.

Using PCR policies seems like the right approach: https://wiki.archlinux.org/title/Trusted_Platform_Module#PCR_policies bu the recommendations seem like a moving target and the discussion page is not reassuring. Is the following a "correct" way to go about TPM based unlocking with a UKI?

/etc/kernel/uki.conf

[UKI]
SecureBootSigningTool=systemd-sbsign
SignKernel=false
SecureBootPrivateKey=
/etc/kernel/secure-boot-private-key.pem
SecureBootCertificate=
/etc/kernel/secure-boot-certificate.pem
PCRPKey=/etc/systemd/tpm2-pcr-public-key-initrd.pem
Splash=/usr/share/systemd/bootctl/splash-arch.bmp
SignInitrdPCRs=yes

[PCRSignature:initrd]
Phases=enter-initrd
PCRPrivateKey=/etc/systemd/tpm2-pcr-private-key-initrd.pem
PCRPublicKey=/etc/systemd/tpm2-pcr-public-key-initrd.pem/etc/kernel/uki.conf

# systemd-cryptenroll --wipe-slot=tpm2 --tpm2-device=auto --tpm2-public-key-policyref=initrd \
                      --tpm2-public-key=/etc/systemd/tpm2-pcr-public-key-initrd.pem \
                      /dev/disk/by-designator/root-luks
1 Upvotes

9 comments sorted by

1

u/archover 25d ago edited 25d ago

I use physical control and a non trivial LUKS passphrase for years, and feel it's not an inconvenience and I'm protected. I am however, thinking about Secure Boot. Laptop used outside the house a lot.

Hope you get some ideas here, and good day.

0

u/AppointmentNearby161 25d ago

This is an air gapped server that requires unattended reboots so I think the TPM is the only way.

1

u/archover 25d ago

I see. A server in your house? Good info you added. Good day.

0

u/AppointmentNearby161 25d ago

This is work infrastructure. While I would rather use Debian, Arch was much easier for maintaining airgapped machines 15 years ago (e.g., custom packaging and local repos on a USB stick). Debian documentation, along with my skills, have improved enough that if I had to start over, I would go with Debian.

2

u/Toaster_Strudel_517 25d ago

I'm using both pcr7+15 and pubkey.

2

u/Vannoway 25d ago

This is what I use:

systemd-cryptenroll \
  --tpm2-device=auto \
  --tpm2-pcrs=7+15:sha256=0000000000000000000000000000000000000000000000000000000000000000 \
  --tpm2-public-key=/etc/systemd/tpm2-pcr-public-key-initrd.pem \
  --tpm2-public-key-policyref=initrd \
  --tpm2-with-pin=yes \
  /dev/disk/by-partlabel/ROOT

/etc/kernel/uki.conf:

[UKI]
PCRBanks=sha256
PCRPKey=/etc/systemd/tpm2-pcr-public-key-initrd.pem
SignInitrdPCRs=yes

[PCRSignature:initrd]
Phases=enter-initrd
PCRPrivateKey=/etc/systemd/tpm2-pcr-private-key-initrd.pem
PCRPublicKey=/etc/systemd/tpm2-pcr-public-key-initrd.pem

/etc/crypttab (the tpm2-measure-pcr=yes is what puts the volume key into PCR 15):

cryptroot UUID=<partition UUID> none discard,x-initrd.attach,tpm2-device=auto,tpm2-measure-pcr=yes

You can pin the volume key hash, so the initrd refuses any volume with a different key. After the first boot with the TPM unlock working:

grep volume-key /run/log/systemd/tpm2-measure.log | grep -o -E '[0-9a-f]{64}'

Add fixate-volume-key=<that hash> to the options in the crypttab line above, then:

mkinitcpio -P
sbctl sign-all
systemctl reboot

If you typo the hash the root volume won't attach, so keep a live USB around. Also, this only works with Secure Boot on, since PCR 7 is in the policy.

2

u/Synthetic451 25d ago

I prefer using two separate keys for the different phases but using --tpm2-public-key-policyref is fine as long as systemd is newer than 262. Here's what I use

[UKI]
PCRPKey=/etc/systemd/tpm2-pcr-public-key-initrd.pem
SignInitrdPCRs=yes

[PCRSignature:initrd]
Phases=enter-initrd
PCRPrivateKey=/etc/systemd/tpm2-pcr-private-key-initrd.pem
PCRPublicKey=/etc/systemd/tpm2-pcr-public-key-initrd.pem

[PCRSignature:system]
Phases=enter-initrd:leave-initrd
       enter-initrd:leave-initrd:sysinit
       enter-initrd:leave-initrd:sysinit:ready
PCRPrivateKey=/etc/systemd/tpm2-pcr-private-key-system.pem
PCRPublicKey=/etc/systemd/tpm2-pcr-public-key-system.pem

Then I enroll using this

sudo systemd-cryptenroll /dev/<device partition> \
    --wipe-slot=tpm2 \
    --tpm2-device=auto \
    --tpm2-pcrs=7 \
    --tpm2-public-key=/etc/systemd/tpm2-pcr-public-key-initrd.pem

You should still bind to PCR 7 so that Secure Boot being disabled will immediately prevent TPM from releasing the secrets.

EDIT: I should mention that I use sbctl to sign instead of sbsign, so adjust accordingly.

0

u/bozehaan 25d ago

Why not lock the bios, set the internal drive as only allowed boot disk, require password for different drives. If you're really paranoid about physical access, there's tamper protection stickers you can put over the screws

1

u/gmes78 25d ago

That is orthogonal to encryption with TPM.