From dccf6bab6540b5ae4c3ecf7cbefd61bb0418f125 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:38 +0000 Subject: [PATCH 1/6] stage1: attest with the boot disk's GPT digests (vaportpm#13) The firmware measures the boot disk's GPT (EV_EFI_GPT_EVENT: PCR5, PCR2 on GCE TDX) and stage2 rewrites it, so a verifier needs the digests to replay that PCR after a first boot. stage1 finds the boot disk (stage2's find_boot_device rules, duplicated: the one disk with the data partition, else the one with an ESP), reads its GPT and passes H(UEFI_GPT_DATA) to vaportpm's attest(), which now requires it. - Pin vaportpm-attest to lockboot/vaportpm#13 (gpt-digest, unreleased). - `make update-vaportpm`: re-resolve Cargo.lock after changing the rev. Tested: test-chain x86_64 + aarch64; stage2 pivot reboot test under QEMU and on GCP c3-standard-4 TDX (boot 2 attests the rewritten GPT; PCR2 replays from it). Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 2 +- Cargo.toml | 10 ++-- Makefile | 5 ++ crates/stage1/src/bootdisk.rs | 90 +++++++++++++++++++++++++++++++++++ crates/stage1/src/main.rs | 6 ++- 5 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 crates/stage1/src/bootdisk.rs diff --git a/Cargo.lock b/Cargo.lock index 8daa9fe..dcd0f11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2046,7 +2046,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vaportpm-attest" version = "0.3.0" -source = "git+https://github.com/lockboot/vaportpm?rev=7041f461eb33bc15ad914466042b7befe358d119#7041f461eb33bc15ad914466042b7befe358d119" +source = "git+https://github.com/lockboot/vaportpm?rev=8b2c35c22829852bdd570eb5296499cd5f4f7c95#8b2c35c22829852bdd570eb5296499cd5f4f7c95" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 67a6609..b6a6275 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,10 +18,11 @@ libc = "0.2" # use — the detached .sig is a cross-repo wire contract. ed25519-compact = { version = "2", default-features = false } -# Pinned to the vaportpm v0.3.0 release commit: immutable SHA + a `version` guard (the build fails -# if the rev ever drifts to a commit whose crate version isn't 0.3.0). Tag is not GPG-signed yet; -# a signed release will follow. Bump both on the next vaportpm release. -vaportpm-attest = { git = "https://github.com/lockboot/vaportpm", rev = "7041f461eb33bc15ad914466042b7befe358d119", version = "=0.3.0" } +# Pinned to an immutable SHA + a `version` guard (the build fails if the rev drifts to a commit +# whose crate version isn't 0.3.0). Currently the vaportpm `gpt-digest` branch (lockboot/vaportpm#13, +# unreleased); move to the next release commit and bump the guard once it is cut. After changing +# the rev, `make update-vaportpm` re-resolves Cargo.lock. +vaportpm-attest = { git = "https://github.com/lockboot/vaportpm", rev = "8b2c35c22829852bdd570eb5296499cd5f4f7c95", version = "=0.3.0" } reqwest = { version = "=0.12.24", default-features = false, features = ["blocking", "rustls-tls-webpki-roots-no-provider"] } rustls = { version = "=0.23.23", default-features = false, features = ["std", "tls12"] } @@ -35,3 +36,4 @@ lto = true # Enable Link Time Optimization codegen-units = 1 # Maximize optimization strip = true # Strip symbols panic = "abort" # Smaller panic handler + diff --git a/Makefile b/Makefile index fbb5019..026a6b8 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,11 @@ ci: docker-build-base fmt-fix: docker-build-base ## Apply rustfmt across the whole workspace (no --check) $(DOCKER_RUN) $(DOCKER_SAMEUSER) $(BUILD_IMAGE) cargo fmt --all +# Re-resolve Cargo.lock's vaportpm-attest entry to the rev in Cargo.toml (after bumping it). +.PHONY: update-vaportpm +update-vaportpm: docker-build-base + $(DOCKER_RUN) $(DOCKER_SAMEUSER) $(BUILD_IMAGE) cargo update -p vaportpm-attest + ##################################################################### # UKI build (stage0 serves linux.efi over the network and admits it by diff --git a/crates/stage1/src/bootdisk.rs b/crates/stage1/src/bootdisk.rs new file mode 100644 index 0000000..4235702 --- /dev/null +++ b/crates/stage1/src/bootdisk.rs @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! The boot disk's GPT digests, for the attestation. +//! +//! The firmware measures the boot disk's GPT (`EV_EFI_GPT_EVENT`, PCR5; PCR2 on GCE TDX), and +//! stage2 rewrites that GPT, so a verifier needs the digests to replay the PCR. They are read +//! from the disk here rather than from the firmware event log, which not every platform hands +//! to Linux intact. +//! +//! Identifying the disk duplicates stage2's `blockdev::find_boot_device()` rules (keep them in +//! step): a disk carrying the lockboot data partition, else the one disk with an EFI System +//! Partition; zero or several candidates is an error. + +use anyhow::{bail, Context, Result}; +use std::path::{Path, PathBuf}; +use vaportpm_attest::gpt::uefi_gpt_data_device; +use vaportpm_attest::GptDigests; + +/// EFI System Partition type GUID c12a7328-f81f-11d2-ba4b-00a0c93ec93b, in on-disk byte order. +const ESP_TYPE: [u8; 16] = [ + 0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11, 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b, +]; +/// stage2's data partition type GUID 1c8f6b2d-af5e-4d3b-9c4f-2b3c4d5e6f70, in on-disk byte order. +const DATA_TYPE: [u8; 16] = [ + 0x2d, 0x6b, 0x8f, 0x1c, 0x5e, 0xaf, 0x3b, 0x4d, 0x9c, 0x4f, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f, 0x70, +]; + +/// GPT digests of the boot disk. +pub fn gpt_digests() -> Result { + let (dev, data) = find_boot_disk()?; + eprintln!( + "stage1: boot disk {} ({} bytes of UEFI_GPT_DATA)", + dev.display(), + data.len() + ); + Ok(GptDigests::of(&data)) +} + +/// The boot disk and its `UEFI_GPT_DATA`. +fn find_boot_disk() -> Result<(PathBuf, Vec)> { + let mut data_disks = Vec::new(); + let mut esp_disks = Vec::new(); + for dev in whole_disks()? { + let Ok(gpt) = uefi_gpt_data_device(&dev) else { + continue; + }; + let types = partition_types(&gpt); + if types.contains(&DATA_TYPE) { + data_disks.push((dev, gpt)); + } else if types.contains(&ESP_TYPE) { + esp_disks.push((dev, gpt)); + } + } + match data_disks.len() { + 1 => return Ok(data_disks.remove(0)), + 0 => {} + n => bail!("{n} disks carry the lockboot data partition -- refusing to guess"), + } + match esp_disks.len() { + 1 => Ok(esp_disks.remove(0)), + 0 => bail!("no lockboot boot disk found (no data partition, no ESP)"), + n => bail!("{n} disks have an ESP -- cannot identify the boot disk"), + } +} + +/// The type GUIDs of the entries in a `UEFI_GPT_DATA` (header, UINT64 count, entries). +fn partition_types(gpt: &[u8]) -> Vec<[u8; 16]> { + let size = u32::from_le_bytes(gpt[84..88].try_into().unwrap()) as usize; + gpt[100..] + .chunks_exact(size) + .map(|e| e[..16].try_into().unwrap()) + .collect() +} + +/// Whole disks under /sys/block, less the kinds that are never the boot disk. +fn whole_disks() -> Result> { + let mut out = Vec::new(); + for entry in std::fs::read_dir("/sys/block").context("read /sys/block")? { + let name = entry?.file_name(); + let n = name.to_string_lossy(); + if ["loop", "ram", "sr", "dm-", "md", "zram", "fd", "nbd"] + .iter() + .any(|p| n.starts_with(p)) + { + continue; + } + out.push(Path::new("/dev").join(&*n)); + } + Ok(out) +} diff --git a/crates/stage1/src/main.rs b/crates/stage1/src/main.rs index 0a4cfdc..67d3b1f 100644 --- a/crates/stage1/src/main.rs +++ b/crates/stage1/src/main.rs @@ -15,6 +15,8 @@ use std::os::fd::{AsRawFd, FromRawFd, OwnedFd}; use std::os::unix::ffi::OsStringExt; use std::thread; use std::time::{Duration, SystemTime, UNIX_EPOCH}; +mod bootdisk; + use vaportpm_attest as tpm; use vaportpm_attest::{PcrOps, Tpm}; @@ -76,7 +78,7 @@ fn main_inner() -> Result<()> { .to_string() .into_bytes() }; - println!("{}", tpm::attest(&nonce)?); + println!("{}", tpm::attest(&nonce, &bootdisk::gpt_digests()?)?); return Ok(()); } @@ -179,7 +181,7 @@ fn parse_json_to_config(data: Vec) -> Result { /// does not yet contain it). Code only — config is deliberately not bound. fn generate_pre_execution_attestation(binary_data: &[u8]) -> Result<()> { let path = format!("{}/stage1.attest", TMP_DIR); - let contents = tpm::attest(&sha256!(binary_data))?; + let contents = tpm::attest(&sha256!(binary_data), &bootdisk::gpt_digests()?)?; fs::write(&path, contents).context(format!("Failed to write attestation to {}", &path))?; Ok(()) } From bf98318ee7da9a1ece0c5d34a30736ecc860d609 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:31:46 +0000 Subject: [PATCH 2/6] deps: vaportpm-attest v0.4.1 Repin from the unreleased lockboot/vaportpm#13 commit (8b2c35c) to the v0.4.1 release commit 157ec04, guard =0.4.1. Since 8b2c35c: the attest CLI's --disk flag and boot-disk detection, and the 64 KiB cap on the GPT entry array, which stage1's uefi_gpt_data_device() read now gets. Cargo.lock: only the vaportpm-attest entry (make update-vaportpm). Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 4 ++-- Cargo.toml | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcd0f11..441d963 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2045,8 +2045,8 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vaportpm-attest" -version = "0.3.0" -source = "git+https://github.com/lockboot/vaportpm?rev=8b2c35c22829852bdd570eb5296499cd5f4f7c95#8b2c35c22829852bdd570eb5296499cd5f4f7c95" +version = "0.4.1" +source = "git+https://github.com/lockboot/vaportpm?rev=157ec04bf2efafc9d096dd063c904d9739156a86#157ec04bf2efafc9d096dd063c904d9739156a86" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index b6a6275..62b4988 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,9 @@ libc = "0.2" ed25519-compact = { version = "2", default-features = false } # Pinned to an immutable SHA + a `version` guard (the build fails if the rev drifts to a commit -# whose crate version isn't 0.3.0). Currently the vaportpm `gpt-digest` branch (lockboot/vaportpm#13, -# unreleased); move to the next release commit and bump the guard once it is cut. After changing -# the rev, `make update-vaportpm` re-resolves Cargo.lock. -vaportpm-attest = { git = "https://github.com/lockboot/vaportpm", rev = "8b2c35c22829852bdd570eb5296499cd5f4f7c95", version = "=0.3.0" } +# whose crate version isn't 0.4.1): the vaportpm v0.4.1 release commit. After changing the rev, +# `make update-vaportpm` re-resolves Cargo.lock. +vaportpm-attest = { git = "https://github.com/lockboot/vaportpm", rev = "157ec04bf2efafc9d096dd063c904d9739156a86", version = "=0.4.1" } reqwest = { version = "=0.12.24", default-features = false, features = ["blocking", "rustls-tls-webpki-roots-no-provider"] } rustls = { version = "=0.23.23", default-features = false, features = ["std", "tls12"] } From 656176e7f30de3d096cbc38e7a0b4acadb591911 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:31:46 +0000 Subject: [PATCH 3/6] ci: create the release as a draft, then publish action-gh-release with draft: false publishes the release before uploading its assets; an immutable release accepts no uploads once published, so the first tagged release would ship empty (vaportpm v0.4.0 did, vaportpm#14). Create it as a draft with the assets, then publish with `gh release edit --draft=false`. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5bf3d1..cea93d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -98,18 +98,26 @@ jobs: with: subject-checksums: subjects.sha256 - - name: Create UKI release + # Created as a draft with its assets, then published: a release is immutable from the + # moment it is published (repo setting, workspace tools/rulesets.sh) and then accepts no + # uploads, so publishing first leaves it empty (as vaportpm v0.4.0 was). + - name: Create draft UKI release uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3.0.1 with: tag_name: ${{ github.ref_name }} files: | uki-x86_64.zip uki-aarch64.zip - draft: false + draft: true prerelease: true generate_release_notes: true make_latest: true + - name: Publish UKI release + env: + GH_TOKEN: ${{ github.token }} + run: gh release edit "${{ github.ref_name }}" -R "${{ github.repository }}" --draft=false + # ---- stage1 runtime container image (tag: v*) ------------------------ # Minimal busybox + stage1 utility image; belongs to the stage1/UKI track. release-docker: From b6c3d3f74cd191667c5176b3f43852d278d0c0b8 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:14:38 +0000 Subject: [PATCH 4/6] uki: kernel 7.2.11 + stub 259.10 (FCOS 44.20261023.3.1); build the pinned RPMs only - fedora-deps.mk: kernel 7.0.12-201 -> 7.2.11-200.fc44, systemd-boot stub 259.6-1 -> 259.10-1.fc44 (make update-fedora-deps FCOS=44.20261023.3.1 SYSTEMD=259.10-1.fc44). - Kernel 7.2 has no crypto/hkdf.ko (nvme-auth no longer depends on it): dropped from the initramfs module list and from init, which stopped the boot at 'modprobe: hkdf failed'. - build.sh extracts exactly the kernel RPMs fedora-deps.mk pins instead of kernel-core-*.rpm, and takes the module directory from the same pin. A bump left the previous RPMs in the build dir and the wildcard picked the old kernel silently. - update-fedora-deps.py removes the previous versions' RPMs and the files derived from them. Tested: workspace make selftest, both arches, 7.2.11 in every boot log; a build with stray old-version RPM files present gives the same UKI; update-fedora-deps removes them. Co-Authored-By: Claude --- tools/build-uki/build.sh | 28 +++++++++++++++++++-------- tools/build-uki/fedora-deps.mk | 20 +++++++++---------- tools/build-uki/init | 1 - tools/build-uki/update-fedora-deps.py | 20 +++++++++++++++++++ 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/tools/build-uki/build.sh b/tools/build-uki/build.sh index 20de427..00e452a 100755 --- a/tools/build-uki/build.sh +++ b/tools/build-uki/build.sh @@ -27,11 +27,21 @@ if [ ! -f "${OUTPUT_DIR}/stub.efi" ]; then exit 1 fi -echo "Extracting kernel-core RPM (vmlinuz)..." -rpm2cpio "${OUTPUT_DIR}"/kernel-core-*.rpm | (cd "${OUTPUT_DIR}/tmp" && cpio --quiet -idmu) +# The kernel is exactly the one fedora-deps.mk pins, never "whichever RPM is in the directory": +# a bump leaves the previous version's RPMs behind until update-fedora-deps.py removes them. +KERNEL_NVR=$(sed -n 's/^FEDORA_KERNEL_VERSION := //p' "${SCRIPT_DIR}/fedora-deps.mk") +[ -n "${KERNEL_NVR}" ] || { echo "ERROR: FEDORA_KERNEL_VERSION not found in fedora-deps.mk"; exit 1; } +KERNEL_CORE_RPM="${OUTPUT_DIR}/kernel-core-${KERNEL_NVR}.${ARCH}.rpm" +KERNEL_MODULES_RPM="${OUTPUT_DIR}/kernel-modules-core-${KERNEL_NVR}.${ARCH}.rpm" +for rpm in "${KERNEL_CORE_RPM}" "${KERNEL_MODULES_RPM}"; do + [ -f "${rpm}" ] || { echo "ERROR: pinned RPM not found: ${rpm}"; exit 1; } +done + +echo "Extracting $(basename "${KERNEL_CORE_RPM}") (vmlinuz)..." +rpm2cpio "${KERNEL_CORE_RPM}" | (cd "${OUTPUT_DIR}/tmp" && cpio --quiet -idmu) -echo "Extracting kernel-modules-core RPM (core drivers including gve and ena)..." -rpm2cpio "${OUTPUT_DIR}"/kernel-modules-core-*.rpm | (cd "${OUTPUT_DIR}/tmp" && cpio --quiet -idmu) +echo "Extracting $(basename "${KERNEL_MODULES_RPM}") (core drivers including gve and ena)..." +rpm2cpio "${KERNEL_MODULES_RPM}" | (cd "${OUTPUT_DIR}/tmp" && cpio --quiet -idmu) if [ ! -d "${OUTPUT_DIR}/tmp/lib/modules" ]; then echo "ERROR: kernel modules directory not found after extraction!" @@ -39,8 +49,10 @@ if [ ! -d "${OUTPUT_DIR}/tmp/lib/modules" ]; then fi echo "Kernel and modules extracted successfully" -# Find the installed kernel version -KERNEL_VERSION=$(ls "${OUTPUT_DIR}/tmp/lib/modules/" | head -n1) +# The pinned kernel's module directory +KERNEL_VERSION="${KERNEL_NVR}.${ARCH}" +[ -d "${OUTPUT_DIR}/tmp/lib/modules/${KERNEL_VERSION}" ] \ + || { echo "ERROR: no modules for ${KERNEL_VERSION} in the extracted RPMs"; exit 1; } echo "Kernel version: ${KERNEL_VERSION}" # Extract kernel config @@ -143,8 +155,8 @@ REQUIRED_MODULES=( # NVMe disk driver, so stage2 can see the persistent volume (EC2 EBS is NVMe; # the harness also attaches its disk as NVMe). Never needed to boot (initramfs + # in-memory payload), so it was previously absent. Dep chain, loaded in order by - # init: hkdf -> nvme-auth, nvme-keyring -> nvme-core -> nvme. - "crypto/hkdf.ko" + # init: nvme-auth, nvme-keyring -> nvme-core -> nvme. (Up to kernel 7.0 nvme-auth also + # needed crypto/hkdf.ko, which 7.2 no longer has.) "drivers/nvme/common/nvme-auth.ko" "drivers/nvme/common/nvme-keyring.ko" "drivers/nvme/host/nvme-core.ko" diff --git a/tools/build-uki/fedora-deps.mk b/tools/build-uki/fedora-deps.mk index 36a7857..731ecc8 100644 --- a/tools/build-uki/fedora-deps.mk +++ b/tools/build-uki/fedora-deps.mk @@ -4,14 +4,14 @@ # GPG-verified against keys/RPM-GPG-KEY-fedora-44-primary at bump time and every build. FEDORA_RELEASE := 44 -FEDORA_KERNEL_VERSION := 7.0.12-201.fc44 -FEDORA_KERNEL_BASE_URL := https://kojipkgs.fedoraproject.org/packages/kernel/7.0.12/201.fc44/data/signed/6d9f90a6 -SYSTEMD_BOOT_VERSION := 259.6-1.fc44 -SYSTEMD_BOOT_BASE_URL := https://kojipkgs.fedoraproject.org/packages/systemd/259.6/1.fc44/data/signed/6d9f90a6 +FEDORA_KERNEL_VERSION := 7.2.11-200.fc44 +FEDORA_KERNEL_BASE_URL := https://kojipkgs.fedoraproject.org/packages/kernel/7.2.11/200.fc44/data/signed/6d9f90a6 +SYSTEMD_BOOT_VERSION := 259.10-1.fc44 +SYSTEMD_BOOT_BASE_URL := https://kojipkgs.fedoraproject.org/packages/systemd/259.10/1.fc44/data/signed/6d9f90a6 -FEDORA_KERNEL_CORE_SHA256_x86_64 := 5c549be1c1157dd58693344777cc7722e8c13350b6fcc96cacf72cd64d52f358 -FEDORA_KERNEL_CORE_SHA256_aarch64 := ccbd289e27706d00a6587360f7cf6a3c5742bd124ebe7c511b98a2ca9e73fe8c -FEDORA_KERNEL_MODULES_SHA256_x86_64 := f9f000cbc1ba3b49c2cbd105cc1ccc10d2d9f9e10802e92d6c966c8d1375857c -FEDORA_KERNEL_MODULES_SHA256_aarch64 := f282c61f947a9dee282b66b89b528876b1e4d9be505f15133811953419fefa28 -SYSTEMD_BOOT_SHA256_x86_64 := 6a3707da87640b2fca178e5c7e44cf92fa6321f3389c166f713b4f9b0411ff20 -SYSTEMD_BOOT_SHA256_aarch64 := 190a2559e97d381d2de3be786d55b359df1c0b4067427c025ef31ce4177e0d2a +FEDORA_KERNEL_CORE_SHA256_x86_64 := 6c993e04efdc0d45ae0e2542e045c37450a53ea968416c2e936eca5351988b24 +FEDORA_KERNEL_CORE_SHA256_aarch64 := a32bb946edb9b874c7a423d78867ca2196c934b14862632292b65db0730441a1 +FEDORA_KERNEL_MODULES_SHA256_x86_64 := 5c3d413174778693568a672167d92f60021d7c9b6e4810d90d4ad780f7bc7ce7 +FEDORA_KERNEL_MODULES_SHA256_aarch64 := 6b076ff02115a064f7d26d9c64861cb27e8c5aaa8b84ee6ab1ccb07d16484c2f +SYSTEMD_BOOT_SHA256_x86_64 := ef6e716e8ab4cc71b4174b6b4be4ef4643db669bfc4bb43c225825be2fede792 +SYSTEMD_BOOT_SHA256_aarch64 := f081569df04934e36fb7da3b4bef601c25f297d66fdb46bfc753b011aa8a9f7a diff --git a/tools/build-uki/init b/tools/build-uki/init index a7495b6..c0b460c 100644 --- a/tools/build-uki/init +++ b/tools/build-uki/init @@ -85,7 +85,6 @@ mod netfs mod erofs # NVMe disk driver (EC2 EBS + the harness disk are NVMe). Deps in order. -mod hkdf mod nvme-auth mod nvme-keyring mod nvme-core diff --git a/tools/build-uki/update-fedora-deps.py b/tools/build-uki/update-fedora-deps.py index 9f2db7b..2286bd8 100755 --- a/tools/build-uki/update-fedora-deps.py +++ b/tools/build-uki/update-fedora-deps.py @@ -143,6 +143,25 @@ def download_verify_sha256(binrpm, srcname, nvr, arch, keyfile, sigkey): return h.hexdigest() +def remove_previous(nvr_for): + """Remove what earlier pins left in the per-arch build dirs: RPMs of other versions, and the + files derived from them (the *.rpm symlinks, stub.efi). Otherwise make sees them as up to date + (a downloaded RPM keeps the server's mtime) and the next build silently reuses the old ones.""" + for arch in ARCHES: + d = os.path.join(HERE, arch) + if not os.path.isdir(d): + continue + keep = {f"{binrpm}-{nvr_for[srcname]}.{arch}.rpm" for _, binrpm, srcname in PACKAGES} + stale = [n for n in os.listdir(d) + if any(n.startswith(binrpm + "-") and n.endswith(".rpm") for _, binrpm, _ in PACKAGES) + and n not in keep] + stale += [n for n in ("kernel-core.rpm", "kernel-modules-core.rpm", "stub.efi") + if os.path.lexists(os.path.join(d, n))] + for n in sorted(stale): + os.remove(os.path.join(d, n)) + print(f"removed {arch}/{n}") + + def main(): ap = argparse.ArgumentParser(description="Regenerate fedora-deps.mk (GPG-verified kernel + stub pins).") ap.add_argument("--fcos", help="Fedora CoreOS build version, e.g. 44.20260621.3.1") @@ -200,6 +219,7 @@ def main(): for arch in ARCHES: f.write(f"{stem}_SHA256_{arch} := {shas[f'{stem}_SHA256_{arch}']}\n") print(f"wrote {out}") + remove_previous(nvr_for) if __name__ == "__main__": From 77ebd306c1580a15e1591c3a4ce6c69f952423cd Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:14:38 +0000 Subject: [PATCH 5/6] release tooling: remove tools/publish.sh; QEMU for the release-docker job - tools/publish.sh uploaded every UKI to the same object name, so a new release overwrote the one running instances pin by sha256, and it printed a _stage1 snippet stage0 rejects (https, no payload wrapper). lockboot-deploy create replaces it. - release-docker builds linux/amd64,linux/arm64 and Dockerfile.runtime's builder stage runs commands per platform: add docker/setup-qemu-action, as stage0 and stage2 have. Untested until a tag. Co-Authored-By: Claude --- .github/workflows/build.yml | 4 ++ README.md | 2 +- tools/publish.sh | 94 ------------------------------------- 3 files changed, 5 insertions(+), 95 deletions(-) delete mode 100755 tools/publish.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cea93d1..7224b0a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -146,6 +146,10 @@ jobs: name: uki-aarch64 path: tools/build-uki/aarch64 + # Dockerfile.runtime's builder stage runs commands for each target platform. + - name: Set up QEMU (arm64 layers on the amd64 runner) + uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 diff --git a/README.md b/README.md index 23f4cf3..e6c3d72 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ lockboot-deploy validate ./deploy # check against the admission rul lockboot-deploy modify ./deploy --add-base-url http://cdn3 # add / --remove-base-url a mirror ``` -`create` writes `deploy//{linux.efi,stage2}` (+ `.sig` in signed mode) and merges `deploy/user-data.json`; sync the directory to each mirror and pass `user-data.json` as the instance's user-data. It shares the `metadata` types with the stage1 verifier, so what it emits is exactly what stage0/stage1 accept. (`tools/publish.sh` remains as a simpler UKI-only uploader; the bootable cloud image — the stage0 Secure Boot root — is published from the [stage0 repo](https://github.com/lockboot/stage0).) +`create` writes `deploy//{linux.efi,stage2}` (+ `.sig` in signed mode) and merges `deploy/user-data.json`; sync the directory to each mirror and pass `user-data.json` as the instance's user-data. It shares the `metadata` types with the stage1 verifier, so what it emits is exactly what stage0/stage1 accept. (The bootable cloud image — the stage0 Secure Boot root — is published from the [stage0 repo](https://github.com/lockboot/stage0).) The release key comes from `lockboot-deploy keygen --out release.pem --pub release.pub.b64` (a PKCS#8 ed25519 key; randomness is read from `/dev/urandom`, so it builds with no host C toolchain), and `lockboot-deploy sign --domain --key release.pem --in --out .sig` produces one domain-separated signature — the low-level primitive the test Makefile drives for each artifact. diff --git a/tools/publish.sh b/tools/publish.sh deleted file mode 100755 index 5d6518d..0000000 --- a/tools/publish.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -# Publish a netboot UKI (linux.efi) so stage0 can fetch it, and print the matching -# _stage1 user-data block (sha256 admission mode). -# -# Unlike the stage0 publishers (which bake a cloud image), the UKI is just a file -# served over HTTP(S): stage0 downloads it, verifies the pinned sha256, measures -# it into PCR 14, and chain-loads it. The pin MUST be the sha256 of the FINAL -# (post-sbsign) linux.efi — exactly the bytes uploaded here. -# -# Usage: ./publish.sh [version] -# dest-uri : s3://bucket/prefix or gs://bucket/prefix -# arch : x86_64 | aarch64 -# version : a v* release tag, or 'local' (default) to use a local build -# -# Example: ./publish.sh s3://lockboot/uki x86_64 v0.3.0 -# ./publish.sh gs://lockboot/uki aarch64 local - -set -euo pipefail - -if [ $# -lt 2 ]; then - echo "Usage: $0 [version]" - exit 1 -fi - -DEST_URI="${1%/}" # strip trailing slash -ARCH="$2" -VERSION="${3:-local}" - -if [ "${ARCH}" != "x86_64" ] && [ "${ARCH}" != "aarch64" ]; then - echo "Error: arch must be x86_64 or aarch64"; exit 1 -fi - -# Resolve the UKI: local build, or a verified v* release artifact. -if [ "${VERSION}" != "local" ]; then - TEMP_DIR=$(mktemp -d); trap "rm -rf ${TEMP_DIR}" EXIT - GH_REPO=$(git remote get-url origin | sed 's/.*github.com[:/]\(.*\)\.git/\1/' || echo "") - [ -n "${GH_REPO}" ] || { echo "Error: could not determine GitHub repository"; exit 1; } - echo "Downloading uki-${ARCH}.zip from release ${VERSION}..." - gh release download "${VERSION}" --repo "${GH_REPO}" --pattern "uki-${ARCH}.zip" --dir "${TEMP_DIR}" - gh attestation verify "${TEMP_DIR}/uki-${ARCH}.zip" --repo "${GH_REPO}" \ - || { echo "Error: attestation verification failed"; exit 1; } - unzip -q "${TEMP_DIR}/uki-${ARCH}.zip" -d "${TEMP_DIR}" - WORK_DIR="${TEMP_DIR}" -else - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" - WORK_DIR="${REPO_ROOT}/tools/build-uki/${ARCH}" -fi - -UKI_FILE="${WORK_DIR}/linux.efi" -[ -f "${UKI_FILE}" ] || { echo "Error: ${UKI_FILE} not found (build the UKI first)"; exit 1; } - -# Pin = sha256 of the bytes we upload. Cross-check against the build's recorded -# pin if present, to catch a stale/mismatched linux.efi.sha256. -SHA256=$(sha256sum "${UKI_FILE}" | awk '{print $1}') -if [ -f "${WORK_DIR}/linux.efi.sha256" ]; then - RECORDED=$(awk '{print $1}' "${WORK_DIR}/linux.efi.sha256") - if [ "${RECORDED}" != "${SHA256}" ]; then - echo "Error: linux.efi.sha256 (${RECORDED}) != actual (${SHA256})"; exit 1 - fi -fi - -KEY="linux-${ARCH}.efi" -OBJECT="${DEST_URI}/${KEY}" - -case "${DEST_URI}" in - s3://*) - BUCKET="${DEST_URI#s3://}"; BUCKET="${BUCKET%%/*}" - PREFIX="${DEST_URI#s3://${BUCKET}}"; PREFIX="${PREFIX#/}" - aws s3 cp "${UKI_FILE}" "${OBJECT}" - URL="https://${BUCKET}.s3.amazonaws.com/${PREFIX:+${PREFIX}/}${KEY}" - ;; - gs://*) - BUCKET="${DEST_URI#gs://}"; BUCKET="${BUCKET%%/*}" - PREFIX="${DEST_URI#gs://${BUCKET}}"; PREFIX="${PREFIX#/}" - gcloud storage cp "${UKI_FILE}" "${OBJECT}" - URL="https://storage.googleapis.com/${BUCKET}/${PREFIX:+${PREFIX}/}${KEY}" - ;; - *) - echo "Error: dest-uri must start with s3:// or gs://"; exit 1 - ;; -esac - -echo "Uploaded: ${OBJECT}" -echo "sha256: ${SHA256}" -echo "" -echo "Paste into instance user-data (_stage1, sha256 admission mode):" -cat < Date: Wed, 18 Nov 2026 15:11:14 +0000 Subject: [PATCH 6/6] build: UKI version from the commit date and the pinned kernel; flat per-arch artifact The os-release embedded in the UKI carried the build date's yy.mm, so a commit built a different UKI in a different month, and a hardcoded "fc41" / "Fedora 41" on an fc44 kernel. The yy.mm is now the committer date (UTC) of the commit being built, passed in by the Makefile (the build image has no git); build.sh refuses to run without it. The Fedora tag is the dist tag of the kernel fedora-deps.mk pins. The uki- artifact is flat again. Since build//stage2 joined the upload list, upload-artifact rooted the artifact at the repo root, so release-docker's download into tools/build-uki/ would have nested the files where Dockerfile.runtime does not look. The build job now collects the release files into one directory and uploads that. The release job still extracts each zip into contents/, so attestation subjects stay distinct: /. Tested: the x86_64 UKI is byte-identical to the previous build with the date change alone, and follows a forced COMMIT_YEAR_MONTH; both UKIs embed VERSION_ID=26.11.fc44; workspace `make selftest` passes on both arches. Not tested: the artifact layout (the next CI run shows it) and release-docker (first runs at a tag). Co-Authored-By: Claude --- .github/workflows/build.yml | 21 +++++++++++---------- Makefile | 7 ++++++- tools/build-uki/build.sh | 15 +++++++++------ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7224b0a..face77f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,20 +41,21 @@ jobs: - name: Build UKI + example-stage2 for ${{ matrix.arch }} run: make ${{ matrix.arch }} stage2-${{ matrix.arch }} - # UKI (stage1) track: the netboot payload + its sha256 pin, - # busybox/stage1 for the runtime image, and the example-stage2 leaf. + # UKI (stage1) track: the netboot payload + its sha256 pin, busybox/stage1 for the runtime + # image, and the example-stage2 leaf. Collected into one directory so the artifact holds + # exactly these files at its root: upload-artifact roots an artifact at the common ancestor + # of its paths, and the release zip and release-docker's download both take that layout. + - name: Collect release files for ${{ matrix.arch }} + run: | + mkdir -p dist/${{ matrix.arch }} + cp tools/build-uki/${{ matrix.arch }}/{linux.efi,linux.efi.sha256,stage1.replay.json,os-release,busybox,stage1} \ + build/${{ matrix.arch }}/stage2 dist/${{ matrix.arch }}/ + - name: Upload UKI artifacts for ${{ matrix.arch }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: uki-${{ matrix.arch }} - path: | - tools/build-uki/${{ matrix.arch }}/linux.efi - tools/build-uki/${{ matrix.arch }}/linux.efi.sha256 - tools/build-uki/${{ matrix.arch }}/stage1.replay.json - tools/build-uki/${{ matrix.arch }}/os-release - tools/build-uki/${{ matrix.arch }}/busybox - tools/build-uki/${{ matrix.arch }}/stage1 - build/${{ matrix.arch }}/stage2 + path: dist/${{ matrix.arch }}/* # ---- UKI (stage1) release track (tag: v*) ---------------------------- release-uki: diff --git a/Makefile b/Makefile index 026a6b8..c38e82e 100644 --- a/Makefile +++ b/Makefile @@ -79,8 +79,13 @@ tools/build-uki/%/kernel-modules-core.rpm: docker-build-base # Build the netboot UKI (linux.efi) for a specific architecture. build.sh extracts # a rootfs via the HOST docker daemon, so DOCKER_OPT_DOCKER forwards the socket. +# +# The UKI embeds an os-release whose version is yy.mm. It is taken from the committer date (UTC) +# of the commit being built, not from the build date, so a commit builds the same UKI in any +# month. Read here because the build image has no git. +COMMIT_YEAR_MONTH := $(shell TZ=UTC git log -1 --format=%cd --date=format-local:%y.%m) tools/build-uki/%/linux.efi: tools/build-uki/%/busybox tools/build-uki/%/stage1 tools/build-uki/%/stub.efi tools/build-uki/%/kernel-core.rpm tools/build-uki/%/kernel-modules-core.rpm tools/build-uki/mkuki - $(DOCKER_RUN) $(DOCKER_OPT_DOCKER) -e ARCH=$* \ + $(DOCKER_RUN) $(DOCKER_OPT_DOCKER) -e ARCH=$* -e COMMIT_YEAR_MONTH=$(COMMIT_YEAR_MONTH) \ $(BUILD_IMAGE) ./tools/build-uki/build.sh # Build AND extract stage1 inside the one container step, so the cp runs where diff --git a/tools/build-uki/build.sh b/tools/build-uki/build.sh index 00e452a..5944c88 100755 --- a/tools/build-uki/build.sh +++ b/tools/build-uki/build.sh @@ -7,7 +7,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Get architecture from environment (default to x86_64) ARCH=${ARCH:-x86_64} -echo "=== Building UKI for Fedora 41 (${ARCH}) ===" +echo "=== Building UKI (${ARCH}) ===" # Output directory (same as dependencies - everything self-contained) OUTPUT_DIR="${SCRIPT_DIR}/${ARCH}" @@ -20,7 +20,7 @@ if [ "${ARCH}" != "x86_64" ] && [ "${ARCH}" != "aarch64" ]; then exit 1 fi -# Use systemd-boot stub extracted by Makefile from Fedora 41 RPM (systemd v256) +# Use the systemd-boot stub the Makefile extracted from the Fedora RPM fedora-deps.mk pins if [ ! -f "${OUTPUT_DIR}/stub.efi" ]; then echo "ERROR: systemd-boot stub not found at ${OUTPUT_DIR}/stub.efi" echo "Please run 'make tools/build-uki/${ARCH}/stub.efi' first" @@ -31,6 +31,8 @@ fi # a bump leaves the previous version's RPMs behind until update-fedora-deps.py removes them. KERNEL_NVR=$(sed -n 's/^FEDORA_KERNEL_VERSION := //p' "${SCRIPT_DIR}/fedora-deps.mk") [ -n "${KERNEL_NVR}" ] || { echo "ERROR: FEDORA_KERNEL_VERSION not found in fedora-deps.mk"; exit 1; } +# The kernel's dist tag (fc44 in 7.2.11-200.fc44) names the Fedora release in os-release. +FEDORA_DIST="${KERNEL_NVR##*.}" KERNEL_CORE_RPM="${OUTPUT_DIR}/kernel-core-${KERNEL_NVR}.${ARCH}.rpm" KERNEL_MODULES_RPM="${OUTPUT_DIR}/kernel-modules-core-${KERNEL_NVR}.${ARCH}.rpm" for rpm in "${KERNEL_CORE_RPM}" "${KERNEL_MODULES_RPM}"; do @@ -263,15 +265,16 @@ echo "${CMDLINE_SERIAL} ${CMDLINE_COMMON}" > "${CMDLINE_PATH}" # Set SOURCE_DATE_EPOCH for reproducible builds export SOURCE_DATE_EPOCH=0 -# Generate version with year.month format (e.g., 26.02) -YEAR_MONTH=$(date +%y.%m) -OSREL_VERSION="${YEAR_MONTH} ${ARCH} (Fedora 41)" +# Version in year.month format (e.g., 26.02): the built commit's committer date, from the Makefile. +# Never the build date: os-release is embedded in the UKI, so it would change the measured bytes. +YEAR_MONTH="${COMMIT_YEAR_MONTH:?set COMMIT_YEAR_MONTH (yy.mm of the commit being built; the Makefile does)}" +OSREL_VERSION="${YEAR_MONTH} ${ARCH} (Fedora ${FEDORA_DIST#fc})" OSREL_NAME="Lock.Boot" # Combine stub + kernel + initrd into UKI # Use os-release from extracted RPM if available, otherwise create minimal one OSREL_PATH="${OUTPUT_DIR}/os-release" echo "ID=lockboot" > "${OSREL_PATH}" -echo "VERSION_ID=${YEAR_MONTH}.fc41" >> "${OSREL_PATH}" +echo "VERSION_ID=${YEAR_MONTH}.${FEDORA_DIST}" >> "${OSREL_PATH}" echo "VERSION=\"${OSREL_VERSION}\"" >> "${OSREL_PATH}" echo "NAME=\"${OSREL_NAME}\"" >> "${OSREL_PATH}" echo "PRETTY_NAME=\"${OSREL_NAME} ${OSREL_VERSION}\"" >> "${OSREL_PATH}"