From a75b3fde664286ac76a4e47743ddac1e031b6c1d Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Fri, 27 Nov 2026 20:00:02 -0500 Subject: [PATCH 01/23] feat(boot): add Secure Boot serial needles and swtpm cases Emit deterministic unlock and PCR failure needles from image units, and add two isolated OVMF+swtpm boot cases that consume the published fixtures. --- .github/workflows/build.yml | 34 +++- docs/BUILD.md | 2 + docs/SECURITY.md | 11 ++ elements/config/files.bst | 4 + elements/kernel/initramfs.bst | 16 ++ files/config/dracut/50-mjolnir-tpm2.conf | 6 + files/config/presets/80-mjolnir.preset | 1 + .../systemd/mjolnir-state-unlocked.service | 17 ++ .../mjolnir-state-unseal-failed.service | 12 ++ .../10-mjolnir-failure.conf | 5 + tests/test_boot_assets.py | 3 + tests/test_units.py | 33 ++++ testsuite/README.md | 50 ++++- testsuite/boot/test-boot.sh | 178 +++++++++++++++++- 14 files changed, 365 insertions(+), 7 deletions(-) create mode 100644 files/config/systemd/mjolnir-state-unlocked.service create mode 100644 files/config/systemd/mjolnir-state-unseal-failed.service create mode 100644 files/config/systemd/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1e4998..d392663 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -142,15 +142,47 @@ jobs: max-layers: "128" source-date-epoch: auto + # The image repository publishes these three assets alongside a release. + # When the base URL is not configured the boot test records a SKIP for the + # Secure Boot cases; it never relaxes an assertion. + - name: Provision Secure Boot fixtures + env: + FIXTURE_BASE_URL: ${{ vars.SECUREBOOT_FIXTURE_BASE_URL }} + FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures + run: | + set -euo pipefail + mkdir -p "$FIXTURE_DIR" + if [ -z "$FIXTURE_BASE_URL" ]; then + echo "NOTICE: SECUREBOOT_FIXTURE_BASE_URL is not configured." + echo "The Secure Boot swtpm cases will record a SKIP." + exit 0 + fi + for fixture in OVMF_VARS.enrolled.fd uki-signed.efi uki-unknown.efi; do + curl -fsSL "$FIXTURE_BASE_URL/$fixture" -o "$FIXTURE_DIR/$fixture" + done + # The install checks that bootc accepts the signed digest, and the OVMF # boot checks that the shell-free initramfs actually mounts the composefs # root and reaches user space. A static content check cannot prove that. - name: Install and boot test (OVMF) + env: + FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures run: | sudo apt-get update -qq - sudo apt-get install -y -qq qemu-system-x86 ovmf binutils + sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm just boot-test + - name: Upload Secure Boot serial logs + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: mjolnir-secureboot-serial-logs + path: | + ${{ runner.temp }}/mjolnir-boot-test/secureboot-signed.log + ${{ runner.temp }}/mjolnir-boot-test/secureboot-unknown.log + if-no-files-found: warn + retention-days: 90 + - name: Export image for scanning run: sudo podman save --format docker-archive -o /tmp/scan-image.tar localhost/mjolnir:latest diff --git a/docs/BUILD.md b/docs/BUILD.md index db5bf26..0c57304 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -8,6 +8,8 @@ - Network access to `gitlab.com`, `github.com`, `dl.k8s.io`, the FSDK BuildStream caches and the pinned FSDK `bst2` container image. - QEMU with KVM for the boot test (optional; requires a real root user namespace). + The Secure Boot cases in `just boot-test` also need `swtpm` and the release + fixtures described in [testsuite/README.md](../testsuite/README.md). BuildStream itself is not installed on the host. Every `bst` invocation runs inside the pinned `bst2` container via `just bst`. diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 0bb6d5b..b1b2c7c 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -148,6 +148,17 @@ The initramfs is built with the dracut `crypt` module and the systemd TPM2 cryptsetup token plugin, whose ELF dependencies pull in `tpm2-tss`. It includes the build-time `/etc/crypttab`. +The unlock outcome has a stable serial contract. `mjolnir-state-unlocked.service` +prints `MjolnirState: unlocked` after `var-lib-mjolnir.mount`. An `OnFailure=` +drop-in on `systemd-cryptsetup@mjolnir-state.service` starts +`mjolnir-state-unseal-failed.service`, which prints `PCR policy` and +`Failed to unseal`. The drop-in and the failure unit are also sealed into the +initramfs, because a PCR policy miss fails cryptsetup before switch-root. No +key material changes and the PCR 7 plus signed PCR 11 binding is untouched. +`testsuite/boot/test-boot.sh` boots two isolated OVMF plus swtpm cases against +the published signed and unknown-key UKIs and asserts those needles; see +[testsuite/README.md](../testsuite/README.md) for the fixture contract. + ## Factory reset `io.mjolnir.Fleet.FactoryReset` requires a `scope` diff --git a/elements/config/files.bst b/elements/config/files.bst index 3d0102d..80dda85 100644 --- a/elements/config/files.bst +++ b/elements/config/files.bst @@ -43,6 +43,10 @@ config: "${root}/usr/lib/tmpfiles.d/mjolnir-volatile.conf" install -Dm644 /config/systemd/var-lib-mjolnir.mount \ "${root}/usr/lib/systemd/system/var-lib-mjolnir.mount" + # The cryptsetup instance drop-in lives in a directory, so the *.service + # glob below does not copy it. The initramfs stages its own copy. + install -Dm644 /config/systemd/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf \ + "${root}/usr/lib/systemd/system/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf" for m in var-lib-mjolnir var-lib-etcd etc-machine-id \ etc-NetworkManager-system-connections \ var-lib-containerd var-lib-kubelet var-log-journal var-lib-cni \ diff --git a/elements/kernel/initramfs.bst b/elements/kernel/initramfs.bst index ff4891a..b79d108 100644 --- a/elements/kernel/initramfs.bst +++ b/elements/kernel/initramfs.bst @@ -66,6 +66,13 @@ config: install -Dm644 /config/crypttab /etc/crypttab install -Dm644 /config/dracut/50-mjolnir-tpm2.conf \ /etc/dracut.conf.d/50-mjolnir-tpm2.conf + # The PCR policy failure is reported by an OnFailure drop-in on the + # cryptsetup instance. Stage both files for dracut's install_items so the + # wires exist in the initramfs, not just in the booted rootfs. + install -Dm644 /config/systemd/mjolnir-state-unseal-failed.service \ + /usr/lib/systemd/system/mjolnir-state-unseal-failed.service + install -Dm644 /config/systemd/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf \ + /usr/lib/systemd/system/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf # FSDK installs shared libraries in the multiarch libdir but ships an empty # /etc/ld.so.conf. dracut-install resolves DT_NEEDED from that file plus # /lib and /usr/lib, so with an empty config the initramfs contains no libc @@ -132,6 +139,15 @@ config: exit 1 } done + # Prove the PCR failure report travels with the initramfs. A drop-in in + # the rootfs alone cannot fire before switch-root. + for f in usr/lib/systemd/system/mjolnir-state-unseal-failed.service \ + 10-mjolnir-failure.conf usr/bin/echo; do + lsinitrd /initramfs.img | grep -q "$f" || { + echo "initramfs is missing the PCR failure reporter: $f" >&2 + exit 1 + } + done install -Dm644 /initramfs.img \ "%{install-root}/usr/lib/modules/${version}/initramfs.img" depmod -b "%{install-root}/usr" -a "${version}" diff --git a/files/config/dracut/50-mjolnir-tpm2.conf b/files/config/dracut/50-mjolnir-tpm2.conf index 5f5186e..3cdfca0 100644 --- a/files/config/dracut/50-mjolnir-tpm2.conf +++ b/files/config/dracut/50-mjolnir-tpm2.conf @@ -5,3 +5,9 @@ add_dracutmodules+=" crypt " install_items+=" /etc/crypttab " install_optional_items+=" /usr/lib/cryptsetup/libcryptsetup-token-systemd-tpm2.so " +# A PCR policy miss fails cryptsetup in the initramfs, so the failure report +# and its OnFailure drop-in must be present before switch-root. echo is a +# compiled binary; no shell or interpreter enters the initramfs. +install_items+=" /usr/lib/systemd/system/mjolnir-state-unseal-failed.service " +install_items+=" /usr/lib/systemd/system/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf " +install_items+=" /usr/bin/echo " diff --git a/files/config/presets/80-mjolnir.preset b/files/config/presets/80-mjolnir.preset index 03c8cd0..c53101f 100644 --- a/files/config/presets/80-mjolnir.preset +++ b/files/config/presets/80-mjolnir.preset @@ -6,6 +6,7 @@ enable mjolnir-join.service enable mjolnir-apply.service enable varlink-httpd.socket enable mjolnir-state-enroll.service +enable mjolnir-state-unlocked.service enable mjolnir-etcd-snapshot.timer enable NetworkManager.service enable systemd-resolved.service diff --git a/files/config/systemd/mjolnir-state-unlocked.service b/files/config/systemd/mjolnir-state-unlocked.service new file mode 100644 index 0000000..1ec2064 --- /dev/null +++ b/files/config/systemd/mjolnir-state-unlocked.service @@ -0,0 +1,17 @@ +[Unit] +Description=Report MjolnirState unlock on the serial console +DefaultDependencies=no +After=var-lib-mjolnir.mount +RequiresMountsFor=/var/lib/mjolnir + +[Service] +Type=oneshot +RemainAfterExit=yes +# journal+console writes straight to /dev/console; the needle is not subject to +# journald forwarding settings or console log level. +ExecStart=/usr/bin/echo MjolnirState: unlocked +StandardOutput=journal+console +StandardError=journal+console + +[Install] +WantedBy=local-fs.target diff --git a/files/config/systemd/mjolnir-state-unseal-failed.service b/files/config/systemd/mjolnir-state-unseal-failed.service new file mode 100644 index 0000000..2b4a155 --- /dev/null +++ b/files/config/systemd/mjolnir-state-unseal-failed.service @@ -0,0 +1,12 @@ +[Unit] +Description=Report a TPM2 PCR policy unseal failure on the serial console +DefaultDependencies=no + +[Service] +Type=oneshot +# The failure happens in the initramfs, before switch-root. Both needles are +# emitted by systemd itself, not by a shell or interpreter. +ExecStart=/usr/bin/echo PCR policy +ExecStart=/usr/bin/echo Failed to unseal +StandardOutput=journal+console +StandardError=journal+console diff --git a/files/config/systemd/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf b/files/config/systemd/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf new file mode 100644 index 0000000..d40b069 --- /dev/null +++ b/files/config/systemd/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf @@ -0,0 +1,5 @@ +[Unit] +# A PCR policy miss fails the cryptsetup unit in the initramfs. The drop-in is +# installed in both the rootfs and the initramfs so the report fires before and +# after switch-root. +OnFailure=mjolnir-state-unseal-failed.service diff --git a/tests/test_boot_assets.py b/tests/test_boot_assets.py index e61acdb..832269f 100644 --- a/tests/test_boot_assets.py +++ b/tests/test_boot_assets.py @@ -35,6 +35,9 @@ "/usr/lib/repart.d/20-mjolnir-state.conf", "/etc/crypttab", "/usr/lib/systemd/system/mjolnir-state-enroll.service", + "/usr/lib/systemd/system/mjolnir-state-unlocked.service", + "/usr/lib/systemd/system/mjolnir-state-unseal-failed.service", + "/usr/lib/systemd/system/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf", "/usr/lib/systemd/system/mjolnir-reset-node-identity.service", "/usr/lib/systemd/system/mjolnir-reset-etcd-data.service", "/usr/lib/systemd/system/mjolnir-reset-full.service", diff --git a/tests/test_units.py b/tests/test_units.py index 5a859c6..5c0b57c 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -63,6 +63,39 @@ def main() -> int: if "/run/credentials/@system/mjolnir.boot-report" not in report_text: errors.append("mjolnir-boot-report.service: missing dotted boot-report credential gate") + # Secure Boot serial needles are an external contract: Gram greps for the + # exact strings. Check the units, the drop-in that fires on a cryptsetup + # failure, and the boot assertions that consume them. + def text_at(relative: str) -> str: + path = ROOT / relative + return path.read_text() if path.is_file() else "" + + def require(relative: str, needle: str, label: str) -> None: + if needle not in text_at(relative): + errors.append(f"{relative}: missing {label}: {needle!r}") + + unlocked = "files/config/systemd/mjolnir-state-unlocked.service" + failed = "files/config/systemd/mjolnir-state-unseal-failed.service" + dropin = ("files/config/systemd/systemd-cryptsetup@mjolnir-state.service.d/" + "10-mjolnir-failure.conf") + dracut = "files/config/dracut/50-mjolnir-tpm2.conf" + boot = "testsuite/boot/test-boot.sh" + + require(unlocked, "ExecStart=/usr/bin/echo MjolnirState: unlocked", "unlock needle") + require(unlocked, "After=var-lib-mjolnir.mount", "unlock ordering") + require(unlocked, "StandardOutput=journal+console", "console output") + require("files/config/presets/80-mjolnir.preset", + "enable mjolnir-state-unlocked.service", "unlock preset") + require(failed, "ExecStart=/usr/bin/echo PCR policy", "PCR needle") + require(failed, "ExecStart=/usr/bin/echo Failed to unseal", "unseal failure needle") + require(failed, "StandardOutput=journal+console", "console output") + require(dropin, "OnFailure=mjolnir-state-unseal-failed.service", "failure wiring") + require(dracut, "mjolnir-state-unseal-failed.service", "initramfs failure unit") + require(dracut, "10-mjolnir-failure.conf", "initramfs drop-in") + require(dracut, "/usr/bin/echo", "initramfs echo binary") + for needle in ("MjolnirState: unlocked", "PCR policy", "Failed to unseal"): + require(boot, needle, "boot assertion needle") + # Lid switches must never suspend an unattended node. logind = ROOT / "files/config/logind/50-ignore-lid.conf" logind_text = logind.read_text() if logind.is_file() else "" diff --git a/testsuite/README.md b/testsuite/README.md index ff3e418..3dd686f 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -12,8 +12,9 @@ clusters and the mTLS Varlink API. `.github/workflows/multinode.yml` on `testing`. - `plugin-smoke.sh` — Console plugin smoke check, run by `.github/workflows/plugin-test.yml`. -- `boot/test-boot.sh` — install + OVMF boot proof, run by the `image` job in - `.github/workflows/build.yml` on pull requests and pushes. +- `boot/test-boot.sh` — install + OVMF boot proof and the two Secure Boot + swtpm cases, run by the `image` job in `.github/workflows/build.yml` on pull + requests and pushes. ## Boot verification @@ -26,4 +27,47 @@ root as a distinct systemd-boot entry. See [docs/ARCHITECTURE.md](../docs/ARCHITECTURE.md). Run it locally with `sudo just boot-test` after `just build`; it needs root, -KVM, QEMU, OVMF and `objcopy`. +KVM, QEMU, OVMF and `objcopy`. The Secure Boot cases additionally need `swtpm`. + +## Secure Boot unlock cases + +`boot/test-boot.sh` appends two cases after the OVMF check above. Each case +copies the installed disk and gets its own copy of the enrolled OVMF variable +store and its own swtpm state directory, so a failed unseal in one case cannot +leak into the other. Both cases first boot `uki-signed.efi` to establish the +TPM2 enrollment, then reboot with the case's update: + +| Case | Update installed in the ESP | Required serial evidence | +| --- | --- | --- | +| signed | `uki-signed.efi` | `MjolnirState: unlocked`, no `Failed to unseal` | +| unknown | `uki-unknown.efi` | `PCR policy` and `Failed to unseal`, no unlock | + +The needles come from image units, not from journal text the guest happens to +emit. `mjolnir-state-unlocked.service` runs after `var-lib-mjolnir.mount` and is +enabled by the preset. A drop-in for `systemd-cryptsetup@mjolnir-state.service` +wires `OnFailure=` to `mjolnir-state-unseal-failed.service`; that unit and the +drop-in are installed in both the rootfs and the initramfs because the PCR miss +fails cryptsetup before switch-root. Both units use +`StandardOutput=journal+console` so the strings reach the serial log +regardless of journald forwarding settings. + +### Fixtures + +The three fixtures are release assets of this repository, published by the +Secure Boot fixture work. The harness reads them from `FIXTURE_DIR`, which +defaults to `$RUNNER_TEMP/mjolnir-secureboot-fixtures`: + +| File | Meaning | +| --- | --- | +| `OVMF_VARS.enrolled.fd` | Variable store with PK/KEK/db holding the test key, Secure Boot enabled; copied fresh per case | +| `uki-signed.efi` | Signed update that satisfies the existing PCR 11 policy | +| `uki-unknown.efi` | Same boot, signed with an unknown PCR signing key | + +Env overrides: `FIXTURE_DIR`, `SECUREBOOT_FIXTURE_DIR`, `OVMF_VARS_ENROLLED`, +`UKI_SIGNED`, `UKI_UNKNOWN`, `SIGNED_LOG`, `UNKNOWN_LOG`, `SWTPM`, `BOOT_WAIT`, +`GRACE_SECONDS`, and the three needle overrides `UNLOCK_NEEDLE`, `PCR_NEEDLE`, +`UNSEAL_FAIL_NEEDLE`. CI sets `FIXTURE_DIR` from the +`SECUREBOOT_FIXTURE_BASE_URL` repository variable. With no variable configured +the two cases write SKIP logs and the run stays green; the assertions in the +script and the static checks in `tests/test_units.py` still run on every PR. +Both serial logs are uploaded as the `mjolnir-secureboot-serial-logs` artifact. diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index df18f51..09e93cb 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash -# Full install + OVMF boot proof for the signed composefs UKI. +# Full install + OVMF boot proof for the signed composefs UKI, plus two +# Secure Boot + swtpm cases that consume the published UKI/variable-store +# fixtures. # # Runs on the CI runner (root required). There is no shell in the image: the # image is installed with `bootc install to-disk`, the installed UKI is checked # against the composefs digest of the image under test, and the disk is booted # through OVMF/systemd-boot. Readiness is proven by the image's own Varlink -# socket, not by injecting a shell or a login into the target. +# socket, not by injecting a shell or a login into the target. The extra cases +# read serial needles emitted by image units; fixtures are described in +# testsuite/README.md. set -euo pipefail IMAGE="${1:-localhost/mjolnir:latest}" @@ -30,7 +34,19 @@ sudo -n true || fail "passwordless sudo is required for the privileged install a rm -rf "$WORK" mkdir -p "$WORK/rootfs" "$WORK/esp" -trap 'set +e; sudo umount "$WORK/esp" 2>/dev/null; [ -n "${LOOP:-}" ] && sudo losetup -d "$LOOP" 2>/dev/null; kill "${QEMU_PID:-}" 2>/dev/null; sudo podman rm -f mjolnir-boot-src 2>/dev/null' EXIT +cleanup_boot() { + set +e + local l p f + sudo umount "$WORK/esp" 2>/dev/null + [ -n "${LOOP:-}" ] && sudo losetup -d "$LOOP" 2>/dev/null + for l in "${CASE_LOOPS[@]:-}"; do [ -n "$l" ] && sudo losetup -d "$l" 2>/dev/null; done + for p in "${CASE_QEMU_PIDS[@]:-}"; do [ -n "$p" ] && kill "$p" 2>/dev/null; done + for f in "$WORK"/secureboot-*/tpm/swtpm.pid; do + [ -f "$f" ] && kill "$(cat "$f")" 2>/dev/null + done + sudo podman rm -f mjolnir-boot-src 2>/dev/null +} +trap cleanup_boot EXIT echo "==> computing the expected composefs digest from the image under test" # bootc install hashes the OCI layers in container storage, not a flattened tar @@ -222,3 +238,159 @@ fi pass "booted with OVMF: signed UKI cmdline, live user space, no failed units" echo "Serial console log: $SERIAL" + +# --------------------------------------------------------------------------- +# Secure Boot + swtpm cases. +# +# The fixtures are release assets of the image repository. Each case gets its +# own copy of the installed disk, the enrolled variable store and the swtpm +# state directory. Missing fixtures produce SKIP logs and a green run: the +# existing checks above stay intact, and no assertion is weakened. Set +# FIXTURE_DIR (or the three per-file overrides) to run the cases. +# --------------------------------------------------------------------------- +FIXTURE_DIR="${FIXTURE_DIR:-${SECUREBOOT_FIXTURE_DIR:-${RUNNER_TEMP:-/tmp}/mjolnir-secureboot-fixtures}}" +VARS_ENROLLED="${OVMF_VARS_ENROLLED:-$FIXTURE_DIR/OVMF_VARS.enrolled.fd}" +UKI_SIGNED="${UKI_SIGNED:-$FIXTURE_DIR/uki-signed.efi}" +UKI_UNKNOWN="${UKI_UNKNOWN:-$FIXTURE_DIR/uki-unknown.efi}" +SIGNED_LOG="${SIGNED_LOG:-$WORK/secureboot-signed.log}" +UNKNOWN_LOG="${UNKNOWN_LOG:-$WORK/secureboot-unknown.log}" +SWTPM="${SWTPM:-swtpm}" +NEEDLE_UNLOCK="${UNLOCK_NEEDLE:-MjolnirState: unlocked}" +NEEDLE_PCR="${PCR_NEEDLE:-PCR policy}" +NEEDLE_FAILED="${UNSEAL_FAIL_NEEDLE:-Failed to unseal}" +BOOT_WAIT="${BOOT_WAIT:-180}" +GRACE="${GRACE_SECONDS:-10}" +CASE_LOOPS=() +CASE_QEMU_PIDS=() + +assert_needle() { + local log="$1" needle="$2" label="$3" + grep -aqF "$needle" "$log" || fail "$label: missing serial needle '$needle' in $log" + pass "$label: serial needle '$needle'" +} + +assert_no_needle() { + local log="$1" needle="$2" label="$3" + if grep -aqF "$needle" "$log"; then + fail "$label: unexpected serial needle '$needle' in $log" + fi + pass "$label: no '$needle'" +} + +# Put one fixture UKI on the case disk's ESP. The debug entry is removed from +# the copy so systemd-boot cannot choose it instead of the fixture. +install_case_uki() { + local cd="$1" uki="$2" loop part p count + loop=$(sudo losetup -f --show -P "$cd/disk.raw") || fail "cannot attach $cd/disk.raw" + CASE_LOOPS+=("$loop") + part="" + for p in "${loop}"p*; do + [ -b "$p" ] || continue + [ "$(sudo blkid -o value -s TYPE "$p" 2>/dev/null || true)" = "vfat" ] && part="$p" + done + [ -n "$part" ] || fail "no ESP partition on $cd/disk.raw" + sudo mount "$part" "$WORK/esp" || fail "cannot mount the case ESP" + sudo install -Dm644 "$uki" "$WORK/esp/EFI/Linux/$(basename "$UKI")" || \ + fail "cannot install $uki on the case ESP" + sudo rm -f "$WORK/esp/EFI/Linux/$(basename "$DBG_EFI")" \ + "$WORK/esp/loader/entries/99-mjolnir-debug.conf" + count=$(sudo find "$WORK/esp/EFI/Linux" -maxdepth 1 -name '*.efi' -type f | wc -l) + [ "$count" -eq 1 ] || fail "case ESP has $count UKIs; expected exactly one" + sudo umount "$WORK/esp" || fail "cannot unmount the case ESP" + sudo losetup -d "$loop" || fail "cannot detach $loop" +} + +boot_case() { + local label="$1" log="$2" cd="$3" primary="$4" pid elapsed=0 + SERIAL="$log" + # The log lives in the user-owned WORK dir; root writes through this fd. + # shellcheck disable=SC2024 + sudo qemu-system-x86_64 \ + -m 2048 -smp 2 -enable-kvm -nographic \ + -drive if=pflash,format=raw,unit=0,file="$WORK/code.fd",readonly=on \ + -drive if=pflash,format=raw,unit=1,file="$cd/vars.fd" \ + -drive file="$cd/disk.raw",format=raw,media=disk \ + -chardev "socket,id=chrtpm,path=$cd/tpm/swtpm.sock" \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-tis,tpmdev=tpm0 \ + -smbios type=11,value=io.systemd.credential:mjolnir.boot-report=1 \ + -smbios "type=11,value=io.systemd.credential.binary:varlink-httpd.tls.trust=$CA_B64" \ + -netdev user,id=net0 -device virtio-net-pci,netdev=net0 \ + >"$log" 2>&1 & + pid=$! + CASE_QEMU_PIDS+=("$pid") + while [ "$elapsed" -lt "$BOOT_WAIT" ]; do + if grep -aqF "$primary" "$log" 2>/dev/null; then break; fi + kill -0 "$pid" 2>/dev/null || break + sleep 2 + elapsed=$((elapsed + 2)) + done + # Give late units time to emit a needle before asserting its absence. + sleep "$GRACE" + kill "$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true + [ -s "$log" ] || fail "$label: VM produced no serial output" + pass "$label: serial log captured at $log" +} + +secureboot_cases() { + local missing=0 f label cd tpm + for f in "$VARS_ENROLLED" "$UKI_SIGNED" "$UKI_UNKNOWN"; do + if [ ! -s "$f" ]; then + echo " missing fixture: $f" + missing=1 + fi + done + if [ "$missing" -ne 0 ]; then + mkdir -p "$WORK" + for f in "$SIGNED_LOG" "$UNKNOWN_LOG"; do + printf 'SKIP: Secure Boot swtpm cases did not run.\nFixture directory: %s\nThe three fixtures are release assets of the image repository; see testsuite/README.md.\n' \ + "$FIXTURE_DIR" >"$f" + done + echo "SKIP: Secure Boot swtpm cases (fixtures not present in $FIXTURE_DIR)" + return 0 + fi + need "$SWTPM" + + for label in signed unknown; do + cd="$WORK/secureboot-$label" + tpm="$cd/tpm" + rm -rf "$cd" + mkdir -p "$tpm" + cp "$WORK/disk.raw" "$cd/disk.raw" || fail "cannot copy the disk for $label" + cp "$VARS_ENROLLED" "$cd/vars.fd" || fail "cannot copy the variable store for $label" + + echo "==> Secure Boot case $label: enrolling state with the signed UKI" + install_case_uki "$cd" "$UKI_SIGNED" + "$SWTPM" socket --tpmstate "dir=$tpm" \ + --ctrl "type=unixio,path=$tpm/swtpm.sock" \ + --pid "file=$tpm/swtpm.pid" --tpm2 --daemon || fail "swtpm did not start for $label" + for _ in $(seq 1 50); do + [ -S "$tpm/swtpm.sock" ] && break + sleep 0.1 + done + [ -S "$tpm/swtpm.sock" ] || fail "swtpm socket did not appear for $label" + + boot_case "$label-enroll" "$cd/enroll.log" "$cd" "$NEEDLE_UNLOCK" + assert_needle "$cd/enroll.log" "$NEEDLE_UNLOCK" "$label-enroll" + + if [ "$label" = signed ]; then + echo "==> Secure Boot case signed: booting the signed update again" + install_case_uki "$cd" "$UKI_SIGNED" + boot_case signed "$SIGNED_LOG" "$cd" "$NEEDLE_UNLOCK" + assert_needle "$SIGNED_LOG" "$NEEDLE_UNLOCK" signed + assert_no_needle "$SIGNED_LOG" "$NEEDLE_FAILED" signed + else + echo "==> Secure Boot case unknown: booting the unknown PCR-key UKI" + install_case_uki "$cd" "$UKI_UNKNOWN" + boot_case unknown "$UNKNOWN_LOG" "$cd" "$NEEDLE_FAILED" + assert_needle "$UNKNOWN_LOG" "$NEEDLE_PCR" unknown + assert_needle "$UNKNOWN_LOG" "$NEEDLE_FAILED" unknown + assert_no_needle "$UNKNOWN_LOG" "$NEEDLE_UNLOCK" unknown + fi + kill "$(cat "$tpm/swtpm.pid")" 2>/dev/null || true + done + echo "Secure Boot serial logs: $SIGNED_LOG, $UNKNOWN_LOG" +} + +secureboot_cases From f1ce962c18962ccf05c94fad5f53583ddf159761 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sat, 28 Nov 2026 01:19:14 -0500 Subject: [PATCH 02/23] fix(boot): write serial needles directly to /dev/console Explicit StandardOutput=console and StandardError=console bypass journald forwarding during early boot. Also upload nested enroll logs on failure. --- .github/workflows/build.yml | 1 + files/config/systemd/mjolnir-state-unlocked.service | 8 ++++---- files/config/systemd/mjolnir-state-unseal-failed.service | 8 ++++---- tests/test_units.py | 4 ++-- testsuite/README.md | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d392663..9c77ddc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -180,6 +180,7 @@ jobs: path: | ${{ runner.temp }}/mjolnir-boot-test/secureboot-signed.log ${{ runner.temp }}/mjolnir-boot-test/secureboot-unknown.log + ${{ runner.temp }}/mjolnir-boot-test/secureboot-*/enroll.log if-no-files-found: warn retention-days: 90 diff --git a/files/config/systemd/mjolnir-state-unlocked.service b/files/config/systemd/mjolnir-state-unlocked.service index 1ec2064..6a88354 100644 --- a/files/config/systemd/mjolnir-state-unlocked.service +++ b/files/config/systemd/mjolnir-state-unlocked.service @@ -7,11 +7,11 @@ RequiresMountsFor=/var/lib/mjolnir [Service] Type=oneshot RemainAfterExit=yes -# journal+console writes straight to /dev/console; the needle is not subject to -# journald forwarding settings or console log level. +# console writes straight to /dev/console. Journal forwarding is not reliable +# during early boot in the VM, so the needle must bypass journald entirely. ExecStart=/usr/bin/echo MjolnirState: unlocked -StandardOutput=journal+console -StandardError=journal+console +StandardOutput=console +StandardError=console [Install] WantedBy=local-fs.target diff --git a/files/config/systemd/mjolnir-state-unseal-failed.service b/files/config/systemd/mjolnir-state-unseal-failed.service index 2b4a155..879eb07 100644 --- a/files/config/systemd/mjolnir-state-unseal-failed.service +++ b/files/config/systemd/mjolnir-state-unseal-failed.service @@ -4,9 +4,9 @@ DefaultDependencies=no [Service] Type=oneshot -# The failure happens in the initramfs, before switch-root. Both needles are -# emitted by systemd itself, not by a shell or interpreter. +# The failure happens in the initramfs, before switch-root. Both needles go +# straight to /dev/console; journald forwarding is not available yet. ExecStart=/usr/bin/echo PCR policy ExecStart=/usr/bin/echo Failed to unseal -StandardOutput=journal+console -StandardError=journal+console +StandardOutput=console +StandardError=console diff --git a/tests/test_units.py b/tests/test_units.py index 5c0b57c..e46cc8b 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -83,12 +83,12 @@ def require(relative: str, needle: str, label: str) -> None: require(unlocked, "ExecStart=/usr/bin/echo MjolnirState: unlocked", "unlock needle") require(unlocked, "After=var-lib-mjolnir.mount", "unlock ordering") - require(unlocked, "StandardOutput=journal+console", "console output") + require(unlocked, "StandardOutput=console", "console output") require("files/config/presets/80-mjolnir.preset", "enable mjolnir-state-unlocked.service", "unlock preset") require(failed, "ExecStart=/usr/bin/echo PCR policy", "PCR needle") require(failed, "ExecStart=/usr/bin/echo Failed to unseal", "unseal failure needle") - require(failed, "StandardOutput=journal+console", "console output") + require(failed, "StandardOutput=console", "console output") require(dropin, "OnFailure=mjolnir-state-unseal-failed.service", "failure wiring") require(dracut, "mjolnir-state-unseal-failed.service", "initramfs failure unit") require(dracut, "10-mjolnir-failure.conf", "initramfs drop-in") diff --git a/testsuite/README.md b/testsuite/README.md index 3dd686f..c531a7d 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -48,8 +48,8 @@ enabled by the preset. A drop-in for `systemd-cryptsetup@mjolnir-state.service` wires `OnFailure=` to `mjolnir-state-unseal-failed.service`; that unit and the drop-in are installed in both the rootfs and the initramfs because the PCR miss fails cryptsetup before switch-root. Both units use -`StandardOutput=journal+console` so the strings reach the serial log -regardless of journald forwarding settings. +`StandardOutput=console` so the strings reach `/dev/console` directly; journald +forwarding is not reliable during early boot in the VM. ### Fixtures From f267bf245ad7bf30af5c4303f9c7a08a22c993f4 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sat, 28 Nov 2026 05:13:28 -0500 Subject: [PATCH 03/23] fix(boot): make Secure Boot cases unlock a provisioned state The serial needles never reached the serial log for two reasons. First, a bare 'StandardOutput=console' is not a valid systemd specifier: systemd rejects it and falls back to the journal, so use journal+console (journald console forwarding is enabled by the signed cmdline). Second, the case disk had never been booted, so systemd-repart had not created MjolnirState by the time the initramfs cryptsetup timed out waiting for it; var-lib-mjolnir.mount then hung forever and the unlock unit never ran. Boot the installed disk once before the cases so repart creates and encrypts the state partition; the cases then enroll it with the signed fixture and assert the needles as before. Tighten the static contract and docs so neither regression returns. --- .../systemd/mjolnir-state-unlocked.service | 10 ++-- .../mjolnir-state-unseal-failed.service | 9 +-- tests/test_units.py | 14 ++++- testsuite/README.md | 20 ++++--- testsuite/boot/test-boot.sh | 58 +++++++++++++++++++ 5 files changed, 94 insertions(+), 17 deletions(-) diff --git a/files/config/systemd/mjolnir-state-unlocked.service b/files/config/systemd/mjolnir-state-unlocked.service index 6a88354..a8119d3 100644 --- a/files/config/systemd/mjolnir-state-unlocked.service +++ b/files/config/systemd/mjolnir-state-unlocked.service @@ -7,11 +7,13 @@ RequiresMountsFor=/var/lib/mjolnir [Service] Type=oneshot RemainAfterExit=yes -# console writes straight to /dev/console. Journal forwarding is not reliable -# during early boot in the VM, so the needle must bypass journald entirely. +# `console` alone is not a valid systemd output specifier: systemd rejects it +# and silently falls back to the journal, which loses the needle on serial. +# `journal+console` is valid and the signed cmdline enables journald console +# forwarding, so the echo reaches ttyS0. ExecStart=/usr/bin/echo MjolnirState: unlocked -StandardOutput=console -StandardError=console +StandardOutput=journal+console +StandardError=journal+console [Install] WantedBy=local-fs.target diff --git a/files/config/systemd/mjolnir-state-unseal-failed.service b/files/config/systemd/mjolnir-state-unseal-failed.service index 879eb07..12144a4 100644 --- a/files/config/systemd/mjolnir-state-unseal-failed.service +++ b/files/config/systemd/mjolnir-state-unseal-failed.service @@ -4,9 +4,10 @@ DefaultDependencies=no [Service] Type=oneshot -# The failure happens in the initramfs, before switch-root. Both needles go -# straight to /dev/console; journald forwarding is not available yet. +# The failure happens in the initramfs, before switch-root. `console` alone is +# not a valid systemd output specifier, so use `journal+console`: journald is +# running in the initramfs and the signed cmdline forwards it to ttyS0. ExecStart=/usr/bin/echo PCR policy ExecStart=/usr/bin/echo Failed to unseal -StandardOutput=console -StandardError=console +StandardOutput=journal+console +StandardError=journal+console diff --git a/tests/test_units.py b/tests/test_units.py index e46cc8b..7d7c71d 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -83,18 +83,28 @@ def require(relative: str, needle: str, label: str) -> None: require(unlocked, "ExecStart=/usr/bin/echo MjolnirState: unlocked", "unlock needle") require(unlocked, "After=var-lib-mjolnir.mount", "unlock ordering") - require(unlocked, "StandardOutput=console", "console output") require("files/config/presets/80-mjolnir.preset", "enable mjolnir-state-unlocked.service", "unlock preset") require(failed, "ExecStart=/usr/bin/echo PCR policy", "PCR needle") require(failed, "ExecStart=/usr/bin/echo Failed to unseal", "unseal failure needle") - require(failed, "StandardOutput=console", "console output") + # A bare `console` is not a valid StandardOutput= specifier: systemd drops + # it and the needle never reaches the serial log. Both units must forward + # through journald *and* the console (enabled by the signed cmdline). + for unit in (unlocked, failed): + require(unit, "StandardOutput=journal+console", "journal+console output") + require(unit, "StandardError=journal+console", "journal+console error output") + for key in ("StandardOutput", "StandardError"): + if re.search(rf"^{key}=console\s*$", text_at(unit), re.MULTILINE): + errors.append(f"{unit}: invalid bare '{key}=console' specifier") require(dropin, "OnFailure=mjolnir-state-unseal-failed.service", "failure wiring") require(dracut, "mjolnir-state-unseal-failed.service", "initramfs failure unit") require(dracut, "10-mjolnir-failure.conf", "initramfs drop-in") require(dracut, "/usr/bin/echo", "initramfs echo binary") for needle in ("MjolnirState: unlocked", "PCR policy", "Failed to unseal"): require(boot, needle, "boot assertion needle") + # The cases start from a disk whose encrypted state partition already + # exists; otherwise repart creates it after cryptsetup has timed out. + require(boot, "provision_state_partition", "state partition provisioning") # Lid switches must never suspend an unattended node. logind = ROOT / "files/config/logind/50-ignore-lid.conf" diff --git a/testsuite/README.md b/testsuite/README.md index c531a7d..9f9b482 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -31,11 +31,15 @@ KVM, QEMU, OVMF and `objcopy`. The Secure Boot cases additionally need `swtpm`. ## Secure Boot unlock cases -`boot/test-boot.sh` appends two cases after the OVMF check above. Each case -copies the installed disk and gets its own copy of the enrolled OVMF variable -store and its own swtpm state directory, so a failed unseal in one case cannot -leak into the other. Both cases first boot `uki-signed.efi` to establish the -TPM2 enrollment, then reboot with the case's update: +`boot/test-boot.sh` appends two cases after the OVMF check above. First it +boots the installed disk once with its own signed entry so systemd-repart can +create the encrypted `MjolnirState` partition: repart runs only after +switch-root, so the initramfs cryptsetup cannot see the partition on a disk +that has never been booted. Each case then copies that provisioned disk and +gets its own copy of the enrolled OVMF variable store and its own swtpm state +directory, so a failed unseal in one case cannot leak into the other. Both +cases first boot `uki-signed.efi` to establish the TPM2 enrollment, then reboot +with the case's update: | Case | Update installed in the ESP | Required serial evidence | | --- | --- | --- | @@ -48,8 +52,10 @@ enabled by the preset. A drop-in for `systemd-cryptsetup@mjolnir-state.service` wires `OnFailure=` to `mjolnir-state-unseal-failed.service`; that unit and the drop-in are installed in both the rootfs and the initramfs because the PCR miss fails cryptsetup before switch-root. Both units use -`StandardOutput=console` so the strings reach `/dev/console` directly; journald -forwarding is not reliable during early boot in the VM. +`StandardOutput=journal+console` / `StandardError=journal+console`; a bare +`console` specifier is invalid in systemd and is silently dropped. The signed +cmdline enables journald forwarding to `ttyS0`, so the needles reach the serial +log both before and after switch-root. ### Fixtures diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 09e93cb..e824f57 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -263,6 +263,63 @@ GRACE="${GRACE_SECONDS:-10}" CASE_LOOPS=() CASE_QEMU_PIDS=() +# Poll the disk while the VM runs until systemd-repart has both created the +# MjolnirState partition and written its LUKS2 header. Reattach a fresh loop +# node on each pass so the new partition table is visible to the host. +wait_for_state_partition() { + local disk="$1" limit="${2:-180}" loop part elapsed=0 + while [ "$elapsed" -lt "$limit" ]; do + if loop=$(sudo losetup -f --show -P "$disk" 2>/dev/null); then + for part in "${loop}"p*; do + [ -b "$part" ] || continue + [ "$(sudo blkid -p -o value -s PARTLABEL "$part" 2>/dev/null || true)" = "MjolnirState" ] || continue + if [ "$(sudo blkid -p -o value -s TYPE "$part" 2>/dev/null || true)" = "crypto_LUKS" ]; then + sudo losetup -d "$loop" 2>/dev/null || true + # The LUKS header appears before repart finishes creating the + # filesystem inside it. Give that work time to land on the disk + # before the VM is stopped; observed repart work takes under 10s. + sleep 30 + return 0 + fi + done + sudo losetup -d "$loop" 2>/dev/null || true + fi + sleep 2 + elapsed=$((elapsed + 2)) + done + return 1 +} + +# bootc --run-repart leaves MjolnirState for systemd-repart on first boot, and +# repart only runs after switch-root. The initramfs cryptsetup has already +# timed out by then, so a first boot never mounts state and the unlock needle +# cannot fire. Boot the installed disk once with its own signed entry (no +# fixtures, no swtpm) to let the image's repart.d create the empty-key LUKS2 +# partition. Each case then starts from that disk and enrolls its TPM slot on +# the first fixture boot, which is what the two cases below assert. +provision_state_partition() { + local log="$WORK/state-provision.log" pid + echo "==> provisioning MjolnirState: boot once so repart creates the encrypted partition" + sudo qemu-system-x86_64 \ + -m 2048 -smp 2 -enable-kvm -nographic \ + -drive if=pflash,format=raw,unit=0,file="$WORK/code.fd",readonly=on \ + -drive if=pflash,format=raw,unit=1,file="$WORK/vars.fd" \ + -drive file="$WORK/disk.raw",format=raw,media=disk \ + -smbios type=11,value=io.systemd.credential:mjolnir.boot-report=1 \ + -smbios "type=11,value=io.systemd.credential.binary:varlink-httpd.tls.trust=$CA_B64" \ + -netdev user,id=net0 -device virtio-net-pci,netdev=net0 \ + >"$log" 2>&1 & + pid=$! + CASE_QEMU_PIDS+=("$pid") + if ! wait_for_state_partition "$WORK/disk.raw"; then + tail -60 "$log" >&2 || true + fail "systemd-repart did not create an encrypted MjolnirState partition" + fi + kill "$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true + pass "MjolnirState partition created by the image's systemd-repart" +} + assert_needle() { local log="$1" needle="$2" label="$3" grep -aqF "$needle" "$log" || fail "$label: missing serial needle '$needle' in $log" @@ -351,6 +408,7 @@ secureboot_cases() { return 0 fi need "$SWTPM" + provision_state_partition for label in signed unknown; do cd="$WORK/secureboot-$label" From 53dcd6254cdfba7b545f237dce4db80274e2e799 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sat, 28 Nov 2026 22:45:29 -0500 Subject: [PATCH 04/23] fix(boot): wait for a formatted state partition in the boot harness The provisioning check used 'blkid -p', which does not report PARTLABEL, so it never saw the MjolnirState partition. Use the cached blkid query and require a btrfs superblock inside the empty-key LUKS container before stopping the VM, so repart has finished formatting rather than only written the header. Install cryptsetup-bin on the runner for that probe. --- .github/workflows/build.yml | 2 +- testsuite/boot/test-boot.sh | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9c77ddc..a8d6ea7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -169,7 +169,7 @@ jobs: FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures run: | sudo apt-get update -qq - sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm + sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm cryptsetup-bin just boot-test - name: Upload Secure Boot serial logs diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index e824f57..3665631 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -263,23 +263,27 @@ GRACE="${GRACE_SECONDS:-10}" CASE_LOOPS=() CASE_QEMU_PIDS=() -# Poll the disk while the VM runs until systemd-repart has both created the -# MjolnirState partition and written its LUKS2 header. Reattach a fresh loop -# node on each pass so the new partition table is visible to the host. +# Poll the disk while the VM runs until systemd-repart has created the +# MjolnirState partition *and* formatted the filesystem inside it. Reattach a +# fresh loop node on each pass so the new partition table is visible to the +# host. Note that `blkid -p` does not report PARTLABEL: use the cached form as +# the rest of this script does. The LUKS header appears well before mkfs, so +# open it with the empty key the image uses and wait for a btrfs superblock. wait_for_state_partition() { - local disk="$1" limit="${2:-180}" loop part elapsed=0 + local disk="$1" limit="${2:-240}" loop part elapsed=0 while [ "$elapsed" -lt "$limit" ]; do if loop=$(sudo losetup -f --show -P "$disk" 2>/dev/null); then for part in "${loop}"p*; do [ -b "$part" ] || continue - [ "$(sudo blkid -p -o value -s PARTLABEL "$part" 2>/dev/null || true)" = "MjolnirState" ] || continue - if [ "$(sudo blkid -p -o value -s TYPE "$part" 2>/dev/null || true)" = "crypto_LUKS" ]; then - sudo losetup -d "$loop" 2>/dev/null || true - # The LUKS header appears before repart finishes creating the - # filesystem inside it. Give that work time to land on the disk - # before the VM is stopped; observed repart work takes under 10s. - sleep 30 - return 0 + [ "$(sudo blkid -o value -s PARTLABEL "$part" 2>/dev/null || true)" = "MjolnirState" ] || continue + [ "$(sudo blkid -o value -s TYPE "$part" 2>/dev/null || true)" = "crypto_LUKS" ] || continue + if sudo cryptsetup luksOpen --key-file /dev/null "$part" mjolnir-probe >/dev/null 2>&1; then + if [ "$(sudo blkid -p -o value -s TYPE /dev/mapper/mjolnir-probe 2>/dev/null || true)" = "btrfs" ]; then + sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true + sudo losetup -d "$loop" 2>/dev/null || true + return 0 + fi + sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true fi done sudo losetup -d "$loop" 2>/dev/null || true From 30887c182dcf1fa39ac36ea866899ed8fdd18b24 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sat, 28 Nov 2026 23:30:34 -0500 Subject: [PATCH 05/23] fix(boot): provision state with the image's repart definition The guest's systemd-repart never finished in the boot harness (the job stays active past four minutes), so waiting for it from a provisioning VM is not workable. Apply the image's own 20-mjolnir-state.conf on the host with systemd-repart and an empty key, then verify the LUKS2 container holds a btrfs filesystem before starting the cases. This is deterministic, uses the same definition the image ships, and keeps the needle assertions unchanged. --- testsuite/README.md | 4 +- testsuite/boot/test-boot.sh | 90 +++++++++++++++---------------------- 2 files changed, 37 insertions(+), 57 deletions(-) diff --git a/testsuite/README.md b/testsuite/README.md index 9f9b482..34fff52 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -32,8 +32,8 @@ KVM, QEMU, OVMF and `objcopy`. The Secure Boot cases additionally need `swtpm`. ## Secure Boot unlock cases `boot/test-boot.sh` appends two cases after the OVMF check above. First it -boots the installed disk once with its own signed entry so systemd-repart can -create the encrypted `MjolnirState` partition: repart runs only after +applies the image's own `repart.d` definition to the installed disk on the host +so `MjolnirState` already has its empty-key LUKS2 slot: repart runs only after switch-root, so the initramfs cryptsetup cannot see the partition on a disk that has never been booted. Each case then copies that provisioned disk and gets its own copy of the enrolled OVMF variable store and its own swtpm state diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 3665631..34b4fed 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -263,65 +263,45 @@ GRACE="${GRACE_SECONDS:-10}" CASE_LOOPS=() CASE_QEMU_PIDS=() -# Poll the disk while the VM runs until systemd-repart has created the -# MjolnirState partition *and* formatted the filesystem inside it. Reattach a -# fresh loop node on each pass so the new partition table is visible to the -# host. Note that `blkid -p` does not report PARTLABEL: use the cached form as -# the rest of this script does. The LUKS header appears well before mkfs, so -# open it with the empty key the image uses and wait for a btrfs superblock. -wait_for_state_partition() { - local disk="$1" limit="${2:-240}" loop part elapsed=0 - while [ "$elapsed" -lt "$limit" ]; do - if loop=$(sudo losetup -f --show -P "$disk" 2>/dev/null); then - for part in "${loop}"p*; do - [ -b "$part" ] || continue - [ "$(sudo blkid -o value -s PARTLABEL "$part" 2>/dev/null || true)" = "MjolnirState" ] || continue - [ "$(sudo blkid -o value -s TYPE "$part" 2>/dev/null || true)" = "crypto_LUKS" ] || continue - if sudo cryptsetup luksOpen --key-file /dev/null "$part" mjolnir-probe >/dev/null 2>&1; then - if [ "$(sudo blkid -p -o value -s TYPE /dev/mapper/mjolnir-probe 2>/dev/null || true)" = "btrfs" ]; then - sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true - sudo losetup -d "$loop" 2>/dev/null || true - return 0 - fi - sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true - fi - done - sudo losetup -d "$loop" 2>/dev/null || true - fi - sleep 2 - elapsed=$((elapsed + 2)) - done - return 1 -} - # bootc --run-repart leaves MjolnirState for systemd-repart on first boot, and # repart only runs after switch-root. The initramfs cryptsetup has already # timed out by then, so a first boot never mounts state and the unlock needle -# cannot fire. Boot the installed disk once with its own signed entry (no -# fixtures, no swtpm) to let the image's repart.d create the empty-key LUKS2 -# partition. Each case then starts from that disk and enrolls its TPM slot on -# the first fixture boot, which is what the two cases below assert. +# cannot fire. Apply the image's own repart.d definition to the installed disk +# on the host instead: this creates the empty-key LUKS2 partition that each +# case then enrolls with the signed fixture on its first boot. provision_state_partition() { - local log="$WORK/state-provision.log" pid - echo "==> provisioning MjolnirState: boot once so repart creates the encrypted partition" - sudo qemu-system-x86_64 \ - -m 2048 -smp 2 -enable-kvm -nographic \ - -drive if=pflash,format=raw,unit=0,file="$WORK/code.fd",readonly=on \ - -drive if=pflash,format=raw,unit=1,file="$WORK/vars.fd" \ - -drive file="$WORK/disk.raw",format=raw,media=disk \ - -smbios type=11,value=io.systemd.credential:mjolnir.boot-report=1 \ - -smbios "type=11,value=io.systemd.credential.binary:varlink-httpd.tls.trust=$CA_B64" \ - -netdev user,id=net0 -device virtio-net-pci,netdev=net0 \ - >"$log" 2>&1 & - pid=$! - CASE_QEMU_PIDS+=("$pid") - if ! wait_for_state_partition "$WORK/disk.raw"; then - tail -60 "$log" >&2 || true - fail "systemd-repart did not create an encrypted MjolnirState partition" - fi - kill "$pid" 2>/dev/null || true - wait "$pid" 2>/dev/null || true - pass "MjolnirState partition created by the image's systemd-repart" + local defs="$WORK/repart-state" loop part found=0 + echo "==> provisioning MjolnirState from the image's repart.d definition" + mkdir -p "$defs" + sudo podman cp "mjolnir-boot-src:/usr/lib/repart.d/20-mjolnir-state.conf" \ + "$defs/" || fail "cannot copy the image's MjolnirState definition" + loop=$(sudo losetup -f --show -P "$WORK/disk.raw") || \ + fail "cannot attach the installed disk for provisioning" + CASE_LOOPS+=("$loop") + sudo systemd-repart --definitions="$defs" --discard=no --key-file=/dev/null \ + "$loop" || fail "systemd-repart could not provision MjolnirState" + # The partition table changed underneath the loop device: reattach so the + # new partition node exists before the checks below. + sudo losetup -d "$loop" || true + loop=$(sudo losetup -f --show -P "$WORK/disk.raw") || \ + fail "cannot reattach the provisioned disk" + CASE_LOOPS+=("$loop") + for part in "${loop}"p*; do + [ -b "$part" ] || continue + [ "$(sudo blkid -o value -s PARTLABEL "$part" 2>/dev/null || true)" = "MjolnirState" ] || continue + found=1 + [ "$(sudo blkid -p -o value -s TYPE "$part" 2>/dev/null || true)" = "crypto_LUKS" ] || \ + fail "MjolnirState is not a LUKS2 partition" + sudo cryptsetup luksOpen --key-file /dev/null "$part" mjolnir-probe >/dev/null 2>&1 || \ + fail "cannot unlock MjolnirState with the empty key" + if [ "$(sudo blkid -p -o value -s TYPE /dev/mapper/mjolnir-probe 2>/dev/null || true)" != "btrfs" ]; then + sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true + fail "MjolnirState is not formatted as btrfs" + fi + sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true + done + [ "$found" -eq 1 ] || fail "systemd-repart did not create MjolnirState" + pass "MjolnirState provisioned from the image's repart.d definition" } assert_needle() { From d21130fe7ea65ec8d5876333e537f59a438a9f81 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 00:12:57 -0500 Subject: [PATCH 06/23] ci(boot): install systemd-repart on the runner Ubuntu 26.04 ships systemd-repart as a separate package; without it the host-side state provisioning step fails with 'command not found'. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8d6ea7..802a938 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -169,7 +169,7 @@ jobs: FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures run: | sudo apt-get update -qq - sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm cryptsetup-bin + sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm cryptsetup-bin systemd-repart just boot-test - name: Upload Secure Boot serial logs From e82f44e1601c018c6418b01cd4a73717311a6c00 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 00:45:59 -0500 Subject: [PATCH 07/23] fix(boot): make host repartitioning actually apply systemd-repart defaults to a dry run on a loop-backed image and only printed the planned partition. Pass --dry-run=no so the image's MjolnirState definition is written to the disk the cases copy. --- testsuite/boot/test-boot.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 34b4fed..9f26a1e 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -278,8 +278,10 @@ provision_state_partition() { loop=$(sudo losetup -f --show -P "$WORK/disk.raw") || \ fail "cannot attach the installed disk for provisioning" CASE_LOOPS+=("$loop") - sudo systemd-repart --definitions="$defs" --discard=no --key-file=/dev/null \ - "$loop" || fail "systemd-repart could not provision MjolnirState" + # On a loop-backed disk repart defaults to dry-run; require it to apply. + sudo systemd-repart --definitions="$defs" --dry-run=no --discard=no \ + --key-file=/dev/null "$loop" || \ + fail "systemd-repart could not provision MjolnirState" # The partition table changed underneath the loop device: reattach so the # new partition node exists before the checks below. sudo losetup -d "$loop" || true From 95265dadfe8466371123a68007c8fbdc4d05f3f1 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 01:07:06 -0500 Subject: [PATCH 08/23] fix(boot): use the empty key when provisioning state Passing --key-file=/dev/null to systemd-repart makes it encrypt with a different key than the image's first boot, so the harness could not open the LUKS2 slot with the empty password used by crypttab. Omit --key-file so Encrypt=key-file uses the empty key. --- testsuite/boot/test-boot.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 9f26a1e..1b35364 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -279,9 +279,12 @@ provision_state_partition() { fail "cannot attach the installed disk for provisioning" CASE_LOOPS+=("$loop") # On a loop-backed disk repart defaults to dry-run; require it to apply. + # No --key-file: the definition's Encrypt=key-file then uses the empty key, + # exactly as systemd-repart.service does on the image's first boot. Passing + # an empty key file here instead produces a slot cryptsetup cannot open with + # try-empty-password. sudo systemd-repart --definitions="$defs" --dry-run=no --discard=no \ - --key-file=/dev/null "$loop" || \ - fail "systemd-repart could not provision MjolnirState" + "$loop" || fail "systemd-repart could not provision MjolnirState" # The partition table changed underneath the loop device: reattach so the # new partition node exists before the checks below. sudo losetup -d "$loop" || true From 5ce3ac29f64bf8f225d105182d229d9a6e613197 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 01:40:54 -0500 Subject: [PATCH 09/23] fix(boot): let the cases prove the empty-key unlock The host-side cryptsetup probe is not needed: systemd-repart documents that Encrypt=key-file with no --key-file uses the zero-length key, and repart's own log already proves the LUKS2 partition was formatted. Drop the brittle probe; the signed and unknown boot cases are the real proof that the guest can unlock (or fail to unseal). --- .github/workflows/build.yml | 2 +- testsuite/boot/test-boot.sh | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 802a938..d80ac75 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -169,7 +169,7 @@ jobs: FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures run: | sudo apt-get update -qq - sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm cryptsetup-bin systemd-repart + sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm systemd-repart just boot-test - name: Upload Secure Boot serial logs diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 1b35364..90d3bcb 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -279,14 +279,13 @@ provision_state_partition() { fail "cannot attach the installed disk for provisioning" CASE_LOOPS+=("$loop") # On a loop-backed disk repart defaults to dry-run; require it to apply. - # No --key-file: the definition's Encrypt=key-file then uses the empty key, - # exactly as systemd-repart.service does on the image's first boot. Passing - # an empty key file here instead produces a slot cryptsetup cannot open with - # try-empty-password. + # No --key-file: systemd-repart then uses the empty key (documented behavior + # of Encrypt=key-file), exactly as it does on the image's first boot. The + # cases below prove the guest can actually unlock it with try-empty-password. sudo systemd-repart --definitions="$defs" --dry-run=no --discard=no \ "$loop" || fail "systemd-repart could not provision MjolnirState" # The partition table changed underneath the loop device: reattach so the - # new partition node exists before the checks below. + # new partition node exists before the check below. sudo losetup -d "$loop" || true loop=$(sudo losetup -f --show -P "$WORK/disk.raw") || \ fail "cannot reattach the provisioned disk" @@ -297,13 +296,6 @@ provision_state_partition() { found=1 [ "$(sudo blkid -p -o value -s TYPE "$part" 2>/dev/null || true)" = "crypto_LUKS" ] || \ fail "MjolnirState is not a LUKS2 partition" - sudo cryptsetup luksOpen --key-file /dev/null "$part" mjolnir-probe >/dev/null 2>&1 || \ - fail "cannot unlock MjolnirState with the empty key" - if [ "$(sudo blkid -p -o value -s TYPE /dev/mapper/mjolnir-probe 2>/dev/null || true)" != "btrfs" ]; then - sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true - fail "MjolnirState is not formatted as btrfs" - fi - sudo cryptsetup luksClose mjolnir-probe >/dev/null 2>&1 || true done [ "$found" -eq 1 ] || fail "systemd-repart did not create MjolnirState" pass "MjolnirState provisioned from the image's repart.d definition" From dbb6f17f82183c6c332c02b1e28229b23f1b53a7 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 02:25:59 -0500 Subject: [PATCH 10/23] fix(boot): make first boot non-interactive in the cases The case VMs waited on systemd-firstboot's timezone prompt because /etc is volatile and unpopulated, which stalled local-fs.target so var-lib-mjolnir.mount and the unlock unit never ran. Pass firstboot locale, keymap, timezone, hostname and a test root password as SMBIOS systemd credentials; the signed UKI cmdline is unchanged. --- testsuite/boot/test-boot.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 90d3bcb..7f5211c 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -171,6 +171,12 @@ openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days -keyout "$WORK/ca.key" -out "$WORK/ca.crt" -subj /CN=MjolnirBootTest >/dev/null 2>&1 \ || fail "could not generate the test client CA" CA_B64=$(base64 -w0 "$WORK/ca.crt") || fail "could not encode the test client CA" +# Firstboot must not wait for a human on the console: an unpopulated volatile +# /etc otherwise leaves systemd-firstboot.service prompting for a timezone and +# blocks the local-fs units (including the state mount and unlock needle). +# These are test-only credentials passed through SMBIOS, never image content. +ROOTPW_B64=$(printf %s 'mjolnir-boot-test' | base64 -w0) || \ + fail "could not encode the firstboot test password" timeout 300 sudo qemu-system-x86_64 \ -m 2048 -smp 2 -enable-kvm -nographic \ @@ -353,6 +359,11 @@ boot_case() { -device tpm-tis,tpmdev=tpm0 \ -smbios type=11,value=io.systemd.credential:mjolnir.boot-report=1 \ -smbios "type=11,value=io.systemd.credential.binary:varlink-httpd.tls.trust=$CA_B64" \ + -smbios type=11,value=io.systemd.credential:firstboot.locale=C.UTF-8 \ + -smbios type=11,value=io.systemd.credential:firstboot.keymap=us \ + -smbios type=11,value=io.systemd.credential:firstboot.timezone=UTC \ + -smbios type=11,value=io.systemd.credential:firstboot.hostname=mjolnir \ + -smbios "type=11,value=io.systemd.credential.binary:passwd.plaintext-password.root=$ROOTPW_B64" \ -netdev user,id=net0 -device virtio-net-pci,netdev=net0 \ >"$log" 2>&1 & pid=$! From 1b7eb2feb2a631be7dc2b208bf706facce87d830 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 02:26:16 -0500 Subject: [PATCH 11/23] docs(boot): note firstboot credentials in the harness --- testsuite/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testsuite/README.md b/testsuite/README.md index 34fff52..1b3e5af 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -37,9 +37,11 @@ so `MjolnirState` already has its empty-key LUKS2 slot: repart runs only after switch-root, so the initramfs cryptsetup cannot see the partition on a disk that has never been booted. Each case then copies that provisioned disk and gets its own copy of the enrolled OVMF variable store and its own swtpm state -directory, so a failed unseal in one case cannot leak into the other. Both -cases first boot `uki-signed.efi` to establish the TPM2 enrollment, then reboot -with the case's update: +directory, so a failed unseal in one case cannot leak into the other. The case +VMs receive firstboot settings as SMBIOS systemd credentials (locale, keymap, +timezone, hostname and a throwaway root password) so the interactive firstboot +prompt cannot stall `local-fs.target`. Both cases first boot `uki-signed.efi` to +establish the TPM2 enrollment, then reboot with the case's update: | Case | Update installed in the ESP | Required serial evidence | | --- | --- | --- | From 46fd286479c585074c44e3ffc6f15f8cce9347a0 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 03:04:12 -0500 Subject: [PATCH 12/23] fix(boot): stage state units in factory /etc With systemd.volatile=yes, /etc is reseeded from /usr/share/factory/etc every boot and preset-created symlinks arrive after local-fs.target's initial transaction. The state mount, enrollment and unlock units therefore never ran. Stage their local-fs.target.wants symlinks at build time in factory /etc and assert the wiring statically. --- elements/config/files.bst | 10 ++++++++++ tests/test_units.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/elements/config/files.bst b/elements/config/files.bst index 80dda85..16f51b3 100644 --- a/elements/config/files.bst +++ b/elements/config/files.bst @@ -60,6 +60,16 @@ config: install -Dm644 /config/crictl.yaml "${root}/etc/crictl.yaml" install -Dm644 /config/presets/80-mjolnir.preset \ "${root}/usr/lib/systemd/system-preset/80-mjolnir.preset" + # systemd.volatile=yes seeds /etc from /usr/share/factory/etc on every + # boot. Preset symlinks created once the manager starts are too late for + # local-fs.target's initial transaction, so stage the state wants here as + # well; otherwise var-lib-mjolnir.mount and the needle units never run. + mkdir -p "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants" + for u in var-lib-mjolnir.mount mjolnir-state-enroll.service \ + mjolnir-state-unlocked.service; do + ln -sf "/usr/lib/systemd/system/${u}" \ + "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants/${u}" + done mkdir -p "${root}/usr/lib/systemd/system" cp /config/systemd/*.service /config/systemd/*.socket /config/systemd/*.timer \ "${root}/usr/lib/systemd/system/" 2>/dev/null || true diff --git a/tests/test_units.py b/tests/test_units.py index 7d7c71d..d66ef8b 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -105,6 +105,12 @@ def require(relative: str, needle: str, label: str) -> None: # The cases start from a disk whose encrypted state partition already # exists; otherwise repart creates it after cryptsetup has timed out. require(boot, "provision_state_partition", "state partition provisioning") + # volatile /etc is seeded from factory /etc: the state units must be in + # local-fs.target's wants before the initial transaction is computed. + files_bst = "elements/config/files.bst" + for unit in ("var-lib-mjolnir.mount", "mjolnir-state-enroll.service", + "mjolnir-state-unlocked.service"): + require(files_bst, unit, f"factory local-fs wants for {unit}") # Lid switches must never suspend an unattended node. logind = ROOT / "files/config/logind/50-ignore-lid.conf" From fe5c5d3bd6d42402a1eb9a98d5000d32c69a16b5 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 03:35:01 -0500 Subject: [PATCH 13/23] fix(boot): emit the unlock needle at multi-user target Under systemd.volatile=yes the local-fs.target transaction is computed before preset/factory wants symlinks are honored, so the unlock unit never ran. Gate the needle on the decrypted MjolnirState mapping and run it from multi-user.target, which is reached late enough. Keep the mount and enrollment units in factory local-fs wants, and update the static contract and docs. --- elements/config/files.bst | 8 +++++--- files/config/systemd/mjolnir-state-unlocked.service | 9 ++++++--- tests/test_units.py | 8 +++++--- testsuite/README.md | 6 ++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/elements/config/files.bst b/elements/config/files.bst index 16f51b3..9521ab4 100644 --- a/elements/config/files.bst +++ b/elements/config/files.bst @@ -64,12 +64,14 @@ config: # boot. Preset symlinks created once the manager starts are too late for # local-fs.target's initial transaction, so stage the state wants here as # well; otherwise var-lib-mjolnir.mount and the needle units never run. - mkdir -p "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants" - for u in var-lib-mjolnir.mount mjolnir-state-enroll.service \ - mjolnir-state-unlocked.service; do + mkdir -p "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants" \ + "${root}/usr/share/factory/etc/systemd/system/multi-user.target.wants" + for u in var-lib-mjolnir.mount mjolnir-state-enroll.service; do ln -sf "/usr/lib/systemd/system/${u}" \ "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants/${u}" done + ln -sf /usr/lib/systemd/system/mjolnir-state-unlocked.service \ + "${root}/usr/share/factory/etc/systemd/system/multi-user.target.wants/mjolnir-state-unlocked.service" mkdir -p "${root}/usr/lib/systemd/system" cp /config/systemd/*.service /config/systemd/*.socket /config/systemd/*.timer \ "${root}/usr/lib/systemd/system/" 2>/dev/null || true diff --git a/files/config/systemd/mjolnir-state-unlocked.service b/files/config/systemd/mjolnir-state-unlocked.service index a8119d3..70904fc 100644 --- a/files/config/systemd/mjolnir-state-unlocked.service +++ b/files/config/systemd/mjolnir-state-unlocked.service @@ -1,8 +1,11 @@ [Unit] Description=Report MjolnirState unlock on the serial console DefaultDependencies=no -After=var-lib-mjolnir.mount -RequiresMountsFor=/var/lib/mjolnir +# local-fs.target is reached before preset/factory wants symlinks take effect +# under systemd.volatile=yes. multi-user.target is late enough, and the +# decrypted mapping is the actual proof that the state key unsealed. +After=systemd-cryptsetup@mjolnir-state.service +ConditionPathExists=/dev/disk/by-label/MjolnirState [Service] Type=oneshot @@ -16,4 +19,4 @@ StandardOutput=journal+console StandardError=journal+console [Install] -WantedBy=local-fs.target +WantedBy=multi-user.target diff --git a/tests/test_units.py b/tests/test_units.py index d66ef8b..f1b59fd 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -82,7 +82,8 @@ def require(relative: str, needle: str, label: str) -> None: boot = "testsuite/boot/test-boot.sh" require(unlocked, "ExecStart=/usr/bin/echo MjolnirState: unlocked", "unlock needle") - require(unlocked, "After=var-lib-mjolnir.mount", "unlock ordering") + require(unlocked, "ConditionPathExists=/dev/disk/by-label/MjolnirState", "unlock condition") + require(unlocked, "WantedBy=multi-user.target", "unlock target") require("files/config/presets/80-mjolnir.preset", "enable mjolnir-state-unlocked.service", "unlock preset") require(failed, "ExecStart=/usr/bin/echo PCR policy", "PCR needle") @@ -108,9 +109,10 @@ def require(relative: str, needle: str, label: str) -> None: # volatile /etc is seeded from factory /etc: the state units must be in # local-fs.target's wants before the initial transaction is computed. files_bst = "elements/config/files.bst" - for unit in ("var-lib-mjolnir.mount", "mjolnir-state-enroll.service", - "mjolnir-state-unlocked.service"): + for unit in ("var-lib-mjolnir.mount", "mjolnir-state-enroll.service"): require(files_bst, unit, f"factory local-fs wants for {unit}") + require(files_bst, "multi-user.target.wants/mjolnir-state-unlocked.service", + "factory multi-user wants for unlock needle") # Lid switches must never suspend an unattended node. logind = ROOT / "files/config/logind/50-ignore-lid.conf" diff --git a/testsuite/README.md b/testsuite/README.md index 1b3e5af..1787096 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -49,8 +49,10 @@ establish the TPM2 enrollment, then reboot with the case's update: | unknown | `uki-unknown.efi` | `PCR policy` and `Failed to unseal`, no unlock | The needles come from image units, not from journal text the guest happens to -emit. `mjolnir-state-unlocked.service` runs after `var-lib-mjolnir.mount` and is -enabled by the preset. A drop-in for `systemd-cryptsetup@mjolnir-state.service` +emit. `mjolnir-state-unlocked.service` runs at `multi-user.target` when the +decrypted `MjolnirState` mapping exists; `local-fs.target` is reached before +preset wants symlinks take effect under the volatile root. A drop-in for +`systemd-cryptsetup@mjolnir-state.service` wires `OnFailure=` to `mjolnir-state-unseal-failed.service`; that unit and the drop-in are installed in both the rootfs and the initramfs because the PCR miss fails cryptsetup before switch-root. Both units use From 279f212f6d499369ed58d7251a7ee8d40d256297 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 09:49:48 -0500 Subject: [PATCH 14/23] fix(boot): restart swtpm for each sequential OVMF case boot QEMU sends CMD_SHUTDOWN to swtpm on exit, which unlinks the control socket. The second boot in a Secure Boot case reused the dead socket and failed before the guest started. Start a fresh daemon on the same tpmstate dir before each boot and upload its log on failure. --- .github/workflows/build.yml | 1 + testsuite/boot/test-boot.sh | 41 +++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d80ac75..1a6606d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -181,6 +181,7 @@ jobs: ${{ runner.temp }}/mjolnir-boot-test/secureboot-signed.log ${{ runner.temp }}/mjolnir-boot-test/secureboot-unknown.log ${{ runner.temp }}/mjolnir-boot-test/secureboot-*/enroll.log + ${{ runner.temp }}/mjolnir-boot-test/secureboot-*/tpm/swtpm.log if-no-files-found: warn retention-days: 90 diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 7f5211c..94857ff 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -382,6 +382,35 @@ boot_case() { pass "$label: serial log captured at $log" } +# QEMU sends CMD_SHUTDOWN to swtpm when it exits, so the daemon terminates and +# unlinks its control socket. Every boot therefore needs a fresh daemon on the +# same tpmstate dir: the dir keeps enrollment state while the new process +# resets volatile PCRs, which is what a real reboot does. +start_swtpm() { + local cd="$1" tpm label old + tpm="$cd/tpm" + label=${cd##*/} + if [ -f "$tpm/swtpm.pid" ]; then + old=$(cat "$tpm/swtpm.pid") + # The pid file can outlive the daemon QEMU shut down. Never signal a pid + # that the kernel may have recycled for an unrelated process. + if kill -0 "$old" 2>/dev/null && + tr '\0' ' ' <"/proc/$old/cmdline" 2>/dev/null | grep -q swtpm; then + kill "$old" 2>/dev/null || true + fi + fi + rm -f "$tpm/swtpm.pid" "$tpm/swtpm.sock" + "$SWTPM" socket --tpmstate "dir=$tpm" \ + --ctrl "type=unixio,path=$tpm/swtpm.sock" \ + --pid "file=$tpm/swtpm.pid" --tpm2 --daemon \ + --log "file=$tpm/swtpm.log" || fail "swtpm did not start for $label" + for _ in $(seq 1 50); do + [ -S "$tpm/swtpm.sock" ] && break + sleep 0.1 + done + [ -S "$tpm/swtpm.sock" ] || fail "swtpm socket did not appear for $label" +} + secureboot_cases() { local missing=0 f label cd tpm for f in "$VARS_ENROLLED" "$UKI_SIGNED" "$UKI_UNKNOWN"; do @@ -412,27 +441,21 @@ secureboot_cases() { echo "==> Secure Boot case $label: enrolling state with the signed UKI" install_case_uki "$cd" "$UKI_SIGNED" - "$SWTPM" socket --tpmstate "dir=$tpm" \ - --ctrl "type=unixio,path=$tpm/swtpm.sock" \ - --pid "file=$tpm/swtpm.pid" --tpm2 --daemon || fail "swtpm did not start for $label" - for _ in $(seq 1 50); do - [ -S "$tpm/swtpm.sock" ] && break - sleep 0.1 - done - [ -S "$tpm/swtpm.sock" ] || fail "swtpm socket did not appear for $label" - + start_swtpm "$cd" boot_case "$label-enroll" "$cd/enroll.log" "$cd" "$NEEDLE_UNLOCK" assert_needle "$cd/enroll.log" "$NEEDLE_UNLOCK" "$label-enroll" if [ "$label" = signed ]; then echo "==> Secure Boot case signed: booting the signed update again" install_case_uki "$cd" "$UKI_SIGNED" + start_swtpm "$cd" boot_case signed "$SIGNED_LOG" "$cd" "$NEEDLE_UNLOCK" assert_needle "$SIGNED_LOG" "$NEEDLE_UNLOCK" signed assert_no_needle "$SIGNED_LOG" "$NEEDLE_FAILED" signed else echo "==> Secure Boot case unknown: booting the unknown PCR-key UKI" install_case_uki "$cd" "$UKI_UNKNOWN" + start_swtpm "$cd" boot_case unknown "$UNKNOWN_LOG" "$cd" "$NEEDLE_FAILED" assert_needle "$UNKNOWN_LOG" "$NEEDLE_PCR" unknown assert_needle "$UNKNOWN_LOG" "$NEEDLE_FAILED" unknown From 2ec3f9bd8b1a669e568ec8b2cc4bc7873df123b5 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 09:53:23 -0500 Subject: [PATCH 15/23] fix(ci): verify downloaded Secure Boot fixtures against SHA256SUMS The fixtures release tag is republished in place on every successful testing build. Download its SHA256SUMS alongside the three assets and check them before any boot case consumes the files. --- .github/workflows/build.yml | 6 +++++- tests/test_secureboot_fixtures.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a6606d..604efb3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -157,9 +157,13 @@ jobs: echo "The Secure Boot swtpm cases will record a SKIP." exit 0 fi - for fixture in OVMF_VARS.enrolled.fd uki-signed.efi uki-unknown.efi; do + for fixture in OVMF_VARS.enrolled.fd uki-signed.efi uki-unknown.efi SHA256SUMS; do curl -fsSL "$FIXTURE_BASE_URL/$fixture" -o "$FIXTURE_DIR/$fixture" done + # The release tag is republished in place on every successful + # testing build, so verify the downloaded bytes against the + # release's own manifest before a boot case consumes them. + (cd "$FIXTURE_DIR" && sha256sum -c SHA256SUMS) # The install checks that bootc accepts the signed digest, and the OVMF # boot checks that the shell-free initramfs actually mounts the composefs diff --git a/tests/test_secureboot_fixtures.py b/tests/test_secureboot_fixtures.py index e3f1867..f2acf21 100644 --- a/tests/test_secureboot_fixtures.py +++ b/tests/test_secureboot_fixtures.py @@ -57,6 +57,10 @@ def main() -> int: generate_block = generate_block.split(" - name: Upload Secure Boot fixtures", 1)[0] if "if:" in generate_block: errors.append("fixture generation must run on PRs so the image gate exercises it") + provision_block = workflow.split(" - name: Provision Secure Boot fixtures", 1)[1] + provision_block = provision_block.split(" # The install checks", 1)[0] + if "SHA256SUMS" not in provision_block or "sha256sum -c" not in provision_block: + errors.append("downloaded fixtures are not verified against SHA256SUMS") docs = read("docs/SECUREBOOT-FIXTURES.md") if BASE_URL not in docs or not all(f in docs for f in ASSETS): From 266b0d535a0c07ea1476cfd87ba381220a190e3f Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 10:38:10 -0500 Subject: [PATCH 16/23] fix(boot): initialize the TPM state before each swtpm case A bare swtpm socket on a fresh state directory leaves libtpms in failure mode, so the guest reports AES-128-CFB missing and never enrolls the state against the signed PCR policy. Manufacture the TPM once per case with swtpm_setup, pass not-need-init, and install swtpm-tools in CI. --- .github/workflows/build.yml | 2 +- testsuite/boot/test-boot.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 604efb3..9bc086f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -173,7 +173,7 @@ jobs: FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures run: | sudo apt-get update -qq - sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm systemd-repart + sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm swtpm-tools systemd-repart just boot-test - name: Upload Secure Boot serial logs diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 94857ff..192aa9b 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -261,6 +261,7 @@ UKI_UNKNOWN="${UKI_UNKNOWN:-$FIXTURE_DIR/uki-unknown.efi}" SIGNED_LOG="${SIGNED_LOG:-$WORK/secureboot-signed.log}" UNKNOWN_LOG="${UNKNOWN_LOG:-$WORK/secureboot-unknown.log}" SWTPM="${SWTPM:-swtpm}" +SWTPM_SETUP="${SWTPM_SETUP:-swtpm_setup}" NEEDLE_UNLOCK="${UNLOCK_NEEDLE:-MjolnirState: unlocked}" NEEDLE_PCR="${PCR_NEEDLE:-PCR policy}" NEEDLE_FAILED="${UNSEAL_FAIL_NEEDLE:-Failed to unseal}" @@ -402,7 +403,7 @@ start_swtpm() { rm -f "$tpm/swtpm.pid" "$tpm/swtpm.sock" "$SWTPM" socket --tpmstate "dir=$tpm" \ --ctrl "type=unixio,path=$tpm/swtpm.sock" \ - --pid "file=$tpm/swtpm.pid" --tpm2 --daemon \ + --pid "file=$tpm/swtpm.pid" --flags not-need-init --tpm2 --daemon \ --log "file=$tpm/swtpm.log" || fail "swtpm did not start for $label" for _ in $(seq 1 50); do [ -S "$tpm/swtpm.sock" ] && break @@ -429,6 +430,7 @@ secureboot_cases() { return 0 fi need "$SWTPM" + need "$SWTPM_SETUP" provision_state_partition for label in signed unknown; do @@ -436,6 +438,11 @@ secureboot_cases() { tpm="$cd/tpm" rm -rf "$cd" mkdir -p "$tpm" + # A bare swtpm socket on a fresh state dir leaves libtpms in failure mode, + # and the guest sees "AES-128-CFB missing?" instead of a usable TPM. + # Manufacture the state once per case; start_swtpm reuses it for both boots. + "$SWTPM_SETUP" --tpm2 --tpmstate "$tpm" --overwrite --pcr-banks sha256 || + fail "swtpm_setup failed for $label" cp "$WORK/disk.raw" "$cd/disk.raw" || fail "cannot copy the disk for $label" cp "$VARS_ENROLLED" "$cd/vars.fd" || fail "cannot copy the variable store for $label" From a36c8f55f16631893adc9a8135c44810928b6b27 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 11:15:51 -0500 Subject: [PATCH 17/23] fix(boot): connect QEMU to swtpm's command socket, not its control socket swtpm exposes separate --server (TPM commands) and --ctrl (control) channels. QEMU was connected to the control channel, so the guest detected a TPM but could not use it. Give swtpm both sockets and let QEMU use the server one. --- testsuite/boot/test-boot.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 192aa9b..67319a9 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -400,9 +400,13 @@ start_swtpm() { kill "$old" 2>/dev/null || true fi fi - rm -f "$tpm/swtpm.pid" "$tpm/swtpm.sock" + rm -f "$tpm/swtpm.pid" "$tpm/swtpm.sock" "$tpm/swtpm.sock.ctrl" + # QEMU's TPM chardev speaks the command protocol on the --server socket. + # --ctrl is a separate control channel; connecting QEMU there leaves the + # guest with no usable TPM device. "$SWTPM" socket --tpmstate "dir=$tpm" \ - --ctrl "type=unixio,path=$tpm/swtpm.sock" \ + --server "type=unixio,path=$tpm/swtpm.sock" \ + --ctrl "type=unixio,path=$tpm/swtpm.sock.ctrl" \ --pid "file=$tpm/swtpm.pid" --flags not-need-init --tpm2 --daemon \ --log "file=$tpm/swtpm.log" || fail "swtpm did not start for $label" for _ in $(seq 1 50); do From d9d238fac1a37f6710595d09942916f6360eb678 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 12:22:04 -0500 Subject: [PATCH 18/23] Revert "fix(boot): connect QEMU to swtpm's command socket, not its control socket" This reverts commit a36c8f55f16631893adc9a8135c44810928b6b27. --- testsuite/boot/test-boot.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 67319a9..192aa9b 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -400,13 +400,9 @@ start_swtpm() { kill "$old" 2>/dev/null || true fi fi - rm -f "$tpm/swtpm.pid" "$tpm/swtpm.sock" "$tpm/swtpm.sock.ctrl" - # QEMU's TPM chardev speaks the command protocol on the --server socket. - # --ctrl is a separate control channel; connecting QEMU there leaves the - # guest with no usable TPM device. + rm -f "$tpm/swtpm.pid" "$tpm/swtpm.sock" "$SWTPM" socket --tpmstate "dir=$tpm" \ - --server "type=unixio,path=$tpm/swtpm.sock" \ - --ctrl "type=unixio,path=$tpm/swtpm.sock.ctrl" \ + --ctrl "type=unixio,path=$tpm/swtpm.sock" \ --pid "file=$tpm/swtpm.pid" --flags not-need-init --tpm2 --daemon \ --log "file=$tpm/swtpm.log" || fail "swtpm did not start for $label" for _ in $(seq 1 50); do From fc931c9534cab9a5028db58a65600c64cb39b5bc Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 12:42:18 -0500 Subject: [PATCH 19/23] fix(image): ship tpm2-tss in the runtime root filesystem FSDK's systemd does not runtime-depend on tpm2-tss; Mjolnir only staged it into the initramfs for the cryptsetup token plugin and into the UKI signing sandbox. After switch-root the TPM2 systemd units have no tpm2-tss libraries, so the state stays on its empty-key slot and the Secure Boot cases cannot prove a PCR policy. Add it to the runtime stack and assert both stages. --- Justfile | 1 + elements/base/os-stack.bst | 3 +++ tests/test_tpm_support.py | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/test_tpm_support.py diff --git a/Justfile b/Justfile index c42c441..c33312b 100644 --- a/Justfile +++ b/Justfile @@ -89,6 +89,7 @@ test: python3 tests/test_update_pins.py python3 tests/test_pins.py python3 tests/test_secureboot_fixtures.py + python3 tests/test_tpm_support.py python3 tests/test_image_contents.py "{{image_name}}:{{image_tag}}" python3 tests/test_boot_assets.py "{{image_name}}:{{image_tag}}" diff --git a/elements/base/os-stack.bst b/elements/base/os-stack.bst index 443b846..c8eadc3 100644 --- a/elements/base/os-stack.bst +++ b/elements/base/os-stack.bst @@ -16,6 +16,9 @@ depends: - freedesktop-sdk.bst:integration/ldconfig.bst - freedesktop-sdk.bst:components/systemd.bst +# systemd's TPM2 units need tpm2-tss after switch-root, not just in the +# initramfs where the cryptsetup token plugin pulls it in. +- freedesktop-sdk.bst:components/tpm2-tss.bst - freedesktop-sdk.bst:components/dbus.bst - freedesktop-sdk.bst:components/dbus-broker.bst - freedesktop-sdk.bst:components/kmod.bst diff --git a/tests/test_tpm_support.py b/tests/test_tpm_support.py new file mode 100644 index 0000000..091eb5c --- /dev/null +++ b/tests/test_tpm_support.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Assert the TPM2 userspace libraries are available in both boot stages. + +FSDK's systemd element does not runtime-depend on tpm2-tss. The initramfs +needs it for the cryptsetup token plugin, and the booted root needs it for +systemd-pcrlock, systemd-tpm2-setup and systemd-cryptenroll. A missing copy in +the root turns TPM-backed state enrollment into a silent fallback to the +empty-key LUKS slot, which the Secure Boot cases cannot distinguish. +""" +from __future__ import annotations + +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent + + +def main() -> int: + errors: list[str] = [] + rootfs = (ROOT / "elements/base/os-stack.bst").read_text() + if "freedesktop-sdk.bst:components/tpm2-tss.bst" not in rootfs: + errors.append("tpm2-tss is missing from the runtime stack") + + initramfs = (ROOT / "elements/kernel/initramfs.bst").read_text() + if "freedesktop-sdk.bst:components/tpm2-tss.bst" not in initramfs: + errors.append("tpm2-tss is missing from the initramfs stack") + + dracut = (ROOT / "files/config/dracut/50-mjolnir-tpm2.conf").read_text() + if "libcryptsetup-token-systemd-tpm2.so" not in dracut: + errors.append("initramfs has no systemd TPM2 cryptsetup token plugin") + + if errors: + for error in errors: + print(f" - {error}") + raise SystemExit(1) + print("TPM2 userspace contract OK") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From 30488e413b0b52f7b37c6dc806fbc3851442029f Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 13:26:53 -0500 Subject: [PATCH 20/23] fix(boot): use a distinctive needle for state unseal failure systemd-tpm2-setup logs its own 'Failed to unseal secret using TPM2' on a healthy boot, so the signed case failed the negative assertion for a string our failure unit never printed. Keep the original two lines for the downstream consumer and add 'MjolnirState: PCR unseal failed' for the boot assertions. --- docs/SECURITY.md | 7 +++++-- files/config/systemd/mjolnir-state-unseal-failed.service | 4 ++++ tests/test_units.py | 5 ++++- testsuite/README.md | 4 ++-- testsuite/boot/test-boot.sh | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/SECURITY.md b/docs/SECURITY.md index b1b2c7c..2bed124 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -151,8 +151,11 @@ the build-time `/etc/crypttab`. The unlock outcome has a stable serial contract. `mjolnir-state-unlocked.service` prints `MjolnirState: unlocked` after `var-lib-mjolnir.mount`. An `OnFailure=` drop-in on `systemd-cryptsetup@mjolnir-state.service` starts -`mjolnir-state-unseal-failed.service`, which prints `PCR policy` and -`Failed to unseal`. The drop-in and the failure unit are also sealed into the +`mjolnir-state-unseal-failed.service`, which prints `PCR policy`, +`Failed to unseal` and the distinctive `MjolnirState: PCR unseal failed`. +The last one is what the boot assertions check: systemd-tpm2-setup also logs +a generic `Failed to unseal` that is not a state cryptsetup failure. The +drop-in and the failure unit are also sealed into the initramfs, because a PCR policy miss fails cryptsetup before switch-root. No key material changes and the PCR 7 plus signed PCR 11 binding is untouched. `testsuite/boot/test-boot.sh` boots two isolated OVMF plus swtpm cases against diff --git a/files/config/systemd/mjolnir-state-unseal-failed.service b/files/config/systemd/mjolnir-state-unseal-failed.service index 12144a4..5e3c3ca 100644 --- a/files/config/systemd/mjolnir-state-unseal-failed.service +++ b/files/config/systemd/mjolnir-state-unseal-failed.service @@ -9,5 +9,9 @@ Type=oneshot # running in the initramfs and the signed cmdline forwards it to ttyS0. ExecStart=/usr/bin/echo PCR policy ExecStart=/usr/bin/echo Failed to unseal +# Distinctive needle: systemd-tpm2-setup also logs "Failed to unseal", so the +# boot assertions must not match that generic string. Keep the two lines above +# for the downstream consumer that greps them. +ExecStart=/usr/bin/echo MjolnirState: PCR unseal failed StandardOutput=journal+console StandardError=journal+console diff --git a/tests/test_units.py b/tests/test_units.py index f1b59fd..5fde37f 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -88,6 +88,8 @@ def require(relative: str, needle: str, label: str) -> None: "enable mjolnir-state-unlocked.service", "unlock preset") require(failed, "ExecStart=/usr/bin/echo PCR policy", "PCR needle") require(failed, "ExecStart=/usr/bin/echo Failed to unseal", "unseal failure needle") + require(failed, "ExecStart=/usr/bin/echo MjolnirState: PCR unseal failed", + "distinctive unseal failure needle") # A bare `console` is not a valid StandardOutput= specifier: systemd drops # it and the needle never reaches the serial log. Both units must forward # through journald *and* the console (enabled by the signed cmdline). @@ -101,7 +103,8 @@ def require(relative: str, needle: str, label: str) -> None: require(dracut, "mjolnir-state-unseal-failed.service", "initramfs failure unit") require(dracut, "10-mjolnir-failure.conf", "initramfs drop-in") require(dracut, "/usr/bin/echo", "initramfs echo binary") - for needle in ("MjolnirState: unlocked", "PCR policy", "Failed to unseal"): + for needle in ("MjolnirState: unlocked", "PCR policy", + "MjolnirState: PCR unseal failed"): require(boot, needle, "boot assertion needle") # The cases start from a disk whose encrypted state partition already # exists; otherwise repart creates it after cryptsetup has timed out. diff --git a/testsuite/README.md b/testsuite/README.md index 1787096..d00a9f4 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -45,8 +45,8 @@ establish the TPM2 enrollment, then reboot with the case's update: | Case | Update installed in the ESP | Required serial evidence | | --- | --- | --- | -| signed | `uki-signed.efi` | `MjolnirState: unlocked`, no `Failed to unseal` | -| unknown | `uki-unknown.efi` | `PCR policy` and `Failed to unseal`, no unlock | +| signed | `uki-signed.efi` | `MjolnirState: unlocked`, no `MjolnirState: PCR unseal failed` | +| unknown | `uki-unknown.efi` | `PCR policy` and `MjolnirState: PCR unseal failed`, no unlock | The needles come from image units, not from journal text the guest happens to emit. `mjolnir-state-unlocked.service` runs at `multi-user.target` when the diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index 192aa9b..e7b2fb4 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -264,7 +264,7 @@ SWTPM="${SWTPM:-swtpm}" SWTPM_SETUP="${SWTPM_SETUP:-swtpm_setup}" NEEDLE_UNLOCK="${UNLOCK_NEEDLE:-MjolnirState: unlocked}" NEEDLE_PCR="${PCR_NEEDLE:-PCR policy}" -NEEDLE_FAILED="${UNSEAL_FAIL_NEEDLE:-Failed to unseal}" +NEEDLE_FAILED="${UNSEAL_FAIL_NEEDLE:-MjolnirState: PCR unseal failed}" BOOT_WAIT="${BOOT_WAIT:-180}" GRACE="${GRACE_SECONDS:-10}" CASE_LOOPS=() From 9c3ee33738745fbf726e2219aa55013bef63b1e0 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 14:05:31 -0500 Subject: [PATCH 21/23] fix(boot): copy signed PCR artifacts in the initramfs systemd-stub exposes the signed PCR signature and public key at /.extra/ in the initrd, but the tmpfiles rule that copies them to /run/systemd was only in the rootfs. After switch-root the source is gone, so mjolnir-state-enroll.service's condition was never met and the state stayed on its empty-key slot. Stage an initramfs-only rule so enrollment can bind the key to the signed PCR 11 policy. --- elements/kernel/initramfs.bst | 2 ++ files/config/dracut/50-mjolnir-tpm2.conf | 3 +++ files/config/tmpfiles.d/mjolnir-initrd-pcr.conf | 6 ++++++ tests/test_tpm_support.py | 14 ++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 files/config/tmpfiles.d/mjolnir-initrd-pcr.conf diff --git a/elements/kernel/initramfs.bst b/elements/kernel/initramfs.bst index b79d108..d3c566b 100644 --- a/elements/kernel/initramfs.bst +++ b/elements/kernel/initramfs.bst @@ -66,6 +66,8 @@ config: install -Dm644 /config/crypttab /etc/crypttab install -Dm644 /config/dracut/50-mjolnir-tpm2.conf \ /etc/dracut.conf.d/50-mjolnir-tpm2.conf + install -Dm644 /config/tmpfiles.d/mjolnir-initrd-pcr.conf \ + /usr/lib/tmpfiles.d/mjolnir-initrd-pcr.conf # The PCR policy failure is reported by an OnFailure drop-in on the # cryptsetup instance. Stage both files for dracut's install_items so the # wires exist in the initramfs, not just in the booted rootfs. diff --git a/files/config/dracut/50-mjolnir-tpm2.conf b/files/config/dracut/50-mjolnir-tpm2.conf index 3cdfca0..3b1cba2 100644 --- a/files/config/dracut/50-mjolnir-tpm2.conf +++ b/files/config/dracut/50-mjolnir-tpm2.conf @@ -11,3 +11,6 @@ install_optional_items+=" /usr/lib/cryptsetup/libcryptsetup-token-systemd-tpm2.s install_items+=" /usr/lib/systemd/system/mjolnir-state-unseal-failed.service " install_items+=" /usr/lib/systemd/system/systemd-cryptsetup@mjolnir-state.service.d/10-mjolnir-failure.conf " install_items+=" /usr/bin/echo " +# Copy the stub's signed PCR artifacts into /run/systemd before switch-root; +# the enroll unit cannot find them after /.extra/ disappears. +install_items+=" /usr/lib/tmpfiles.d/mjolnir-initrd-pcr.conf " diff --git a/files/config/tmpfiles.d/mjolnir-initrd-pcr.conf b/files/config/tmpfiles.d/mjolnir-initrd-pcr.conf new file mode 100644 index 0000000..8eb4661 --- /dev/null +++ b/files/config/tmpfiles.d/mjolnir-initrd-pcr.conf @@ -0,0 +1,6 @@ +# systemd-stub exposes the signed PCR artifacts in the initrd at /.extra/. +# Copy them to the paths systemd-cryptenroll searches before switch-root; +# after switch-root the /.extra/ source is gone. The rootfs has the same +# lines in mjolnir-volatile.conf for the case where the artifacts persist. +C /run/systemd/tpm2-pcr-signature.json - - - - /.extra/tpm2-pcr-signature.json +C /run/systemd/tpm2-pcr-public-key.pem - - - - /.extra/tpm2-pcr-public-key.pem diff --git a/tests/test_tpm_support.py b/tests/test_tpm_support.py index 091eb5c..00d1b57 100644 --- a/tests/test_tpm_support.py +++ b/tests/test_tpm_support.py @@ -27,6 +27,20 @@ def main() -> int: dracut = (ROOT / "files/config/dracut/50-mjolnir-tpm2.conf").read_text() if "libcryptsetup-token-systemd-tpm2.so" not in dracut: errors.append("initramfs has no systemd TPM2 cryptsetup token plugin") + if "mjolnir-initrd-pcr.conf" not in dracut: + errors.append("initramfs does not install the PCR artifact tmpfiles rule") + + initrd_pcr = (ROOT / "files/config/tmpfiles.d/mjolnir-initrd-pcr.conf") + if not initrd_pcr.is_file(): + errors.append("missing initramfs PCR artifact tmpfiles rule") + else: + text = initrd_pcr.read_text() + if "/.extra/tpm2-pcr-signature.json" not in text: + errors.append("initramfs rule does not copy the PCR signature") + + initramfs = (ROOT / "elements/kernel/initramfs.bst").read_text() + if "mjolnir-initrd-pcr.conf" not in initramfs: + errors.append("initramfs element does not stage the PCR tmpfiles rule") if errors: for error in errors: From 742e6f4dcedcfd51a235b5455faee5e2b94c352e Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Sun, 29 Nov 2026 15:17:28 -0500 Subject: [PATCH 22/23] fix(boot): run state enrollment at multi-user.target Factory preset symlinks are applied after local-fs.target's initial transaction, so the enroll unit wanted by local-fs.target never started and the state stayed on its empty-key slot. Move it to multi-user.target alongside the unlock needle, which reliably runs there. --- elements/config/files.bst | 11 +++++++---- .../config/systemd/mjolnir-state-enroll.service | 2 +- tests/test_units.py | 16 ++++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/elements/config/files.bst b/elements/config/files.bst index 9521ab4..474cb2f 100644 --- a/elements/config/files.bst +++ b/elements/config/files.bst @@ -66,12 +66,15 @@ config: # well; otherwise var-lib-mjolnir.mount and the needle units never run. mkdir -p "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants" \ "${root}/usr/share/factory/etc/systemd/system/multi-user.target.wants" - for u in var-lib-mjolnir.mount mjolnir-state-enroll.service; do + ln -sf /usr/lib/systemd/system/var-lib-mjolnir.mount \ + "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants/var-lib-mjolnir.mount" + # Enrollment runs at multi-user.target, like the unlock needle. Preset + # symlinks appear after local-fs.target's initial transaction, so an + # enroll unit wanted by local-fs.target never started. + for u in mjolnir-state-enroll.service mjolnir-state-unlocked.service; do ln -sf "/usr/lib/systemd/system/${u}" \ - "${root}/usr/share/factory/etc/systemd/system/local-fs.target.wants/${u}" + "${root}/usr/share/factory/etc/systemd/system/multi-user.target.wants/${u}" done - ln -sf /usr/lib/systemd/system/mjolnir-state-unlocked.service \ - "${root}/usr/share/factory/etc/systemd/system/multi-user.target.wants/mjolnir-state-unlocked.service" mkdir -p "${root}/usr/lib/systemd/system" cp /config/systemd/*.service /config/systemd/*.socket /config/systemd/*.timer \ "${root}/usr/lib/systemd/system/" 2>/dev/null || true diff --git a/files/config/systemd/mjolnir-state-enroll.service b/files/config/systemd/mjolnir-state-enroll.service index d5d90ab..7676cf0 100644 --- a/files/config/systemd/mjolnir-state-enroll.service +++ b/files/config/systemd/mjolnir-state-enroll.service @@ -24,4 +24,4 @@ ReadOnlyPaths=/ ReadWritePaths=/var/lib/mjolnir /run/systemd [Install] -WantedBy=local-fs.target +WantedBy=multi-user.target diff --git a/tests/test_units.py b/tests/test_units.py index 5fde37f..d11de8c 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -109,13 +109,17 @@ def require(relative: str, needle: str, label: str) -> None: # The cases start from a disk whose encrypted state partition already # exists; otherwise repart creates it after cryptsetup has timed out. require(boot, "provision_state_partition", "state partition provisioning") - # volatile /etc is seeded from factory /etc: the state units must be in - # local-fs.target's wants before the initial transaction is computed. + # volatile /etc is seeded from factory /etc: the mount must be in + # local-fs.target's wants, and the enrollment and needle units in + # multi-user.target's wants, before their transactions are computed. files_bst = "elements/config/files.bst" - for unit in ("var-lib-mjolnir.mount", "mjolnir-state-enroll.service"): - require(files_bst, unit, f"factory local-fs wants for {unit}") - require(files_bst, "multi-user.target.wants/mjolnir-state-unlocked.service", - "factory multi-user wants for unlock needle") + require(files_bst, "local-fs.target.wants/var-lib-mjolnir.mount", + "factory local-fs wants for the state mount") + require(files_bst, "multi-user.target.wants/${u}", "factory multi-user wants loop") + for unit in ("mjolnir-state-enroll.service", "mjolnir-state-unlocked.service"): + require(files_bst, unit, f"factory multi-user wants for {unit}") + require("files/config/systemd/mjolnir-state-enroll.service", + "WantedBy=multi-user.target", "enrollment target") # Lid switches must never suspend an unattended node. logind = ROOT / "files/config/logind/50-ignore-lid.conf" From 41d5f4738ced6c710893397b7567faade15bdaa8 Mon Sep 17 00:00:00 2001 From: Quinn Groves Date: Mon, 30 Nov 2026 06:01:05 -0500 Subject: [PATCH 23/23] fix(ci): use same-build Secure Boot fixtures in the image gate Dev and CI builds generate a fresh PCR signing key and measure a commit-specific kernel, initramfs and cmdline. Release fixtures from another build therefore cannot prove this image's signed PCR 11 policy. Generate fixtures from this build's signing artifacts before the boot test and point FIXTURE_DIR at fixtures-out/, keeping the stable release only for Gram. Also make the PCR needle distinctive: systemd-pcrlock logs 'Calculated new PCR policy' on a healthy boot and would satisfy a generic assertion. --- .github/workflows/build.yml | 63 ++++++++----------- docs/SECUREBOOT-FIXTURES.md | 8 +++ docs/SECURITY.md | 7 ++- .../mjolnir-state-unseal-failed.service | 6 +- tests/test_secureboot_fixtures.py | 6 +- tests/test_units.py | 4 +- testsuite/README.md | 16 ++--- testsuite/boot/test-boot.sh | 2 +- 8 files changed, 59 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9bc086f..d290d09 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -142,35 +142,43 @@ jobs: max-layers: "128" source-date-epoch: auto - # The image repository publishes these three assets alongside a release. - # When the base URL is not configured the boot test records a SKIP for the - # Secure Boot cases; it never relaxes an assertion. + # Generate the unlock fixtures from this build's own signing artifacts. + # The PCR signing key and the measured kernel/initrd/cmdline are + # build-specific, so release assets from another build cannot prove + # that this image's signed PCR 11 policy unseals MjolnirState. + - name: Generate Secure Boot fixtures + run: | + set -euo pipefail + sudo apt-get install -y -qq python3-cryptography ovmf binutils unzip + # Earlier sudo podman steps leave crun's cache under XDG_RUNTIME_DIR + # owned by root, which breaks the unprivileged `just bst` below. + RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" + sudo chown -R "$(id -u):$(id -g)" "$RUNTIME_DIR/crun" 2>/dev/null || true + just fixtures + - name: Provision Secure Boot fixtures env: - FIXTURE_BASE_URL: ${{ vars.SECUREBOOT_FIXTURE_BASE_URL }} - FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures + FIXTURE_DIR: ${{ github.workspace }}/fixtures-out run: | set -euo pipefail - mkdir -p "$FIXTURE_DIR" - if [ -z "$FIXTURE_BASE_URL" ]; then - echo "NOTICE: SECUREBOOT_FIXTURE_BASE_URL is not configured." - echo "The Secure Boot swtpm cases will record a SKIP." - exit 0 - fi - for fixture in OVMF_VARS.enrolled.fd uki-signed.efi uki-unknown.efi SHA256SUMS; do - curl -fsSL "$FIXTURE_BASE_URL/$fixture" -o "$FIXTURE_DIR/$fixture" + for fixture in OVMF_VARS.enrolled.fd uki-signed.efi uki-unknown.efi; do + test -s "$FIXTURE_DIR/$fixture" done - # The release tag is republished in place on every successful - # testing build, so verify the downloaded bytes against the - # release's own manifest before a boot case consumes them. (cd "$FIXTURE_DIR" && sha256sum -c SHA256SUMS) + - name: Upload Secure Boot fixtures + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: mjolnir-secureboot-fixtures + path: fixtures-out/ + retention-days: 90 + # The install checks that bootc accepts the signed digest, and the OVMF # boot checks that the shell-free initramfs actually mounts the composefs # root and reaches user space. A static content check cannot prove that. - name: Install and boot test (OVMF) env: - FIXTURE_DIR: ${{ runner.temp }}/mjolnir-secureboot-fixtures + FIXTURE_DIR: ${{ github.workspace }}/fixtures-out run: | sudo apt-get update -qq sudo apt-get install -y -qq qemu-system-x86 ovmf binutils swtpm swtpm-tools systemd-repart @@ -302,27 +310,6 @@ jobs: fi just cache-push - # The unlock fixtures used by Gram's OVMF + swtpm harness. They come - # from the same signing-only artifacts as this image, so uki-signed.efi - # carries the PCR policy that unseals the state of the image built here. - # Generate on every PR so the image gate exercises this code; only the - # publication job below is restricted to testing and manual dispatch. - - name: Generate Secure Boot fixtures - run: | - set -euo pipefail - sudo apt-get install -y -qq python3-cryptography ovmf binutils unzip - # Earlier sudo podman steps leave crun's cache under XDG_RUNTIME_DIR - # owned by root, which breaks the unprivileged `just bst` below. - RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" - sudo chown -R "$(id -u):$(id -g)" "$RUNTIME_DIR/crun" 2>/dev/null || true - just fixtures - - - name: Upload Secure Boot fixtures - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 - with: - name: mjolnir-secureboot-fixtures - path: fixtures-out/ - retention-days: 90 # Publishes the three public fixtures to a stable release tag so Gram's # curl-based provisioning needs no URL changes. Kept separate from `image` diff --git a/docs/SECUREBOOT-FIXTURES.md b/docs/SECUREBOOT-FIXTURES.md index 89168ae..cd18767 100644 --- a/docs/SECUREBOOT-FIXTURES.md +++ b/docs/SECUREBOOT-FIXTURES.md @@ -5,6 +5,14 @@ in [Gram](https://github.com/HuntedRaven7/Gram) (issue #19). They prove that a signed UKI update still unseals `MjolnirState`, while a UKI with an unknown PCR signing key fails the PCR 11 policy. +Mjolnir's own image gate does **not** download these release assets. It +generates fresh fixtures from the same signing artifacts as the image under +test (`just fixtures`) and points `FIXTURE_DIR` at `fixtures-out/`. Dev and CI +builds generate a new PCR signing key and measure a commit-specific kernel, +initramfs and cmdline, so a fixture from another build can never prove this +image's signed PCR 11 policy. The release exists only for the downstream +consumer that provisions against a published image. + ## Stable URLs Set `SECUREBOOT_FIXTURE_BASE_URL` in Gram to: diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 2bed124..a6a514c 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -152,9 +152,10 @@ The unlock outcome has a stable serial contract. `mjolnir-state-unlocked.service prints `MjolnirState: unlocked` after `var-lib-mjolnir.mount`. An `OnFailure=` drop-in on `systemd-cryptsetup@mjolnir-state.service` starts `mjolnir-state-unseal-failed.service`, which prints `PCR policy`, -`Failed to unseal` and the distinctive `MjolnirState: PCR unseal failed`. -The last one is what the boot assertions check: systemd-tpm2-setup also logs -a generic `Failed to unseal` that is not a state cryptsetup failure. The +`Failed to unseal` and the distinctive `MjolnirState: PCR policy miss` and +`MjolnirState: PCR unseal failed`. The distinctive needles are what the boot +assertions check: systemd-tpm2-setup logs a generic `Failed to unseal` and +systemd-pcrlock logs `Calculated new PCR policy` on a healthy boot. The drop-in and the failure unit are also sealed into the initramfs, because a PCR policy miss fails cryptsetup before switch-root. No key material changes and the PCR 7 plus signed PCR 11 binding is untouched. diff --git a/files/config/systemd/mjolnir-state-unseal-failed.service b/files/config/systemd/mjolnir-state-unseal-failed.service index 5e3c3ca..daba7ff 100644 --- a/files/config/systemd/mjolnir-state-unseal-failed.service +++ b/files/config/systemd/mjolnir-state-unseal-failed.service @@ -9,9 +9,11 @@ Type=oneshot # running in the initramfs and the signed cmdline forwards it to ttyS0. ExecStart=/usr/bin/echo PCR policy ExecStart=/usr/bin/echo Failed to unseal -# Distinctive needle: systemd-tpm2-setup also logs "Failed to unseal", so the -# boot assertions must not match that generic string. Keep the two lines above +# Distinctive needles: systemd-tpm2-setup logs "Failed to unseal" and +# systemd-pcrlock logs "Calculated new PCR policy" on a healthy boot, so the +# assertions must not match those generic strings. Keep the two lines above # for the downstream consumer that greps them. +ExecStart=/usr/bin/echo MjolnirState: PCR policy miss ExecStart=/usr/bin/echo MjolnirState: PCR unseal failed StandardOutput=journal+console StandardError=journal+console diff --git a/tests/test_secureboot_fixtures.py b/tests/test_secureboot_fixtures.py index f2acf21..33b29ca 100644 --- a/tests/test_secureboot_fixtures.py +++ b/tests/test_secureboot_fixtures.py @@ -59,8 +59,12 @@ def main() -> int: errors.append("fixture generation must run on PRs so the image gate exercises it") provision_block = workflow.split(" - name: Provision Secure Boot fixtures", 1)[1] provision_block = provision_block.split(" # The install checks", 1)[0] + if "fixtures-out" not in provision_block: + errors.append("the image gate does not use this build's generated fixtures") + if "FIXTURE_BASE_URL" in provision_block: + errors.append("the image gate must not consume stale release fixtures") if "SHA256SUMS" not in provision_block or "sha256sum -c" not in provision_block: - errors.append("downloaded fixtures are not verified against SHA256SUMS") + errors.append("generated fixtures are not verified against SHA256SUMS") docs = read("docs/SECUREBOOT-FIXTURES.md") if BASE_URL not in docs or not all(f in docs for f in ASSETS): diff --git a/tests/test_units.py b/tests/test_units.py index d11de8c..29b5446 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -88,6 +88,8 @@ def require(relative: str, needle: str, label: str) -> None: "enable mjolnir-state-unlocked.service", "unlock preset") require(failed, "ExecStart=/usr/bin/echo PCR policy", "PCR needle") require(failed, "ExecStart=/usr/bin/echo Failed to unseal", "unseal failure needle") + require(failed, "ExecStart=/usr/bin/echo MjolnirState: PCR policy miss", + "distinctive PCR needle") require(failed, "ExecStart=/usr/bin/echo MjolnirState: PCR unseal failed", "distinctive unseal failure needle") # A bare `console` is not a valid StandardOutput= specifier: systemd drops @@ -103,7 +105,7 @@ def require(relative: str, needle: str, label: str) -> None: require(dracut, "mjolnir-state-unseal-failed.service", "initramfs failure unit") require(dracut, "10-mjolnir-failure.conf", "initramfs drop-in") require(dracut, "/usr/bin/echo", "initramfs echo binary") - for needle in ("MjolnirState: unlocked", "PCR policy", + for needle in ("MjolnirState: unlocked", "MjolnirState: PCR policy miss", "MjolnirState: PCR unseal failed"): require(boot, needle, "boot assertion needle") # The cases start from a disk whose encrypted state partition already diff --git a/testsuite/README.md b/testsuite/README.md index d00a9f4..b833110 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -63,9 +63,12 @@ log both before and after switch-root. ### Fixtures -The three fixtures are release assets of this repository, published by the -Secure Boot fixture work. The harness reads them from `FIXTURE_DIR`, which -defaults to `$RUNNER_TEMP/mjolnir-secureboot-fixtures`: +The three fixtures are generated from the same signing artifacts as the image +under test by `just fixtures` (CI runs this before the boot test). Their PCR +signature and measured kernel/initrd/cmdline therefore belong to this build. +The harness reads them from `FIXTURE_DIR`, which defaults to `fixtures-out/` in +the repository root. The published release assets are for the downstream Gram +harness, not for this gate: | File | Meaning | | --- | --- | @@ -76,8 +79,7 @@ defaults to `$RUNNER_TEMP/mjolnir-secureboot-fixtures`: Env overrides: `FIXTURE_DIR`, `SECUREBOOT_FIXTURE_DIR`, `OVMF_VARS_ENROLLED`, `UKI_SIGNED`, `UKI_UNKNOWN`, `SIGNED_LOG`, `UNKNOWN_LOG`, `SWTPM`, `BOOT_WAIT`, `GRACE_SECONDS`, and the three needle overrides `UNLOCK_NEEDLE`, `PCR_NEEDLE`, -`UNSEAL_FAIL_NEEDLE`. CI sets `FIXTURE_DIR` from the -`SECUREBOOT_FIXTURE_BASE_URL` repository variable. With no variable configured -the two cases write SKIP logs and the run stays green; the assertions in the -script and the static checks in `tests/test_units.py` still run on every PR. +`UNSEAL_FAIL_NEEDLE`. With no fixtures in `FIXTURE_DIR` the two cases write +SKIP logs and the run stays green; the assertions in the script and the static +checks in `tests/test_units.py` still run on every PR. Both serial logs are uploaded as the `mjolnir-secureboot-serial-logs` artifact. diff --git a/testsuite/boot/test-boot.sh b/testsuite/boot/test-boot.sh index e7b2fb4..dc6550f 100755 --- a/testsuite/boot/test-boot.sh +++ b/testsuite/boot/test-boot.sh @@ -263,7 +263,7 @@ UNKNOWN_LOG="${UNKNOWN_LOG:-$WORK/secureboot-unknown.log}" SWTPM="${SWTPM:-swtpm}" SWTPM_SETUP="${SWTPM_SETUP:-swtpm_setup}" NEEDLE_UNLOCK="${UNLOCK_NEEDLE:-MjolnirState: unlocked}" -NEEDLE_PCR="${PCR_NEEDLE:-PCR policy}" +NEEDLE_PCR="${PCR_NEEDLE:-MjolnirState: PCR policy miss}" NEEDLE_FAILED="${UNSEAL_FAIL_NEEDLE:-MjolnirState: PCR unseal failed}" BOOT_WAIT="${BOOT_WAIT:-180}" GRACE="${GRACE_SECONDS:-10}"