Files
diskless-workstation/files/dracut/95dot1x-macsec/module-setup.sh
T
Audiobuzz 6278f2847d tpm-enrol: pivot host enrolment to a Go binary, built out-of-VM
Replaces the shell/openssl-provider host enrolment (a35f2d6) with a static
Go + go-tpm binary, and moves BOTH host Go binaries out of the Packer VM.

fleet-enrol (files/enrol/, Go + go-tpm, no CGO):
  - talks to /dev/tpmrm0 DIRECTLY via transport.FromReadWriter(os.File) — no
    linuxtpm, so go-tpm is the only dep and there is NO tpm2-tools key-gen /
    openssl tpm2 provider / curl in the image (removes the biggest bench risk,
    the provider handle: key-ref).
  - ensures the ECDSA key @0x81010001, builds the CSR (crypto.Signer over the
    TPM key), POSTs CSR+context to the broker, shows the Plymouth fingerprint,
    polls /status, writes the leaf cert to NV 0x01800001.
  - tpmkey/ is an exported package so the TPM ceremony is tested against the
    go-tpm software simulator from a SEPARATE simtest/ module (CGO stays out of
    the shipped build). Transaction logic (mock broker) tested in-package.
  - deps pinned by go.sum (not vendored): the binary now builds on the CI
    runner, which has network — reproducible via pinned Go 1.26.4 + go.sum.

Out-of-VM build (decision): both fleet-enrol AND fleet-hostapi compile in the
CI "Build host Go binaries" step (Go 1.26.4, CGO off, -trimpath) and Packer
FILE-PROVISIONS the static binaries in. Dropped the in-VM `dnf install golang`
+ the 2d removal — the Rocky build image carries no Go toolchain / go-tpm tree.

Wiring:
  - tpm-enrol.sh: now a thin GATE (empty-NV check, pre-auth DHCP on en*,
    exec /usr/sbin/fleet-enrol, reboot-to-converge). module-setup.sh bundles the
    binary (asserted) + reverts the tpm2-openssl/curl installs.
  - diskless.pkr.hcl: file provisioners for both binaries; enrol installed to
    /usr/sbin before the initramfs build + fapolicyd-trusted; lsinitrd asserts
    fleet-enrol; dnf reverted to baseline (no tpm2-openssl/curl).
  - gitea-main-ci.yaml: Set up Go + build both binaries + run the simulator
    ceremony test, before packer validate.

TESTED here: transaction unit tests + the full TPM ceremony (key-gen -> persist
-> ECDSA sign -> CSR verify -> chunked NV write -> re-enrol) against the go-tpm
simulator. BENCH-VERIFY (real/swtpm, empty owner auth, pre-auth DHCP, Plymouth,
reboot-converge, prod HTTPS) tracked in docs/TODO.md #11.
2026-07-02 09:55:54 +00:00

106 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
# 95dot1x-macsec: authenticate the port with 802.1X EAP-TLS (TPM-held key,
# client cert in TPM NV) and bring up MACsec before netroot is mounted.
# The supplicant is launched as a systemd "root storage daemon"
# (argv[0] = @wpa_supplicant) so it survives switch-root and keeps the
# MKA session — and therefore the link carrying the root fs — alive.
check() {
require_binaries wpa_supplicant wpa_cli tpm2_nvread openssl || return 1
# First-boot ENROLMENT is the out-of-VM fleet-enrol Go binary (bundled in
# install()), which does key-gen/CSR/NV directly via go-tpm — so no tpm2-tools
# key-gen / openssl provider / curl are required in the initramfs here.
return 0
}
depends() {
# network-manager (not network-legacy): NM renews the DHCP lease in the real
# root after switch-root (the legacy one-shot lease was never renewed). The
# secure path drives DHCP on macsec0 via nmcli instead of the old `ifup`.
echo "network-manager bash"
return 0
}
installkernel() {
instmods macsec
# tpm_crb/tpm_tis are usually built in; assert anyway
instmods tpm_crb tpm_tis
}
install() {
# wpa stack + tpm + openssl, plus the coreutils the hook calls. dracut on
# RHEL only bundles binaries a module requests — head/ls/grep/etc. are NOT
# present by default, so list everything the hook uses.
# nvme: the rd.dot1x=0 test path drives `nvme connect-all` itself (this
# distro's dracut nvmf module populates discovery.conf but never registers
# an initqueue/online autoconnect hook). The nvmf module installs nvme too,
# but list it here so the hook's dependency is explicit and load-order-safe.
# nmcli: the secure path brings macsec0 up via NetworkManager (DHCP+renewal)
# instead of the old network-legacy `ifup`.
inst_multiple wpa_supplicant wpa_cli tpm2_nvread openssl ip setsid nmcli \
grep sed cut tr sha256sum sleep mkdir nvme
# Inline empty-NV enrolment: the gate hook (tpm-enrol.sh) drives networking +
# reboot; the actual key-gen/CSR/broker/NV work is the out-of-VM fleet-enrol
# binary (Go + go-tpm, static — talks to /dev/tpmrm0 directly, no tpm2-tools /
# openssl provider / curl needed). reboot: the hook reboots to converge into
# the secure path after writing the cert to NV.
inst_multiple reboot
if [ -x /usr/sbin/fleet-enrol ]; then
inst_simple /usr/sbin/fleet-enrol /usr/sbin/fleet-enrol
else
derror "95dot1x-macsec: /usr/sbin/fleet-enrol missing — build it out-of-VM (CI 'Build host Go binaries') before the initramfs build"
return 1
fi
# TSS libraries that tpm2_nvread (secure-path NV read) dlopens.
inst_libdir_file "libtss2-*"
# Fleet-generic supplicant config + RADIUS CA
inst_simple /etc/dot1x/wpa_supplicant-dot1x.conf /etc/dot1x/wpa_supplicant-dot1x.conf
inst_simple /etc/dot1x/radius-ca.pem /etc/dot1x/radius-ca.pem
# cmdline-stage hook (runs BEFORE NetworkManager starts): in secure mode it
# drops /run/NetworkManager/conf.d/10-dot1x-unmanaged.conf so NM never grabs
# the physical EAPOL NIC (wpa_supplicant owns it). No-op in rd.dot1x=0 test
# mode, so NM manages+renews the boot NIC. Replaces the old static
# 99-dot1x-unmanaged.conf, which couldn't be mode-aware.
inst_hook cmdline 10 "$moddir/nm-unmanaged.sh"
# Inline empty-NV enrolment: runs BEFORE dot1x-macsec-up.sh (priority 25 < 30).
# No-op when a cert is already present (normal boot) or under rd.dot1x=0; on a
# fresh host it enrols an identity into NV then reboots into the secure path.
inst_hook initqueue/settled 25 "$moddir/tpm-enrol.sh"
# Hook: runs from the initqueue once the NIC exists, before netroot
inst_hook initqueue/settled 30 "$moddir/dot1x-macsec-up.sh"
# Test-mode (rd.dot1x=0) NVMe-oF connect as a systemd unit. This initramfs
# is systemd-driven and does NOT source dracut initqueue/online hooks when
# the ip=dhcp link comes up (verified: the hook installs but never fires),
# and the nvmf module registers no autoconnect — so a dracut hook never
# runs. A oneshot unit ordered Before=initrd-root-device.target, with its
# own wait-for-network + connect loop, connects the namespace
# deterministically. ConditionKernelCommandLine=rd.dot1x=0 makes it a no-op
# on the secure path.
inst_simple "$moddir/nvmf-connect.sh" /usr/sbin/nvmf-connect
# systemdsystemunitdir is normally /usr/lib/systemd/system, but dracut does
# not reliably export it into module-setup context here — when empty,
# inst_simple's dir handling silently DROPS the unit (the bug that left the
# initramfs without nvmf-connect.service). Fall back to the canonical path.
local _unitdir="${systemdsystemunitdir:-/usr/lib/systemd/system}"
inst_simple "$moddir/nvmf-connect.service" "${_unitdir}/nvmf-connect.service"
mkdir -p "${initdir}${_unitdir}/initrd-root-device.target.wants"
ln -sf ../nvmf-connect.service \
"${initdir}${_unitdir}/initrd-root-device.target.wants/nvmf-connect.service"
# Hard-fail the dracut build if the unit didn't land — never ship a UKI that
# silently can't connect its NVMe-oF root in test mode.
if [ ! -e "${initdir}${_unitdir}/nvmf-connect.service" ]; then
derror "95dot1x-macsec: nvmf-connect.service not installed into ${_unitdir}"
return 1
fi
dracut_need_initqueue
}