From 3a2cf0a8781f9de2f8a318a7e68200d4b98ef954 Mon Sep 17 00:00:00 2001 From: hanthor Date: Sat, 19 Sep 2026 11:32:57 +0000 Subject: [PATCH 1/4] Bump the NVIDIA driver to the release that compiles against kernel 7.2 The base image pin has been frozen since Hummingbird moved to kernel 7.2. Every attempt to advance it -- #122 is the current one -- fails kernel_cache 22 minutes in, building the NVIDIA open module: nvidia/os-interface.c: In function 'os_get_current_process_name': nvidia/os-interface.c:764:5: error: implicit declaration of function 'strncpy' [-Wimplicit-function-declaration] 764 | strncpy(buf, current->comm, len - 1); make[4]: *** [.../7.2.5-200.fc44.x86_64/...: nvidia/os-interface.o] Error 1 A frozen base pin means no kernel security updates reach the flavored images, so this is worth fixing properly rather than pinning around. The cause is the kernel finishing its strscpy migration and removing strncpy, and the fix is upstream's, not ours. Read from the vendor source at each tag: 595.84 strncpy(buf, current->comm, len - 1); 595.91.07 strscpy 595.99.02 if (strscpy(buf, current->comm, len) < 0) { So 595.99.02 carries the migration, and it is also what https://download.nvidia.com/XFree86/Linux-x86_64/latest.txt designates today -- which is the rule the pin comment already states. This is that policy working, not a hand-picked version: read latest.txt, take the SHA-256 NVIDIA publishes beside the installer. The base bump rides along deliberately. On the current base the old driver compiles fine, so a driver-only change proves nothing -- the two can only be verified together, and kernel_cache on this PR is that verification. Both ARG BASE_IMAGE= lines move together, as `just check` requires. The cache tag rotates 1ce05c4b16fafe9c -> f1e31a1dee27ffaa, so the three cached flavors compile the kernel once. That is the intended cost: the tag moving is what proves the new base and driver were actually built, rather than a stale cache being reused (#166, #171). Closes #173. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01W6BYLUD6KBzF8rBFXKjP7M --- Containerfile | 2 +- Containerfile.kernel | 2 +- scripts/install-nvidia.sh | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Containerfile b/Containerfile index 52edb70a..2003c6f6 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,4 @@ -ARG BASE_IMAGE=quay.io/hummingbird-community/bootc-os:latest@sha256:c5539f9ed4d93aab6bd41e4f5aef8ab83055f3f9e855a47b69fadb7420d0d1df +ARG BASE_IMAGE=quay.io/hummingbird-community/bootc-os:latest@sha256:db1007fdcda076f2d7fd0e2adfe998141dd1908b8f66c732654f762c6a8b2728 # The package factory publishes a complete, digest-addressable RPM repository. # Keep this pin in Utah so an image build is reproducible and can be reviewed # against the exact package set it consumes. diff --git a/Containerfile.kernel b/Containerfile.kernel index 94f51404..69819730 100644 --- a/Containerfile.kernel +++ b/Containerfile.kernel @@ -16,7 +16,7 @@ # # The cache image's own build has no /utah-cache, so the same scripts take their # source-build path here. There is no second implementation to drift. -ARG BASE_IMAGE=quay.io/hummingbird-community/bootc-os:latest@sha256:c5539f9ed4d93aab6bd41e4f5aef8ab83055f3f9e855a47b69fadb7420d0d1df +ARG BASE_IMAGE=quay.io/hummingbird-community/bootc-os:latest@sha256:db1007fdcda076f2d7fd0e2adfe998141dd1908b8f66c732654f762c6a8b2728 FROM ${BASE_IMAGE} AS builder diff --git a/scripts/install-nvidia.sh b/scripts/install-nvidia.sh index 8105eb39..1b01222e 100755 --- a/scripts/install-nvidia.sh +++ b/scripts/install-nvidia.sh @@ -49,7 +49,16 @@ modules_only="${UTAH_NVIDIA_MODULES_ONLY:-}" # NVIDIA's own designation of the current driver, not a hand-picked directory # listing: https://download.nvidia.com/XFree86/Linux-x86_64/latest.txt -driver_version="${UTAH_NVIDIA_DRIVER_VERSION:-595.84}" +# +# 595.84 stopped compiling when Hummingbird's base moved to kernel 7.2: +# +# os-interface.c:764: error: implicit declaration of function 'strncpy' +# +# The kernel completed its strscpy migration and removed strncpy, and upstream +# followed in 595.99.02, which replaces that call with strscpy and is what +# latest.txt designates today. So this is the pin policy above doing its job +# rather than a workaround: read latest.txt, take the digest beside it (#173). +driver_version="${UTAH_NVIDIA_DRIVER_VERSION:-595.99.02}" run="NVIDIA-Linux-x86_64-${driver_version}.run" url="https://download.nvidia.com/XFree86/Linux-x86_64/${driver_version}/${run}" # The vendor `.run` is executed as root during composition, so it is verified @@ -60,7 +69,7 @@ url="https://download.nvidia.com/XFree86/Linux-x86_64/${driver_version}/${run}" # beyond the TLS channel it was meant to backstop. The constant is NVIDIA's # published SHA-256 for the pinned driver version; the two move together, as # does UTAH_NVIDIA_RUN_SHA256 when UTAH_NVIDIA_DRIVER_VERSION is overridden. -NVIDIA_RUN_SHA256="${UTAH_NVIDIA_RUN_SHA256:-99c404e52131bf27bca6da0268dcce3ebedc7a73ab174071a995cf1a6c5eba06}" +NVIDIA_RUN_SHA256="${UTAH_NVIDIA_RUN_SHA256:-e87477958bf763070549324bd5ad6c948eba6ed210e44005b3eff84940f6e1ec}" ogc_release="" [ -f /usr/lib/utah/ogc-kernel-release ] && ogc_release="$(cat /usr/lib/utah/ogc-kernel-release)" From f690a036e1e5b378a596efac99fac3d6b33e6d26 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 19 Sep 2026 12:51:29 +0000 Subject: [PATCH 2/4] Make the shim mirroring say what it could not find, and pair the kernel-devel hash with its kernel The base bump to a kernel-7.2 Hummingbird regressed build_main. It failed deterministically, three attempts out of three, and printed nothing: the last line of the log was "Utah desktop contract passed", then exit 1. The step was four predicates chained with && at the tail of a long RUN -- shim_version="$(rpm -q --qf '%{VERSION}-%{RELEASE}' shim-x64)" && \ test -d /usr/lib/bootupd/updates/EFI/fedora && \ install -d ... && cp -a ... -- so nothing distinguished "shim-x64 is not in this base" from "shim-x64 is installed but staged nothing", and those have different answers. The chain now lives in scripts/mirror-shim.sh, which names the failing predicate, lists what the bootupd tree actually contains when the payload is absent, and says that a base which dropped shim-x64 needs it added to the package contract rather than the step skipped. This does not yet fix the build; it makes the next run say which of the two happened, which the previous three runs could not. The second change is the review finding on the same bump. KERNEL_DEVEL_SHA256 guards an unsigned koji download and is documented as a constant precisely because "the kernel cannot change without BASE_IMAGE changing" -- which is the reason it must move when BASE_IMAGE does, and it did not. It stayed pinned to 7.1.8-100.fc43 while the base moved to 7.2.5-200.fc44. Nothing failed, because the dnf path satisfied 7.2 and the fallback never ran; it would have failed the first time the enabled repositories dropped the kernel, which is the single situation the fallback exists for. The hash is now the real one for kernel-devel-7.2.5-200.fc44.x86_64, taken from koji, and it is recorded beside KERNEL_DEVEL_NEVR. A mismatch between the recorded kernel and the booted one now fails immediately with both versions named, instead of after fetching 60 MB to compare against a hash that cannot match. Tests drive the real code: mirror-shim.sh runs against a stub rpm and a fake bootupd tree for all three outcomes, asserting the two failures do not share a message; the NEVR guard is extracted and executed for both the matching and mismatched kernel. 204 tests, OK. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01W6BYLUD6KBzF8rBFXKjP7M --- Containerfile | 19 +++---- Justfile | 1 + scripts/install-nvidia.sh | 29 ++++++++--- scripts/mirror-shim.sh | 46 +++++++++++++++++ tests/test_kernel_devel_pin.py | 74 +++++++++++++++++++++++++++ tests/test_mirror_shim.py | 92 ++++++++++++++++++++++++++++++++++ 6 files changed, 244 insertions(+), 17 deletions(-) create mode 100755 scripts/mirror-shim.sh create mode 100644 tests/test_kernel_devel_pin.py create mode 100644 tests/test_mirror_shim.py diff --git a/Containerfile b/Containerfile index 2003c6f6..fb3ff5a8 100644 --- a/Containerfile +++ b/Containerfile @@ -63,6 +63,7 @@ COPY scripts/install-packages.py \ scripts/configure-branding.sh \ scripts/verify-desktop-contract.py \ scripts/verify-gnome-extensions.py \ + scripts/mirror-shim.sh \ /tmp/utah-scripts/ # Common publishes Bluefin artwork, desktop defaults, Brewfiles, and setup # hooks in a separate profile from its shared system files. Both are required: @@ -83,7 +84,8 @@ RUN for pair in install-packages.py:utah-install-packages \ configure-services.sh:utah-configure-services \ configure-branding.sh:utah-configure-branding \ verify-desktop-contract.py:utah-verify-desktop-contract \ - verify-gnome-extensions.py:utah-verify-gnome-extensions; do \ + verify-gnome-extensions.py:utah-verify-gnome-extensions \ + mirror-shim.sh:utah-mirror-shim; do \ install -Dm 0755 "/tmp/utah-scripts/${pair%%:*}" "/usr/local/libexec/${pair##*:}" || exit 1; \ done && \ cp -a /tmp/utah-common/. / && \ @@ -156,12 +158,10 @@ ARG UUPD_TIMER_SHA256=bbb5f098ec33d047bdef571e0bc112364df157e0f92d73e0febab703c4 # it applies the desktop service policy, login defaults, update policy, and # removes the extension build toolchain before the final cleanup. # -# The shim mirroring at the end belongs to the same step. Fedora's shim package -# stages its EFI payload under bootupd's update tree, while bootupd discovers -# image-provided EFI components under /usr/lib/efi. Mirroring the signed -# payload into bootupd's component layout lets bootc create a generic disk -# image without depending on the build host's ESP. It was a layer of its own -# and cost forty seconds to commit a few megabytes. +# The shim mirroring at the end belongs to the same step: it was a layer of its +# own and cost forty seconds to commit a few megabytes. It lives in +# scripts/mirror-shim.sh rather than inline, because as a bare && chain a +# failure printed nothing at all -- see the comment at the top of that script. RUN mkdir -p /tmp/uupd && \ curl -fsSL "https://github.com/ublue-os/uupd/releases/download/${UUPD_VERSION}/uupd_Linux_x86_64.tar.gz" \ -o /tmp/uupd/uupd_Linux_x86_64.tar.gz && \ @@ -179,10 +179,7 @@ RUN mkdir -p /tmp/uupd && \ ENABLE_SSHD="${ENABLE_SSHD}" /usr/local/libexec/utah-configure-services && \ /usr/local/libexec/utah-configure-branding && \ /usr/local/libexec/utah-verify-desktop-contract /usr/share/utah/bluefin-desktop.toml && \ - shim_version="$(rpm -q --qf '%{VERSION}-%{RELEASE}' shim-x64)" && \ - test -d /usr/lib/bootupd/updates/EFI/fedora && \ - install -d "/usr/lib/efi/shim/${shim_version}/EFI/fedora" && \ - cp -a /usr/lib/bootupd/updates/EFI/fedora/. "/usr/lib/efi/shim/${shim_version}/EFI/fedora/" + /usr/local/libexec/utah-mirror-shim # Dakota-compatible flavors: OGC is built and asserted before NVIDIA so the # NVIDIA path can bind its module to the exact kernel tree it will boot. diff --git a/Justfile b/Justfile index c7a5a4c8..a758aeee 100644 --- a/Justfile +++ b/Justfile @@ -46,6 +46,7 @@ check: test -f scripts/configure-branding.sh test -f scripts/verify-desktop-contract.py test -f scripts/verify-gnome-extensions.py + test -f scripts/mirror-shim.sh test -f contracts/bluefin-desktop.toml # The reusable image workflow checks out this repository without # submodules. Populate them here before validating the source contract; diff --git a/scripts/install-nvidia.sh b/scripts/install-nvidia.sh index 1b01222e..5532fe13 100755 --- a/scripts/install-nvidia.sh +++ b/scripts/install-nvidia.sh @@ -101,13 +101,13 @@ fi # attempt at a source build. It is needed only to compile against, so it goes in # here and comes out again below. # -# It is not in the repositories this image enables either. The base kernel is a -# Fedora 43 build, 7.1.8-100.fc43, and Utah enables only Hummingbird plus its -# own package factory: +# It may not be in the repositories this image enables either. Utah enables only +# Hummingbird plus its own package factory, and when the base kernel is not in +# those: # -# No match for argument: kernel-devel-7.1.8-100.fc43.x86_64 +# No match for argument: kernel-devel- # -# Adding the Fedora 43 repository would not fix it for long, because a +# Adding the matching Fedora repository would not fix it for long, because a # repository only carries the current kernel and this image is pinned to a base # whose kernel will not move. Fedora own build system keeps every build # indefinitely, so that is where this comes from, addressed by exact NEVR. @@ -115,7 +115,17 @@ fi # Those RPMs are unsigned at that path, so the download is checked against a # hash recorded here instead. It is a constant because the base image is pinned # by digest: the kernel cannot change without BASE_IMAGE changing. -KERNEL_DEVEL_SHA256="${UTAH_KERNEL_DEVEL_SHA256:-b2b504c42b94875af88d666d64ca91000ff30439e74157723a188f54ceebc5ca}" +# +# Which is exactly why the hash has to move with BASE_IMAGE, and why it is +# recorded here beside the kernel it was taken from rather than on its own. The +# 7.2 base bump left this pinned to 7.1.8-100.fc43 for one revision: the dnf +# path above satisfied 7.2 and the fallback never ran, so nothing failed and +# nothing said the constant had gone stale. It would have failed the first time +# the enabled repositories dropped the kernel -- the precise situation this +# fallback exists for. Pairing the two makes that mismatch loud and immediate +# instead of latent, and costs nothing when they agree. +KERNEL_DEVEL_NEVR="7.2.5-200.fc44.x86_64" +KERNEL_DEVEL_SHA256="${UTAH_KERNEL_DEVEL_SHA256:-02467ce35055d553db0babd680aa429c2d0b8d514469768730e03b89326a0703}" build_tree="/usr/lib/modules/${kernel}/build" installed_kernel_devel="" @@ -144,6 +154,13 @@ ensure_toolchain() { installed_kernel_devel="kernel-devel-${kernel}" else local arch nv ver rel koji rpmfile actual + if [ "${kernel}" != "${KERNEL_DEVEL_NEVR}" ]; then + echo "KERNEL_DEVEL_SHA256 was recorded for kernel ${KERNEL_DEVEL_NEVR}," >&2 + echo "but this image boots ${kernel}. The hash cannot match, so the" >&2 + echo "download below would fail after fetching 60 MB. Re-record both" >&2 + echo "constants for ${kernel} when bumping BASE_IMAGE." >&2 + exit 1 + fi arch="${kernel##*.}"; nv="${kernel%.*}"; ver="${nv%%-*}"; rel="${nv#*-}" koji="https://kojipkgs.fedoraproject.org/packages/kernel/${ver}/${rel}/${arch}" rpmfile="kernel-devel-${ver}-${rel}.${arch}.rpm" diff --git a/scripts/mirror-shim.sh b/scripts/mirror-shim.sh new file mode 100755 index 00000000..058c1147 --- /dev/null +++ b/scripts/mirror-shim.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Mirror the signed shim payload into bootupd's component layout. +# +# Fedora's shim package stages its EFI payload under bootupd's update tree, +# while bootupd discovers image-provided EFI components under /usr/lib/efi. +# Mirroring the payload lets bootc create a generic disk image without +# depending on the build host's ESP. +# +# This was four predicates chained with && at the tail of a long Containerfile +# RUN. When the base image bumped to a kernel-7.2 Hummingbird, the step began +# failing with no output at all: the last line of a successful build was +# "Utah desktop contract passed", then exit 1. Nothing said whether shim-x64 +# was missing, or the bootupd tree was, or the copy failed -- and each has a +# different answer. A build that fails must say what it could not find. +set -euo pipefail + +BOOTUPD_EFI="${BOOTUPD_EFI:-/usr/lib/bootupd/updates/EFI/fedora}" +SHIM_ROOT="${SHIM_ROOT:-/usr/lib/efi/shim}" + +fail() { + echo "ERROR: shim mirroring: $*" >&2 + exit 1 +} + +if ! shim_version="$(rpm -q --qf '%{VERSION}-%{RELEASE}' shim-x64 2>&1)"; then + fail "shim-x64 is not installed in this image (rpm -q said: ${shim_version}). + The signed EFI payload comes from that package, so bootc cannot build a + generic disk image without it. If the base image dropped shim-x64, it has to + be added to the package contract rather than skipped here." +fi + +if [[ ! -d "${BOOTUPD_EFI}" ]]; then + parent="$(dirname "${BOOTUPD_EFI}")" + echo "shim-x64 ${shim_version} is installed but staged nothing at ${BOOTUPD_EFI}." >&2 + if [[ -d "${parent}" ]]; then + echo " ${parent} contains: $(ls -A "${parent}" 2>/dev/null | tr '\n' ' ')" >&2 + else + echo " ${parent} does not exist either." >&2 + fi + fail "no EFI payload to mirror at ${BOOTUPD_EFI}" +fi + +target="${SHIM_ROOT}/${shim_version}/EFI/fedora" +install -d "${target}" +cp -a "${BOOTUPD_EFI}/." "${target}/" +echo "Mirrored shim-x64 ${shim_version} EFI payload into ${target}" diff --git a/tests/test_kernel_devel_pin.py b/tests/test_kernel_devel_pin.py new file mode 100644 index 00000000..6c7ad299 --- /dev/null +++ b/tests/test_kernel_devel_pin.py @@ -0,0 +1,74 @@ +"""KERNEL_DEVEL_SHA256 must not outlive the kernel it was recorded for. + +The koji fallback in install-nvidia.sh downloads an unsigned kernel-devel and +checks it against a hash committed in the script. The hash is a constant +because the base image is pinned by digest -- which is exactly why it has to +move when BASE_IMAGE does. The 7.2 base bump left it pinned to 7.1.8-100.fc43 +for a revision: the dnf path satisfied 7.2 so the fallback never ran, nothing +failed, and nothing said the constant had gone stale. It would have failed only +once the enabled repositories dropped the kernel, which is the one situation +the fallback exists for. +""" +import os +import re +import subprocess +import tempfile +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +SCRIPT = (ROOT / "scripts/install-nvidia.sh").read_text() + + +def constant(name: str) -> str: + match = re.search(rf'^{name}="(?:\$\{{[A-Z0-9_]+:-)?([^"}}]+)\}}?"', SCRIPT, re.MULTILINE) + assert match, f"{name} not found in install-nvidia.sh" + return match.group(1) + + +class KernelDevelPinTests(unittest.TestCase): + def test_the_hash_records_which_kernel_it_belongs_to(self): + nevr = constant("KERNEL_DEVEL_NEVR") + self.assertRegex(nevr, r"^\d+\.\d+\.\d+-\d+\.fc\d+\.\w+$") + self.assertRegex(constant("KERNEL_DEVEL_SHA256"), r"^[0-9a-f]{64}$") + + def test_the_pin_matches_the_kernel_the_base_image_boots(self): + # The one assertion that actually catches the staleness: the recorded + # NEVR has to be the kernel this base carries. Update both together. + self.assertEqual(constant("KERNEL_DEVEL_NEVR"), "7.2.5-200.fc44.x86_64") + + def test_a_mismatched_kernel_fails_before_downloading_60mb(self): + """Drive the real guard: a kernel that is not the recorded one exits 1.""" + guard = re.search( + r'if \[ "\$\{kernel\}" != "\$\{KERNEL_DEVEL_NEVR\}" \]; then.*?\n fi', + SCRIPT, re.DOTALL) + self.assertIsNotNone(guard, "the NEVR guard is not in install-nvidia.sh") + harness = ( + 'KERNEL_DEVEL_NEVR="7.2.5-200.fc44.x86_64"\n' + 'kernel="7.1.8-100.fc43.x86_64"\n' + + guard.group(0).replace("\n ", "\n") + + '\necho "reached the download"\n' + ) + result = subprocess.run(["bash", "-c", harness], capture_output=True, text=True) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertNotIn("reached the download", result.stdout) + self.assertIn("7.1.8-100.fc43.x86_64", result.stderr) + self.assertIn("7.2.5-200.fc44.x86_64", result.stderr) + + def test_the_matching_kernel_passes_the_guard(self): + guard = re.search( + r'if \[ "\$\{kernel\}" != "\$\{KERNEL_DEVEL_NEVR\}" \]; then.*?\n fi', + SCRIPT, re.DOTALL) + harness = ( + 'KERNEL_DEVEL_NEVR="7.2.5-200.fc44.x86_64"\n' + 'kernel="7.2.5-200.fc44.x86_64"\n' + + guard.group(0).replace("\n ", "\n") + + '\necho "reached the download"\n' + ) + result = subprocess.run(["bash", "-c", harness], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("reached the download", result.stdout) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_mirror_shim.py b/tests/test_mirror_shim.py new file mode 100644 index 00000000..4565b849 --- /dev/null +++ b/tests/test_mirror_shim.py @@ -0,0 +1,92 @@ +"""The shim mirroring must say what it could not find. + +Bumping BASE_IMAGE to a kernel-7.2 Hummingbird turned this step into a silent +failure: the build printed "Utah desktop contract passed" and then exited 1, +three attempts in a row, with no indication of which of four chained +predicates had tripped. These tests drive the real script against fake +filesystems, so the diagnostic is a gate rather than a good intention. +""" +import os +import subprocess +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +SCRIPT = ROOT / "scripts/mirror-shim.sh" + + +class MirrorShimTests(unittest.TestCase): + def run_script(self, tmp, *, shim_rc=0, shim_out="16.1-1", stage=True): + """Run the real script with a stub rpm and a fake bootupd tree.""" + bin_dir = Path(tmp) / "bin" + bin_dir.mkdir() + (bin_dir / "rpm").write_text( + f'#!/usr/bin/env bash\nprintf "%s" "{shim_out}"\nexit {shim_rc}\n' + ) + (bin_dir / "rpm").chmod(0o755) + + bootupd = Path(tmp) / "bootupd/updates/EFI/fedora" + if stage: + bootupd.mkdir(parents=True) + (bootupd / "shimx64.efi").write_text("payload") + else: + bootupd.parent.mkdir(parents=True) + + env = dict(os.environ) + env["PATH"] = f"{bin_dir}:{env['PATH']}" + env["BOOTUPD_EFI"] = str(bootupd) + env["SHIM_ROOT"] = str(Path(tmp) / "efi/shim") + return subprocess.run( + ["bash", str(SCRIPT)], capture_output=True, text=True, env=env + ) + + def test_a_staged_payload_is_mirrored_under_the_shim_version(self): + import tempfile + with tempfile.TemporaryDirectory() as tmp: + result = self.run_script(tmp) + self.assertEqual(result.returncode, 0, result.stderr) + mirrored = Path(tmp) / "efi/shim/16.1-1/EFI/fedora/shimx64.efi" + self.assertTrue(mirrored.is_file(), result.stdout + result.stderr) + self.assertEqual(mirrored.read_text(), "payload") + self.assertIn("16.1-1", result.stdout) + + def test_a_missing_shim_package_names_the_package(self): + import tempfile + with tempfile.TemporaryDirectory() as tmp: + result = self.run_script(tmp, shim_rc=1, shim_out="package shim-x64 is not installed") + self.assertEqual(result.returncode, 1) + self.assertIn("shim-x64 is not installed", result.stderr) + # The remedy matters as much as the diagnosis: a base image that + # dropped the package needs it added, not the step skipped. + self.assertIn("package contract", result.stderr) + + def test_an_unstaged_payload_names_the_path_and_lists_the_parent(self): + import tempfile + with tempfile.TemporaryDirectory() as tmp: + result = self.run_script(tmp, stage=False) + self.assertEqual(result.returncode, 1) + self.assertIn("no EFI payload to mirror", result.stderr) + # The two failures must be distinguishable: this one proves the + # package IS installed, which points at bootupd rather than dnf. + self.assertIn("16.1-1 is installed", result.stderr) + + def test_the_two_failures_do_not_share_a_message(self): + import tempfile + with tempfile.TemporaryDirectory() as a, tempfile.TemporaryDirectory() as b: + missing = self.run_script(a, shim_rc=1, shim_out="not installed").stderr + unstaged = self.run_script(b, stage=False).stderr + self.assertNotEqual(missing, unstaged) + + +class ContainerfileWiringTests(unittest.TestCase): + def test_the_containerfile_calls_the_script_and_not_the_old_chain(self): + text = (ROOT / "Containerfile").read_text() + self.assertIn("/usr/local/libexec/utah-mirror-shim", text) + self.assertIn("mirror-shim.sh:utah-mirror-shim", text) + self.assertIn("scripts/mirror-shim.sh \\", text) + # The inline chain is what hid the failure; it must not come back. + self.assertNotIn("rpm -q --qf '%{VERSION}-%{RELEASE}' shim-x64", text) + + +if __name__ == "__main__": + unittest.main() From 7b5204de2969507161d7bce09c70b7c797f828f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 19 Sep 2026 13:16:28 +0000 Subject: [PATCH 3/4] Handle the base image that already mirrors the shim payload itself I did not need to wait for CI for this. Listing both base images layer by layer from the registry answers it outright, and the answer is that the new base has already done the work: old base sha256:c5539f9e... usr/lib/bootupd/updates/EFI/fedora/{shimx64,shim,mmx64,grubx64}.efi no usr/lib/efi/shim at all new base sha256:db1007fd... usr/lib/efi/shim/16.1-5/EFI/fedora/{shimx64,shim,mmx64}.efi, BOOTX64.CSV usr/lib/bootupd/updates/ holds only BIOS.json and EFI.json So the destination Utah was copying into is exactly what the new base now ships, and the source it was copying from no longer exists. The step was not broken by a missing package or a broken transaction; it was asserting a layout the base has moved on from, and failing on a job that was already done. mirror-shim.sh now looks for the payload before doing anything else and exits 0 when it is already in place. It searches for the EFI/fedora/shimx64.efi file rather than assuming a directory name, because the base names that directory for the shim version with no dist tag and rpm need not report the same string. Checking the filesystem first also means the base that ships the payload is the base whose shim-x64 rpm query we no longer depend on. The old layout still works: the copy path is unchanged and tested. The two real failures -- no package and no payload anywhere -- still fail, still say which, and still do not share a message. Tests drive the real script against synthetic filesystems for both layouts, including the case where rpm reports 16.1-5.fc44 while the base directory is 16.1-5. 206 tests, OK. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01W6BYLUD6KBzF8rBFXKjP7M --- scripts/mirror-shim.sh | 55 ++++++++++++----- tests/test_mirror_shim.py | 122 ++++++++++++++++++++++++++------------ 2 files changed, 123 insertions(+), 54 deletions(-) diff --git a/scripts/mirror-shim.sh b/scripts/mirror-shim.sh index 058c1147..28616352 100755 --- a/scripts/mirror-shim.sh +++ b/scripts/mirror-shim.sh @@ -1,37 +1,60 @@ #!/usr/bin/env bash -# Mirror the signed shim payload into bootupd's component layout. +# Make the signed shim payload available in bootupd's component layout, so +# bootc can create a generic disk image without depending on the build host ESP. # -# Fedora's shim package stages its EFI payload under bootupd's update tree, -# while bootupd discovers image-provided EFI components under /usr/lib/efi. -# Mirroring the payload lets bootc create a generic disk image without -# depending on the build host's ESP. +# Two base image layouts exist and both are correct. # -# This was four predicates chained with && at the tail of a long Containerfile -# RUN. When the base image bumped to a kernel-7.2 Hummingbird, the step began -# failing with no output at all: the last line of a successful build was -# "Utah desktop contract passed", then exit 1. Nothing said whether shim-x64 -# was missing, or the bootupd tree was, or the copy failed -- and each has a -# different answer. A build that fails must say what it could not find. +# Old (sha256:c5539f9e...): the payload is staged under bootupd update tree, +# at /usr/lib/bootupd/updates/EFI/fedora/, and /usr/lib/efi/shim does not +# exist. Utah has to do the copy. +# +# New (sha256:db1007fd...): the base already ships +# /usr/lib/efi/shim/16.1-5/EFI/fedora/{shimx64,shim,mmx64}.efi and +# BOOTX64.CSV, and /usr/lib/bootupd/updates/ holds only BIOS.json and +# EFI.json. The mirroring has already been done upstream. +# +# This used to be four predicates chained with && at the tail of a long +# Containerfile RUN, hardcoding the old layout. On the new base it failed with +# no output at all: the last line of a successful build was "Utah desktop +# contract passed", then exit 1, three attempts out of three, with nothing to +# say whether shim-x64 was missing, the tree was missing, or the copy failed. +# +# So: succeed when the payload is already in place, copy when it is staged, and +# fail loudly and specifically when it is neither. A build that fails must say +# what it could not find. set -euo pipefail BOOTUPD_EFI="${BOOTUPD_EFI:-/usr/lib/bootupd/updates/EFI/fedora}" SHIM_ROOT="${SHIM_ROOT:-/usr/lib/efi/shim}" +# Look for an existing payload before asking rpm anything. The base that ships +# it already is the base whose shim-x64 query we least want to depend on, and +# the directory it uses is named for the shim version without a dist tag, which +# need not match what rpm reports. Find the file that matters instead. +existing="$(find "${SHIM_ROOT}" -mindepth 4 -maxdepth 4 \ + -path '*/EFI/fedora/shimx64.efi' -print -quit 2>/dev/null || true)" +if [[ -n "${existing}" ]]; then + echo "Base image already provides the shim payload at ${existing%/shimx64.efi}; nothing to mirror" + exit 0 +fi + fail() { echo "ERROR: shim mirroring: $*" >&2 exit 1 } if ! shim_version="$(rpm -q --qf '%{VERSION}-%{RELEASE}' shim-x64 2>&1)"; then - fail "shim-x64 is not installed in this image (rpm -q said: ${shim_version}). - The signed EFI payload comes from that package, so bootc cannot build a - generic disk image without it. If the base image dropped shim-x64, it has to - be added to the package contract rather than skipped here." + fail "shim-x64 is not installed and no payload is present under ${SHIM_ROOT} + (rpm -q said: ${shim_version}). The signed EFI payload comes from that + package, so bootc cannot build a generic disk image without it. If the base + image dropped shim-x64, it has to be added to the package contract rather + than skipped here." fi if [[ ! -d "${BOOTUPD_EFI}" ]]; then parent="$(dirname "${BOOTUPD_EFI}")" - echo "shim-x64 ${shim_version} is installed but staged nothing at ${BOOTUPD_EFI}." >&2 + echo "shim-x64 ${shim_version} is installed, but nothing is staged at ${BOOTUPD_EFI}" >&2 + echo "and nothing is present under ${SHIM_ROOT} either." >&2 if [[ -d "${parent}" ]]; then echo " ${parent} contains: $(ls -A "${parent}" 2>/dev/null | tr '\n' ' ')" >&2 else diff --git a/tests/test_mirror_shim.py b/tests/test_mirror_shim.py index 4565b849..7d26eed3 100644 --- a/tests/test_mirror_shim.py +++ b/tests/test_mirror_shim.py @@ -1,13 +1,25 @@ -"""The shim mirroring must say what it could not find. +"""The shim mirroring must work on both base layouts, and say what it cannot find. -Bumping BASE_IMAGE to a kernel-7.2 Hummingbird turned this step into a silent -failure: the build printed "Utah desktop contract passed" and then exited 1, -three attempts in a row, with no indication of which of four chained -predicates had tripped. These tests drive the real script against fake -filesystems, so the diagnostic is a gate rather than a good intention. +Two Hummingbird base layouts exist and both are correct. Verified by listing +the layers of each image directly from the registry: + + old base sha256:c5539f9e... + usr/lib/bootupd/updates/EFI/fedora/{shimx64,shim,mmx64,grubx64}.efi + (no usr/lib/efi/shim at all) + + new base sha256:db1007fd... + usr/lib/efi/shim/16.1-5/EFI/fedora/{shimx64,shim,mmx64}.efi + usr/lib/bootupd/updates/ holds only BIOS.json and EFI.json + +The step was four predicates chained with && that hardcoded the old layout, so +the base bump turned it into a silent failure: "Utah desktop contract passed", +then exit 1, three attempts out of three, with nothing said about which of four +things went wrong. These tests drive the real script against fake filesystems +for both layouts and for the two genuine failures. """ import os import subprocess +import tempfile import unittest from pathlib import Path @@ -16,66 +28,100 @@ class MirrorShimTests(unittest.TestCase): - def run_script(self, tmp, *, shim_rc=0, shim_out="16.1-1", stage=True): - """Run the real script with a stub rpm and a fake bootupd tree.""" - bin_dir = Path(tmp) / "bin" + def run_script(self, tmp, *, shim_rc=0, shim_out="16.1-5", + staged=True, preinstalled=None): + """Run the real script with a stub rpm and a synthetic filesystem. + + staged: the old layout -- payload under the bootupd update tree. + preinstalled: the new layout -- a version directory already under + SHIM_ROOT carrying EFI/fedora/shimx64.efi. + """ + tmp = Path(tmp) + bin_dir = tmp / "bin" bin_dir.mkdir() (bin_dir / "rpm").write_text( f'#!/usr/bin/env bash\nprintf "%s" "{shim_out}"\nexit {shim_rc}\n' ) (bin_dir / "rpm").chmod(0o755) - bootupd = Path(tmp) / "bootupd/updates/EFI/fedora" - if stage: + bootupd = tmp / "bootupd/updates/EFI/fedora" + if staged: bootupd.mkdir(parents=True) - (bootupd / "shimx64.efi").write_text("payload") + (bootupd / "shimx64.efi").write_text("staged-payload") else: bootupd.parent.mkdir(parents=True) + shim_root = tmp / "efi/shim" + if preinstalled: + base = shim_root / preinstalled / "EFI/fedora" + base.mkdir(parents=True) + (base / "shimx64.efi").write_text("base-payload") + env = dict(os.environ) env["PATH"] = f"{bin_dir}:{env['PATH']}" env["BOOTUPD_EFI"] = str(bootupd) - env["SHIM_ROOT"] = str(Path(tmp) / "efi/shim") - return subprocess.run( - ["bash", str(SCRIPT)], capture_output=True, text=True, env=env - ) + env["SHIM_ROOT"] = str(shim_root) + return subprocess.run(["bash", str(SCRIPT)], capture_output=True, + text=True, env=env), shim_root - def test_a_staged_payload_is_mirrored_under_the_shim_version(self): - import tempfile + def test_the_old_layout_is_mirrored_under_the_shim_version(self): with tempfile.TemporaryDirectory() as tmp: - result = self.run_script(tmp) + result, shim_root = self.run_script(tmp) self.assertEqual(result.returncode, 0, result.stderr) - mirrored = Path(tmp) / "efi/shim/16.1-1/EFI/fedora/shimx64.efi" + mirrored = shim_root / "16.1-5/EFI/fedora/shimx64.efi" self.assertTrue(mirrored.is_file(), result.stdout + result.stderr) - self.assertEqual(mirrored.read_text(), "payload") - self.assertIn("16.1-1", result.stdout) + self.assertEqual(mirrored.read_text(), "staged-payload") + + def test_a_base_that_already_ships_the_payload_is_a_no_op(self): + """The new base does the mirroring itself; that must not be a failure.""" + with tempfile.TemporaryDirectory() as tmp: + result, shim_root = self.run_script( + tmp, staged=False, preinstalled="16.1-5") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("already provides", result.stdout) + # And it must not have disturbed what the base shipped. + self.assertEqual( + (shim_root / "16.1-5/EFI/fedora/shimx64.efi").read_text(), + "base-payload") + + def test_the_existing_payload_is_found_whatever_rpm_reports(self): + """The base names its directory for the shim version with no dist tag. + + rpm may report something else, so the check must find the file rather + than assume the directory name matches. + """ + with tempfile.TemporaryDirectory() as tmp: + result, _ = self.run_script( + tmp, staged=False, preinstalled="16.1-5", + shim_out="16.1-5.fc44", shim_rc=0) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("already provides", result.stdout) - def test_a_missing_shim_package_names_the_package(self): - import tempfile + def test_a_missing_shim_package_and_no_payload_names_the_package(self): with tempfile.TemporaryDirectory() as tmp: - result = self.run_script(tmp, shim_rc=1, shim_out="package shim-x64 is not installed") + result, _ = self.run_script( + tmp, staged=False, shim_rc=1, + shim_out="package shim-x64 is not installed") self.assertEqual(result.returncode, 1) self.assertIn("shim-x64 is not installed", result.stderr) - # The remedy matters as much as the diagnosis: a base image that - # dropped the package needs it added, not the step skipped. + # The remedy matters as much as the diagnosis. self.assertIn("package contract", result.stderr) - def test_an_unstaged_payload_names_the_path_and_lists_the_parent(self): - import tempfile + def test_an_installed_package_with_no_payload_anywhere_says_so(self): with tempfile.TemporaryDirectory() as tmp: - result = self.run_script(tmp, stage=False) + result, _ = self.run_script(tmp, staged=False) self.assertEqual(result.returncode, 1) self.assertIn("no EFI payload to mirror", result.stderr) - # The two failures must be distinguishable: this one proves the - # package IS installed, which points at bootupd rather than dnf. - self.assertIn("16.1-1 is installed", result.stderr) + # Distinguishable from the missing-package case: this one proves + # the RPM side is fine, so the problem is bootupd, not dnf. + self.assertIn("16.1-5 is installed", result.stderr) def test_the_two_failures_do_not_share_a_message(self): - import tempfile with tempfile.TemporaryDirectory() as a, tempfile.TemporaryDirectory() as b: - missing = self.run_script(a, shim_rc=1, shim_out="not installed").stderr - unstaged = self.run_script(b, stage=False).stderr - self.assertNotEqual(missing, unstaged) + missing, _ = self.run_script(a, staged=False, shim_rc=1, + shim_out="not installed") + absent, _ = self.run_script(b, staged=False) + self.assertNotEqual(missing.stderr, absent.stderr) class ContainerfileWiringTests(unittest.TestCase): @@ -84,7 +130,7 @@ def test_the_containerfile_calls_the_script_and_not_the_old_chain(self): self.assertIn("/usr/local/libexec/utah-mirror-shim", text) self.assertIn("mirror-shim.sh:utah-mirror-shim", text) self.assertIn("scripts/mirror-shim.sh \\", text) - # The inline chain is what hid the failure; it must not come back. + # The inline chain hardcoded the old layout and hid the failure. self.assertNotIn("rpm -q --qf '%{VERSION}-%{RELEASE}' shim-x64", text) From da7bf08254b8ea5272453dcedfd2c931e04730e8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 19 Sep 2026 15:09:45 +0000 Subject: [PATCH 4/4] Make the kernel NEVR overridable, so the hash override is not dead code Review finding, and correct. I added a guard that exits when the booted kernel differs from KERNEL_DEVEL_NEVR, to turn a 60 MB download ending in a checksum mismatch into an immediate failure naming both versions. But UTAH_KERNEL_DEVEL_SHA256 exists for exactly one situation -- validating a kernel this file has not been re-recorded for -- and the guard runs before the hash check, so it blocked precisely the case the override is for. Correct override or not, that path exited 1. I turned an escape hatch into dead code while adding a guard meant to make failures clearer. KERNEL_DEVEL_NEVR now takes UTAH_KERNEL_DEVEL_NEVR the same way the hash takes its override, and the guard message names both variables, so the way past it is to set the pair deliberately rather than to edit the script. Overriding one without the other still fails, which is the intended behaviour: the hash belongs to a specific NEVR and the two only mean anything together. Three tests: both constants accept an override, the guard message names them, and the real guard extracted from the script reaches the download when both are set to a kernel that is not the recorded one. The first fails against the previous constant line. 209 tests pass. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01W6BYLUD6KBzF8rBFXKjP7M --- scripts/install-nvidia.sh | 12 ++++++++-- tests/test_kernel_devel_pin.py | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/scripts/install-nvidia.sh b/scripts/install-nvidia.sh index 5532fe13..24a74cb7 100755 --- a/scripts/install-nvidia.sh +++ b/scripts/install-nvidia.sh @@ -124,7 +124,13 @@ fi # the enabled repositories dropped the kernel -- the precise situation this # fallback exists for. Pairing the two makes that mismatch loud and immediate # instead of latent, and costs nothing when they agree. -KERNEL_DEVEL_NEVR="7.2.5-200.fc44.x86_64" +# +# Both are overridable together, and that pairing is the point. The override on +# the hash exists for exactly one situation -- validating a kernel this file has +# not been re-recorded for -- so a guard that refused to proceed whenever the +# kernel differed from the recorded NEVR would make the override unreachable in +# the only case it is for. Override both, or neither. +KERNEL_DEVEL_NEVR="${UTAH_KERNEL_DEVEL_NEVR:-7.2.5-200.fc44.x86_64}" KERNEL_DEVEL_SHA256="${UTAH_KERNEL_DEVEL_SHA256:-02467ce35055d553db0babd680aa429c2d0b8d514469768730e03b89326a0703}" build_tree="/usr/lib/modules/${kernel}/build" @@ -158,7 +164,9 @@ ensure_toolchain() { echo "KERNEL_DEVEL_SHA256 was recorded for kernel ${KERNEL_DEVEL_NEVR}," >&2 echo "but this image boots ${kernel}. The hash cannot match, so the" >&2 echo "download below would fail after fetching 60 MB. Re-record both" >&2 - echo "constants for ${kernel} when bumping BASE_IMAGE." >&2 + echo "constants for ${kernel} when bumping BASE_IMAGE, or set both" >&2 + echo "UTAH_KERNEL_DEVEL_NEVR and UTAH_KERNEL_DEVEL_SHA256 to validate" >&2 + echo "a kernel this file has not been re-recorded for." >&2 exit 1 fi arch="${kernel##*.}"; nv="${kernel%.*}"; ver="${nv%%-*}"; rel="${nv#*-}" diff --git a/tests/test_kernel_devel_pin.py b/tests/test_kernel_devel_pin.py index 6c7ad299..d224c39b 100644 --- a/tests/test_kernel_devel_pin.py +++ b/tests/test_kernel_devel_pin.py @@ -69,6 +69,49 @@ def test_the_matching_kernel_passes_the_guard(self): self.assertEqual(result.returncode, 0, result.stderr) self.assertIn("reached the download", result.stdout) + def test_both_constants_are_overridable_together(self): + """The guard must not make the hash override unreachable. + + UTAH_KERNEL_DEVEL_SHA256 exists for one situation: validating a kernel + this file has not been re-recorded for. A NEVR guard that refused to + proceed whenever the booted kernel differed from the recorded one would + block exactly that case, leaving the override as dead code. So the NEVR + has to be overridable too, and the pair has to move together. + """ + for name in ("KERNEL_DEVEL_NEVR", "KERNEL_DEVEL_SHA256"): + with self.subTest(constant=name): + line = next(l for l in SCRIPT.splitlines() + if l.startswith(f"{name}=")) + self.assertIn(f"${{UTAH_{name}:-", line, + f"{name} must accept an environment override") + + def test_the_guard_message_names_the_override(self): + # A guard that stops the build has to say how to proceed deliberately, + # or the only way past it is to edit the script. + guard = re.search( + r'if \[ "\$\{kernel\}" != "\$\{KERNEL_DEVEL_NEVR\}" \]; then.*?\n fi', + SCRIPT, re.DOTALL).group(0) + self.assertIn("UTAH_KERNEL_DEVEL_NEVR", guard) + self.assertIn("UTAH_KERNEL_DEVEL_SHA256", guard) + + def test_an_overridden_pair_reaches_the_download(self): + """Drive the real guard with both overrides set to a different kernel.""" + guard = re.search( + r'if \[ "\$\{kernel\}" != "\$\{KERNEL_DEVEL_NEVR\}" \]; then.*?\n fi', + SCRIPT, re.DOTALL).group(0) + harness = ( + 'KERNEL_DEVEL_NEVR="${UTAH_KERNEL_DEVEL_NEVR:-7.2.5-200.fc44.x86_64}"\n' + 'kernel="9.9.9-1.fc99.x86_64"\n' + + guard.replace("\n ", "\n") + + '\necho "reached the download"\n' + ) + import os + env = dict(os.environ, UTAH_KERNEL_DEVEL_NEVR="9.9.9-1.fc99.x86_64") + result = subprocess.run(["bash", "-c", harness], capture_output=True, + text=True, env=env) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("reached the download", result.stdout) + if __name__ == "__main__": unittest.main()