Re-enroll TPM2 auto-unlock for Agama FDE on Leap 16.0 (GRUB2, encrypted /boot)

Hi all,
I installed openSUSE Leap 16.0 using Agama with Full Disk Encryption and TPM2 auto-unlock. It worked fine originally.

I then migrated the installation to a new SSD using a block-level clone (ddrescue). The motherboard/TPM did not change, only the SSD. Unfortunately, a password prompt now appears in the GRUB2 bootloader. After entering the password, everything is working as expected.

My layout is the Leap 16 default: only a separate unencrypted /boot/efi ESP, and /boot is inside the encrypted root.

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINTS
sr0          11:0    1 1024M  0 rom   
nvme0n1     259:0    0  1.7T  0 disk  
|-nvme0n1p1 259:1    0  512M  0 part  /boot/efi
`-nvme0n1p2 259:2    0  1.7T  0 part  
  `-cr_root 254:0    0  1.7T  0 crypt /var
                                      /usr/local
                                      /srv
                                      /root
                                      /home
                                      /boot/grub2/x86_64-efi
                                      /boot/grub2/i386-pc
                                      /opt
                                      /.snapshots
                                      /

I searched online about restoring the TPM2 auto-unlock and only found the Aeon wiki which uses sdbootutil

But it doesn’t seem applicable here, as it is the sdbootutil command configures systemd-boot and not GRUB2, which is used by Leap 16.

Bootloader confirmation (GRUB2 via shim):

bash

$ sudo efibootmgr -v
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000,0001
Boot0000* opensuse-secureboot   HD(1,GPT,f761b314-436b-4b4f-bb7e-ec5dbaa74f9a,0x800,0x100000)/File(\EFI\OPENSUSE\SHIM.EFI)
      dp: 04 01 2a 00 01 00 00 00 00 08 00 00 00 00 00 00 00 00 10 00 00 00 00 00 14 b3 61 f7 6b 43 4f 4b bb 7e ec 5d ba a7 4f 9a 02 02 / 04 04 32 00 5c 00 45 00 46 00 49 00 5c 00 4f 00 50 00 45 00 4e 00 53 00 55 00 53 00 45 00 5c 00 53 00 48 00 49 00 4d 00 2e 00 45 00 46 00 49 00 00 00 / 7f ff 04 00
Boot0001  opensuse      HD(1,GPT,f761b314-436b-4b4f-bb7e-ec5dbaa74f9a,0x800,0x100000)/File(\EFI\OPENSUSE\GRUBX64.EFI)0000424f
      dp: 04 01 2a 00 01 00 00 00 00 08 00 00 00 00 00 00 00 00 10 00 00 00 00 00 14 b3 61 f7 6b 43 4f 4b bb 7e ec 5d ba a7 4f 9a 02 02 / 04 04 38 00 5c 00 45 00 46 00 49 00 5c 00 4f 00 50 00 45 00 4e 00 53 00 55 00 53 00 45 00 5c 00 47 00 52 00 55 00 42 00 58 00 36 00 34 00 2e 00 45 00 46 00 49 00 00 00 / 7f ff 04 00
    data: 00 00 42 4f

Question: What is the supported way on Leap 16 to re-enroll TPM2 auto-unlock for GRUB2 (so GRUB can unlock the LUKS2 root again)?

Cheers
Simon

Outside my experience, but to start with check existing LUKS token…
sudo cryptsetup luksDump /dev/nvme0n1p2

You could disable any old TPM binding with
sudo fdectl tpm-disable
That should ensure a clean state.

This might be worth a read re next steps…
https://en.opensuse.org/SDB:Encrypted_root_file_system#Seal_the_LUKS_key_with_TPM_2.0
Hopefully others can clarify further here.

Also
https://manpages.opensuse.org/Leap-16.0/fde-tools/fdectl.8.en.html

1 Like

Thank you so much @deano_ferrari for the hint into the right direction :pray:


To quickly update the PCR policy of the sealed key, it was simply a matter of # fdectl tpm-authorize, as documented here.

$ sudo fdectl tpm-authorize
Signed PCR policy written to /boot/efi/EFI/OPENSUSE/sealed.tpm
Excluding PCR 10 from prediction (used by IMA)

Although this fixed the TPM auto-unlock right away, there was still a silent issue remaining from the disk migration …


For the migration I have used a live USB, for which I temporarily disabled Secure Boot in the UEFI. After the auto-unlock did work again, I went into the UEFI to enable Secure Boot again, and I also enabled Fast Boot, which I was using previously too.

Unfortunately, this disabled the USB keyboard which prevented me from entering the UEFI setup during boot and from entering the LUKS passphrase in the GRUB2 bootloader, which was necessary again due to the changed UEFI settings …

As I did not have a PS/2 keyboard at hand, I did clear the CMOS of the motherboard with a jumper, which cleared firmware settings and TPM-related state.

At least, I could enter the encryption passphrase again afterwards and boot successfully into Leap 16.0.


In order to (re-)create the seal for the TPM2, I had to use the fdectl regenerate-key command, which did fail:

$ sudo fdectl regenerate-key
Device /dev/disk/by-id/nvme-nvme.<OLD-SSD>-part2 does not exist or access denied.
Authorized policy written to /etc/fde/authorized-policy/authorized-policy.tpm
Please enter LUKS recovery password:
Verifying LUKS recovery password (/dev/disk/by-id/nvme-nvme.<OLD-SSD>-part2)
Device /dev/disk/by-id/nvme-nvme.<OLD-SSD>-part2 does not exist or access denied.
Unable to open the device with the password
Error: Failed to verify password on LUKS partition (/dev/disk/by-id/nvme-nvme.<OLD-SSD>-part2)

After a while I noticed that fdectl is still trying to access the old NVMe SSD, which is not present anymore:

$  ls -l /dev/disk/by-id/nvme-nvme.*-part2                                                                                            
lrwxrwxrwx. 1 root root 15 Dec 28 12:53 /dev/disk/by-id/nvme-nvme.<NEW-SSD>-part2 -> ../../nvme0n1p2

Even specifying the correct mount path or device path with the --device argument to fdectl did not work …

Only afterwards I noticed that there is a configuration file for fdectl which is still pointing to the old NVMe SSD:

$ cat /etc/sysconfig/fde-tools
# Tunables for full disk encryption

# Configure whether to use old-style PCR policies, or TPMv2 authorized policies.
# Set to yes/no
FDE_USE_AUTHORIZED_POLICIES="yes"

# List of PCRs to seal the LUKS key to
FDE_SEAL_PCR_LIST="0,2,4,7,9"
FDE_SEAL_PCR_BANK="sha256"

# It appears that 128 is the maximum size of what TPM2_Load is willing to handle
FDE_KEY_SIZE_BYTES="128"

# These need to match exactly what grub2 uses to create the SRK
FDE_TPM2_SRK_ATTRS="userwithauth|restricted|decrypt|fixedtpm|fixedparent|noda|sensitivedataorigin"

# The PBKDF algorithm to use for deriving LUKS keys from a given password
# For grub2 based schemes, you have to use pbkdf2 for now.
FDE_LUKS_PBKDF="pbkdf2"

# Enable/disable tracing output
FDE_TRACING="true"

# This is used by the installer to inform "fdectl tpm-enable" about a key
# to enroll on the next reboot
FDE_ENROLL_NEW_KEY=""

# Specify the devices to be managed by fdectl
# NOTE: Those devices must use the same recovery password.
FDE_DEVS="/dev/disk/by-id/nvme-nvme.<OLD-SSD>-part2"

# [DEPRECATED] Use FDE_DEVS instead
# FDE_EXTRA_DEVS=""

# Configure whether to update the authorized policy in the sealed key after
# the bootloader update
# Set to yes/no
FDE_TPM_AUTO_UPDATE="yes"

# The RSA key size to be used for SRK and the private sign key
# Expected values: 2048, 3072, 4096, or just leave it empty to let fdectl
# to determine the size at runtime
FDE_RSA_KEY_SIZE=""
FDE_AUTHORIZED_POLICY="authorized-policy"

After changing the FDE_DEVS variable of this file, I could finally use the fdectl regenerate-key command to benefit from auto-unlock via TPM2 during boot again :sunglasses:

$ sudo fdectl regenerate-key
Authorized policy written to /etc/fde/authorized-policy/authorized-policy.tpm
Please enter LUKS recovery password:
Verifying LUKS recovery password (/dev/disk/by-id/nvme-nvme.<NEW-SSD>-part2)
Sealing secret - this may take a moment
Sealed secret written to /etc/fde/authorized-policy/sealed.tpm
copying /usr/share/efi/x86_64/grub.efi to /boot/efi/EFI/opensuse/grub.efi
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0001
Boot0001  opensuse      HD(1,GPT,<PARTUUID>,0x800,0x100000)/File(\EFI\OPENSUSE\GRUBX64.EFI)0000424f
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000,0001
Boot0001  opensuse      HD(1,GPT,<PARTUUID>,0x800,0x100000)/File(\EFI\OPENSUSE\GRUBX64.EFI)0000424f
Boot0000* opensuse-secureboot   HD(1,GPT,<PARTUUID>,0x800,0x100000)/File(\EFI\opensuse\shim.efi)
Unable to verify signature of a boot service; probably a driver residing in ROM.
Signed PCR policy written to /boot/efi/EFI/opensuse/sealed.tpm
Excluding PCR 10 from prediction (used by IMA)
Unable to verify signature of a boot service; probably a driver residing in ROM.
copying /usr/share/efi/x86_64/grub.efi to /boot/efi/EFI/opensuse/grub.efi
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0001
Boot0001  opensuse      HD(1,GPT,<PARTUUID>,0x800,0x100000)/File(\EFI\OPENSUSE\GRUBX64.EFI)0000424f
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000,0001
Boot0001  opensuse      HD(1,GPT,<PARTUUID>,0x800,0x100000)/File(\EFI\OPENSUSE\GRUBX64.EFI)0000424f
Boot0000* opensuse-secureboot   HD(1,GPT,<PARTUUID>,0x800,0x100000)/File(\EFI\opensuse\shim.efi)

Cheers Simon

1 Like

Well done with resolving the issue, and thanks for the well-documented update.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.