|
30 | 30 | cat "$TMP_KEY_DEVICES" | cut -d\ -f1 | xargs /bin/qubes-measure-luks \ |
31 | 31 | || die "LUKS measure failed" |
32 | 32 |
|
33 | | -# Unpack the initrd and fixup the /etc/crypttab |
| 33 | +# Unpack the initrd and fixup the crypttab |
34 | 34 | # this is a hack to split it into two parts since |
35 | 35 | # we know that the first 0x3400 bytes are the microcode |
36 | 36 | INITRD_DIR=/tmp/secret/initrd |
37 | 37 | SECRET_CPIO=/tmp/secret/initrd.cpio |
| 38 | +bootdir=$(dirname "$INITRD") |
38 | 39 | mkdir -p "$INITRD_DIR/etc" |
39 | 40 |
|
40 | 41 | # Attempt to unseal the disk key from the TPM |
@@ -73,9 +74,29 @@ dd if="$INITRD" of="$SECRET_CPIO" bs=512 conv=sync \ |
73 | 74 | || die "Failed to copy initrd to /tmp" |
74 | 75 |
|
75 | 76 | if [ "$unseal_failed" = "n" ]; then |
76 | | - # overwrite /etc/crypttab to mirror the behavior for in seal-key |
77 | | - for uuid in `cat "$TMP_KEY_DEVICES" | cut -d\ -f2`; do |
78 | | - echo "luks-$uuid UUID=$uuid /secret.key" >> "$INITRD_DIR/etc/crypttab" |
79 | | - done |
| 77 | + # kexec-save-default might have created crypttab overrides to be injected in initramfs through additional cpio |
| 78 | + if [ -r "$bootdir/kexec_initrd_crypttab_overrides.txt" ]; then |
| 79 | + echo "$bootdir/kexec_initrd_crypttab_overrides.txt found..." |
| 80 | + echo "Preparing initramfs crypttab overrides as defined under $bootdir/kexec_initrd_crypttab_overrides.txt to be injected through cpio at next kexec call..." |
| 81 | + # kexec-save-default has found crypttab files under initrd and saved them |
| 82 | + cat "$bootdir/kexec_initrd_crypttab_overrides.txt" | while read line; do |
| 83 | + crypttab_file=$(echo "$line" | awk -F ':' {'print $1'}) |
| 84 | + crypttab_entry=$(echo "$line" | awk -F ':' {'print $NF'}) |
| 85 | + # Replace each initrd crypttab file with modified entry containing /secret.key path |
| 86 | + mkdir -p "$INITRD_DIR/$(dirname $crypttab_file)" |
| 87 | + echo "$crypttab_entry" | tee -a "$INITRD_DIR/$crypttab_file" > /dev/null |
| 88 | + echo "initramfs's $crypttab_file will be overriden with $crypttab_entry" |
| 89 | + done |
| 90 | + else |
| 91 | + # No crypttab files were found under selected default boot option's initrd file |
| 92 | + crypttab_file="etc/crypttab" |
| 93 | + mkdir -p "$INITRD_DIR/$(dirname $crypttab_file)" |
| 94 | + # overwrite crypttab to mirror behavior of seal-key |
| 95 | + echo "The following /etc/crypttab lines will be passed through cpio into kexec call for default boot option:" |
| 96 | + for uuid in `cat "$TMP_KEY_DEVICES" | cut -d\ -f2`; do |
| 97 | + # NOTE: discard operation (TRIM) is activated by default if no crypptab found in initrd |
| 98 | + echo "luks-$uuid UUID=$uuid /secret.key luks,discard" | tee -a "$INITRD_DIR/$crypttab_file" |
| 99 | + done |
| 100 | + fi |
80 | 101 | ( cd "$INITRD_DIR" ; find . -type f | cpio -H newc -o ) >> "$SECRET_CPIO" |
81 | 102 | fi |
0 commit comments