Repository navigation
feat(boot): add Secure Boot serial needles and swtpm cases - #72
HuntedRaven7 wants to merge 23 commits into
Conversation
|
CI verdict at head
Evidence: build workflow run 46090878842, https://github.com/HuntedRaven7/Mjolnir/actions/runs/46090878842 The two Secure Boot cases recorded |
Emit deterministic unlock and PCR failure needles from image units, and add two isolated OVMF+swtpm boot cases that consume the published fixtures.
48d6f16 to
a75b3fd
Compare
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.
|
Diagnosis and fix for the failing
Local |
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.
…ntrol socket" This reverts commit a36c8f5.
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.
Why
Issue #71 needs two Secure Boot boot cases. Gram greps serial logs for
MjolnirState: unlocked,PCR policyandFailed to unseal; the image emitted none of them.What changed
StandardOutput=journal+console/StandardError=journal+console. The success unit runs aftervar-lib-mjolnir.mountand is preset-enabled. (A bareconsoleoutput specifier is invalid in systemd and is silently dropped.)OnFailure=drop-in onsystemd-cryptsetup@mjolnir-state.servicestarts the failure unit. The drop-in and unit are sealed into the initramfs because a PCR miss fails cryptsetup before switch-root.test-boot.shcopy 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.bootc install --run-repartleavesMjolnirStatefor 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 ownrepart.ddefinition on the host so the cases start from a disk with an empty-key LUKS2 state partition they can unlock and enroll.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_URLunset, the cases write SKIP logs and CI stays green; no assertion is weakened. This branch was rebased onto PR A, which is now intesting.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 -nand shellcheck pass locally. CI runsjust validate,just test,just lintand the full OVMF boot test. Verdicts are recorded in a PR comment.