Skip to content

feat(boot): add Secure Boot serial needles and swtpm cases - #72

Open
HuntedRaven7 wants to merge 23 commits into
testingfrom
feat/secureboot-cases
Open

HuntedRaven7 wants to merge 23 commits into
testingfrom
feat/secureboot-cases

Conversation

@HuntedRaven7

@HuntedRaven7 HuntedRaven7 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Why

Issue #71 needs two Secure Boot boot cases. Gram greps serial logs for MjolnirState: unlocked, PCR policy and Failed to unseal; the image emitted none of them.

What changed

  • Two oneshot units print the needles via StandardOutput=journal+console / StandardError=journal+console. The success unit runs after var-lib-mjolnir.mount and is preset-enabled. (A bare console output specifier is invalid in systemd and is silently dropped.)
  • An OnFailure= drop-in on systemd-cryptsetup@mjolnir-state.service starts the failure unit. The drop-in and unit are sealed into the initramfs because a PCR miss fails cryptsetup before switch-root.
  • Two OVMF+swtpm cases in test-boot.sh copy the installed disk, give each case its own variable store and TPM state, enroll with the signed fixture, then reboot with the signed or unknown UKI and assert the needles.
  • A provisioning step runs before the cases: bootc install --run-repart leaves MjolnirState for systemd-repart on first boot, but repart only runs after switch-root, after the initramfs cryptsetup has already timed out. The harness applies the image's own repart.d definition on the host so the cases start from a disk with an empty-key LUKS2 state partition they can unlock and enroll.
  • Static needle/wiring checks, image asset checks, CI fixture provisioning, serial-log artifact upload and docs.

Scope

Units, initramfs build inputs, static tests, boot harness, CI and docs. No keys, no PCR binding change, no install-time kargs, no shell or interpreter in the image.

Tradeoffs

Fixtures come from PR A's release assets. With SECUREBOOT_FIXTURE_BASE_URL unset, the cases write SKIP logs and CI stays green; no assertion is weakened. This branch was rebased onto PR A, which is now in testing.

Blast Radius

One new preset-enabled unit runs at boot. A drop-in changes what a failed state cryptsetup triggers; unlock and PCR binding behaviour are unchanged. Existing boot checks are untouched.

Verification

python3 tests/test_units.py, test_state_reset.py, test_initramfs_policy.py, YAML parse, bash -n and shellcheck pass locally. CI runs just validate, just test, just lint and the full OVMF boot test. Verdicts are recorded in a PR comment.

@HuntedRaven7

Copy link
Copy Markdown
Owner Author

CI verdict at head 48d6f16665b711d571e64bdaac72177a6936e791:

  • validate pass (49s); validate-arm64 pass (28s)
  • image pass (28m54s): just validate, static checks, content checks, bootc container lint (13 checks passed, 1 warning for nonempty /boot), install + OVMF boot with the signed cmdline and live Varlink socket
  • Console plugin smoke pass; KubeStellar WDS↔ITS pass; Trivy pass
  • Skipped by existing conditions: BST-native SPDX SBOM, Reproducibility

Evidence: build workflow run 46090878842, https://github.com/HuntedRaven7/Mjolnir/actions/runs/46090878842

The two Secure Boot cases recorded SKIP in CI because SECUREBOOT_FIXTURE_BASE_URL is not configured and PR A's three release assets are not published yet. Both SKIP logs were uploaded as artifact mjolnir-secureboot-serial-logs (602 bytes, ID 15242067304). No assertion was weakened; the static needle/wiring checks and the original OVMF boot check all ran and passed. Once PR A lands and the variable is set, the same job runs both cases unmodified and uploads their real serial logs. Dependency on PR A is recorded in the PR body and in issue71-cases.tsv.

Emit deterministic unlock and PCR failure needles from image units, and add two isolated OVMF+swtpm boot cases that consume the published fixtures.
Explicit StandardOutput=console and StandardError=console bypass journald forwarding during early boot. Also upload nested enroll logs on failure.
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.
@HuntedRaven7

Copy link
Copy Markdown
Owner Author

Diagnosis and fix for the failing image check at f1ce962:

  • The signed-enroll case booted but never emitted MjolnirState: unlocked. The serial log showed two causes:
    1. dev-disk-by-partlabel-MjolnirState.device timed out in the initramfs (90s). bootc install --run-repart leaves MjolnirState for systemd-repart on first boot, but repart only runs after switch-root (~95s), so systemd-cryptsetup@mjolnir-state failed and var-lib-mjolnir.mount then waited on the mapper device forever. The unlock unit is After=var-lib-mjolnir.mount, so it never ran.
    2. StandardOutput=console / StandardError=console are not valid systemd specifiers: systemd logged Failed to parse output specifier, ignoring: console and fell back to the journal.
  • Fix pushed as f267bf2: switch both units to journal+console (journald forwarding to ttyS0 is enabled by the signed cmdline), and add a one-time provisioning boot before the cases so repart creates and encrypts MjolnirState. Each case still copies its own disk/variable store/TPM state and asserts the same needles; no assertion was weakened. Static checks and testsuite/README.md were updated to lock in both properties.

Local test_units.py, bash -n and YAML checks pass. CI on the new head is running; I will report the verdict when it completes.

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.
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.
Ubuntu 26.04 ships systemd-repart as a separate package; without it the host-side state provisioning step fails with 'command not found'.
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.
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.
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).
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.
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.
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.
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.
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.
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.
…cket

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.
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.
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.
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.
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant