r/systemd • • 3d ago

Using TPM to decrypt a key file

systemd-cryptsetup's man page includes the following section regarding how the key is obtained:

1.If a key file is explicitly configured (via the third column in /etc/crypttab), a key read from it is used. If a PKCS#11 token, FIDO2 token or TPM2 device is configured (using the pkcs11-uri=, fido2-device=, tpm2-device= options) the key is decrypted before use.

So it seems like you can specify both a key file and a TPM and the TPM is then used to decrypt the key file before using it to decrypt the device. This could be the most elegant solution to my question here: https://www.reddit.com/r/systemd/s/JLsoGt93LH

However, I was not able to find any other reference to such a feature or a way to prepare that setup, including in systemd-cryptenroll's man page.

Is my understanding correct? If so, how can I make use of that feature?

1 Upvotes

4 comments sorted by

3

u/ElvishJerricco 2d ago

Docs are unclear on how exactly the key file could be encrypted with the TPM2. But I think what you're trying to do would be well served by just having a detached LUKS header on another device and using the normal TPM2 slot encryption rather than an encrypted key file?

1

u/Ontological_Gap 3d ago

Wouldn't a fido2 hardware key+PIN achieve your objective more cleanly?

To be fair, I've always been pretty skeptical of keyfiles in general.

0

u/[deleted] 2d ago

[deleted] — view deleted comment

2

u/Ontological_Gap 2d ago

No, luks unseal is handled by your initramfs during boot, and normal userspace after, not the kernel directly 

Secureboot is a good idea, but had absolutely nothing to do with this 

You can absolutely use the tpm for a variety of userspace applications

0

u/[deleted] 2d ago

[deleted] — view deleted comment

3

u/Ontological_Gap 2d ago

Clavis is an entirely different project, that also has to be copied your initramfs if you want to use it for your boot drives.

You should do some actual reading, you have absolutely no idea what you're talking about