#[SOLVED] no matter how many times I enroll the secure boot keys to TPM dracut asks for my password

276 messages · Page 1 of 1 (latest)

marble tartan
#

So I have an encrypted root volume on /dev/nvme0n1p2, and I have enrolled the decryption keys into the tpm with systemd-cryptenroll.
After regenerating the initramfs, Dracut still asks for the password for the rootfs

how can I get it to use the keys on the tpm
or did I enroll the keys wrong?

untold isleBOT
#

.aw luks

south whaleBOT
untold isleBOT
opaque marlin
untold isleBOT
#

ya

#
[sparky@katie ~]$ run0 lsinitrd | grep tpm2-tss
tpm2-tss
-rw-r--r--   1 root     root           89 Oct 20 22:26 usr/lib/sysusers.d/tpm2-tss.conf
-rw-r--r--   1 root     root          592 Oct 20 22:26 usr/lib/tmpfiles.d/tpm2-tss-fapi.conf
#

tried setting the crypttab.initramfs

#

lemme check if it will work

#

it did not

#

it still asks for the password to decrypt rooffs

#

rootfs

#

The TPM will automatically release the key as long as the boot chain is not tampered with.

opaque marlin
#

@marble tartan try to add systemd to your dracut modules

untold isleBOT
#

hmm idk if my chain is tampered
how do I check :3

#

it's there

OfficerK ↩️

[Reply to:](#1356209447134953712 message) @marble tartan try to add systemd to your dracut modules

opaque marlin
#

ah

untold isleBOT
#

what do I do now :3

opaque marlin
#

if I find smthg I tell u

untold isleBOT
#

would get myself a FIDO2 key
if they weren't as expensive as ₺3k

opaque marlin
#

😔

untold isleBOT
#

keeping the key in an USB, plugging it and then unplugging it is among the options

#

(I'm thinking aloud you might ignore me)

opaque marlin
#

@marble tartan there's this but

#

also was reading this

opaque marlin
untold isleBOT
#

it is not booted tho
it is between booted and not booted

opaque marlin
#

by specifying a different name? idk

untold isleBOT
#

when the initramfs requests the root volume key

opaque marlin
#

yeah I meant after you boot

#

to test it

#

using the command above

untold isleBOT
#

Cannot use device /dev/nvme0n1p2 which is in use (already mapped or mounted).

#

hmm

opaque marlin
untold isleBOT
#

i'll try a live usb

#

TPM2 operation failed, falling back to traditional unlocking: Device or resource busy

opaque marlin
untold isleBOT
#

ya

opaque marlin
#

I think if you specify a different name u might be able to test it even while booted?

#

im not sure

untold isleBOT
#

i tried

#

that did not work either

opaque marlin
#

ah

untold isleBOT
#

On live system this throws "operation not permitted" errors

#

Failed to unseal secret using TPM2: Operation not permitted

#

Found a bug report but that was marked as fixed

opaque marlin
untold isleBOT
#

:3

opaque marlin
#

actually the error is a bit different

#

idk

marble tartan
#

clearing the tpm would revoke the secure boot keys

marble tartan
deep emberBOT
#

0fficerk received a thank you cookie!

opaque marlin
marble tartan
#

it's alright

#

ig i just find a sd card to decrypt (I have no sd card slots)

opaque marlin
sacred hollow
#

the TPM usually binds to PCR 7, secure boot state, by default

untold isleBOT
#

elaborate

#

theyre bound to that

Fleuria ↩️

[Reply to:](#1356209447134953712 message) the TPM usually binds to PCR 7, secure boot state, by default

sacred hollow
#

did you change anything about your secure boot keys, or turned it on or off?

#

oh, wait

#

hang on

sacred hollow
untold isleBOT
#

i did

#

arch live iso

Fleuria ↩️

[Reply to:](#1356209447134953712 message) is this an Ubuntu live ISO?

sacred hollow
#

or otherwise any live ISO which provides secure boot support by default

#

oh, hm

#

oh, archlive

untold isleBOT
#

mhm

sacred hollow
#

did you sign it with your own keys, or did it just work?

untold isleBOT
#

it worked because of ventoy ig

sacred hollow
#

oh, and…

#

did you sign ventoy?

untold isleBOT
#

ya

sacred hollow
#

hm, interesting…

untold isleBOT
#

also enrolled the ventoy keys

sacred hollow
#

so, my hunch is that something in the boot process you used involved shim

#

because shim measures its own keys to PCR 7, and hence would make a shim-booted system not able to unlock your drive

#

something you can try here is to re-enroll the TPM2, but this time not binding to any PCR registers at all

#

if it works then it’s probably shim or something else modifying PCR 7

untold isleBOT
#

i dont see shim

#

if shim was somewhat enrolled it should have probably existed in the efibootmgr output

#

shouldnt it

sacred hollow
#

not necessarily

#

it’s a live usb right?

#

that uses the fallback boot path

#

I’m also talking specifically about the failure in the live environment, not with the main system

untold isleBOT
#

mhm

#

idk

sacred hollow
#

though as for the main system, my one question would be what kernel parameters you are using

untold isleBOT
#
~> cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-linux-cachyos root=UUID=d3a547f3-8f66-4507-abf9-519ff8c99fe7 rw rootflags=subvol=@ loglevel=3
sacred hollow
#

ah!

#

that’s what happened

#

it doesn’t know to use a TPM by default

#

you need to tell systemd-cryptsetup explicitly that a TPM is to be used

untold isleBOT
#

but crypttab.initramfs

sacred hollow
#

dracut does not include crypttab.initramfs

#

unless you specified it manually with the --include flag

untold isleBOT
#

mhm

#

on one side I am compiling stuff on a different machine so if I disappear I am probably fixing that machine

sacred hollow
#

anyway, you can bsdtar out the initramfs file you have

#

to see if there’s even a crypttab file in there

untold isleBOT
#

there is none

sacred hollow
#

as to be expected…

#

so, the quickest fix you can try to apply here

untold isleBOT
#

im including it

sacred hollow
#

okay

#

make sure it’s only named /etc/crypttab in the initramfs

#

the .initramfs thing is a mkinitcpio extension

untold isleBOT
#

aaa

#

how

sacred hollow
#

the --include flag allows you to rename the file to be included

untold isleBOT
#

i recall something like that from dracut(8)

sacred hollow
#

dracut is very weird in this regard because the --include flag can only be used once, for one file

#

everything else can only be added as the exact name and path they are in the main root

#

the other option is to forgo a crypttab

untold isleBOT
#

mhm

sacred hollow
#

since you’re already getting a password prompt in the first place systemd-gpt-auto-generator seems to be doing its job

#

so you can just add rd.luks.options=[LUKS block UUID]=tpm2-device=auto

#

the UUID there is for the LUKS block, not for the filesystem inside

untold isleBOT
#

the uuid for nvme0n1p2

sacred hollow
#

yea, that works

untold isleBOT
#

i set that

sacred hollow
#

then you can try it!

untold isleBOT
#

didnt work

#

BOOT_IMAGE=/vmlinuz-linux-cachyos root=UUID=d3a547f3-8f66-4507-abf9-519ff8c99fe7 rw rootflags=subvol=@ rd.luks.options=UUID=ff47b26b-0cd8-4510-b662-f04df75e9ba1=tpm2-device=auto loglevel=

#

loglevel is 3

sacred hollow
#

no need to add the UUID= there

untold isleBOT
#

mhm

sacred hollow
#

oh, wait

#

I didn’t realise you could just omit the UUID

#

I skimmed through the man page but the Arch Wiki says you can just not specify anything and it’ll apply to all devices

untold isleBOT
#

let's see

sacred hollow
#

If only a list of options, without a UUID, is specified, they apply to any UUIDs not specified elsewhere, and without an entry in /etc/crypttab.

#

if this doesn’t work then it should no longer be a configuration issue but a TPM issue

#

in which case my next suggestion would be to try and enroll a new key not bound to any PCR registers at all

sacred hollow
#

if it does work then something about PCR 7 on your motherboard might be borked, or it might have changed when you didn’t look

untold isleBOT
#

the tpm boots just fine tho

sacred hollow
#

I’m just laying out future hypotheticals

#

what matters right now is just the current step, which is to try again with the correct parameter

untold isleBOT
#

did not work

sacred hollow
#

did it say anything before dropping you into the password prompt?

#

like if it had anything about a TPM error

untold isleBOT
#

nope

sacred hollow
#

okay, well

#

as I said, if you still want to try and troubleshoot this, my next suggestion is to wipe the current TPM2 key slot, and replace it with one that isn’t bound to anything

#

for this, add --tpm2-pcrs='' when enrolling the new TPM slot

untold isleBOT
#
~> run0 systemd-cryptenroll --wipe-slot 2
Wiping requested and no block device node specified, refusing.
#

im stupid

#

i did it

#

the tpm slot was 2

sacred hollow
#

yup, you just forgot to specify the disk at the end

#

which is a mistake I still make too

untold isleBOT
#

ya wiped it

#

on one side I am compiling a window manager

#

so well I might be slow to respond

#

do I enroll again now

Fleuria ↩️

[Reply to:](#1356209447134953712 message) for this, add --tpm2-pcrs='' when enrolling the new TPM slot

sacred hollow
#

yea!

#

you can then try and open it in a live USB again

#

if it works then you could try booting the main system

#

since it’s not bound to anything it should really just work this time

#

if it doesn’t then this is a Cursed Hardware Issue that is beyond my capacity to help

deep emberBOT
#

fleuriafluoride received a thank you cookie!

untold isleBOT
#

thank you so much @sacred hollow

sacred hollow
#

of course!

#

you can tell me how it goes once you try unlocking it

untold isleBOT
#

On live usb it unlocks

#

On machine it does not

sacred hollow
#

then it seems something is still wrong with the configuration for your initramfs…

#

since this is cachyos, did it make a crypttab in the main root?

untold isleBOT
#

ya

#

an empty one

#

well the cachyos installer failed to finish so I just installed the rest of the system myself

sacred hollow
#

hm…

#

well, we could try to explicitly instruct systemd-cryptsetup-generator using kernel parameters as in here

#

though we already tried that once and it didn’t turn out too well…

untold isleBOT
#

mkinitcpio

sacred hollow
#

oh, sure, use mkinitcpio

untold isleBOT
#

i use dracut, not mkinitcpio

sacred hollow
#

oh

#

I misinterpreted

#

well, the kernel parameters should still work since they’re supposed to be for systemd, not dracut or mkinitcpio in particular

#

but if it doesn’t we can try to embed a crypttab into the initramfs

#

if you want to use the /etc/crypttab.initramfs name for this, then you have to find whatever script is running dracut and then add --include /etc/crypttab.initramfs /etc/crypttab to the list of options

untold isleBOT
#

what if I embed the key into the initrd

sacred hollow
#

you can do that, too!

untold isleBOT
#

it's a bit dangerous

#

but nobody that could possibly gain physical access to my machine would be computer literate enough to comprehend that

#

how do I proceed now

sacred hollow
#

well, you can just create a keyfile in the default location

#

in your case this would be something like /etc/cryptsetup-keys.d/root.key

#

and you can add a dracut configuration file to have dracut add it to your initramfs

#

ideally systemd-gpt-auto-generator and systemd-cryptsetup-generator will work together to automatically use it to unlock your root partition

#

if not… I guess dracut would be really weird

untold isleBOT
#

oki

#

i will check

#

But I have to setup another machine now

limpid swan
#

@marble tartan why use tpm?

untold isleBOT
#

because I do not want to enter my password every time to the obnoxious prompt

#

and no I wont use plymouth

#

setting up plymouth is another nightmare

#

and I dont have a card reader either

untold isleBOT
#

alright this is what happens when I install the keys to the initrd

dracut-install: ERROR: installing '/etc/cryptsetup.keys.d/root.key'
dracut[E]: FAILED: /usr/lib/dracut/dracut-install -D /var/tmp/dracut.9mSnen/initramfs -a /etc/cryptsetup.keys.d/root.key
#
install_items+=" /etc/cryptsetup.keys.d/root.key "

this is my miserable config file

sacred hollow
untold isleBOT
#

oops

#

fixed that

#

now I add a crypttab to the initrd right?

sacred hollow
#

you don’t need to, hopefully

#

it’s named root.key so it will automatically be used for /dev/mapper/root

#

and systemd-gpt-auto-generator will automatically name the decrypted root device root

#

but if you reboot and this doesn’t work, you can add a crypttab or rd.luks options

untold isleBOT
#

that did not work so I added luks options

Fleuria ↩️

[Reply to:](#1356209447134953712 message) it’s named root.key so it will automatically be used for /dev/mapper/root

sacred hollow
#

okay, sure

#

wait…

#

I might have forgot this whole time

#

dracut adds options to your initramfs automatically without asking!

untold isleBOT
#

wdym

sacred hollow
#

it will automatically detect command line options

#

and put it into the initramfs

#

and that has probably been screwing over systemd’s automatic systems this whole time

untold isleBOT
#

so do I now uhh

#

remove the rd prefix

#

or do I remove the cmdline altogether

sacred hollow
#

you don’t need to since you will only decrypt the device in the initramfs

#

there’s an option for no hostonly cmdline

#

that will prevent dracut from adding options

#

you can check the man page to see how it’s spelled

untold isleBOT
#

regenerated the initramfs

#

rebooting

untold isleBOT
#

it did not work

sacred hollow
#

okay, this is very late but my question would then be if you’re actually using systemd-gpt-auto-generator

#

that was another assumption I was making that could be wrong

untold isleBOT
#

well how do I check

Fleuria ↩️

[Reply to:](#1356209447134953712 message) okay, this is very late but my question would then be if you’re actually using systemd-gpt-auto-gene…

sacred hollow
#

do you have any root= parameters in your command line?

untold isleBOT
#

ya

#

read-write mount of the open luks volume

sacred hollow
#

and do you have parameters that specify the LUKS volume?

untold isleBOT
#

wdym

Fleuria ↩️

[Reply to:](#1356209447134953712 message) and do you have parameters that specify the LUKS volume?

sacred hollow
#

like, did you add the rd.luks parameters that specified name and UUID and stuff per the Arch Wiki?

untold isleBOT
#

yes

Fleuria ↩️

[Reply to:](#1356209447134953712 message) like, did you add the rd.luks parameters that specified name and UUID and stuff per the Arch Wiki?

sacred hollow
#

in that case, the only thing left to do is to add the parameter explicitly describing the location of the keyfile too

#

and if somehow, after all of that, it still doesn’t work

#

then this is a Cursed Problem and I would recommend trying mkinitcpio

untold isleBOT
#

oki ty

#

(I tried that too, that one did not work either)

Fleuria ↩️

[Reply to:](#1356209447134953712 message) in that case, the only thing left to do is to add the parameter explicitly describing the location o…

sacred hollow
#

like I have a mkinitcpio initramfs with all the systemd bells and whistles

#

and the stuff I’ve done with crypto stuff all worked first try

untold isleBOT
#

so I give mkinitcpio another chance

Fleuria ↩️

[Reply to:](#1356209447134953712 message) and the stuff I’ve done with crypto stuff all worked first try

untold isleBOT
#

mkinitcpio worked, apparently

#

how do I get rid of dracut now

#

thank you all @sacred hollow, @opaque marlin and @limpid swan

deep emberBOT
#

fleuriafluoride, 0fficerk, and killertofus received a thank you cookie!

opaque marlin
untold isleBOT
#

nope I cannot

#

also yay sbctl cannot sign grub now

#

haha

marble tartan
#

[SOLVED] no matter how many times I enroll the secure boot keys to TPM dracut asks for my password