From f858dbd788f056d13c39f0611ff93d9d2751b78f Mon Sep 17 00:00:00 2001 From: "sec-check[bot]" Date: Sat, 12 Sep 2026 16:05:59 -0400 Subject: [PATCH] [architect] refactor: single-source install-repo identity in packages/*.repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit check-repo-availability.py restated the install-source set as its own hardcoded REPOS dict, and the copy had already drifted: it keyed Hummingbird as 'public-hummingbird' while the real repo ID is 'public-hummingbird-x86_64-rpms'. The checker now parses packages/*.repo, selects sections marked '# utah-install: true', and follows a '# ci-mirror:' annotation for the factory repo whose in-image baseurl is file:///etc/utah-packages. nvidia-container-toolkit stays excluded — it is enabled on the image but consumed only by utah-install-nvidia. Refs #73 — the install-packages.py REPOS half is deliberately left open: its textual guard lives in the Justfile, occupied by open hold-gated #44, and the script's Containerfile region is occupied by #56. Signed-off-by: sec-check[bot] --- packages/hummingbird.repo | 1 + packages/utah-packages.repo | 2 + scripts/check-repo-availability.py | 64 ++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/packages/hummingbird.repo b/packages/hummingbird.repo index 8d930675..df6cf48e 100644 --- a/packages/hummingbird.repo +++ b/packages/hummingbird.repo @@ -2,6 +2,7 @@ # and it takes precedence over Fedora via priority, which is how Hummingbird # composes its own buildroot (mock/mock.cfg in redhat/hummingbird/containers). [public-hummingbird-x86_64-rpms] +# utah-install: true name=public-hummingbird-x86_64-rpms baseurl=https://packages.redhat.com/api/pulp-content/public-hummingbird/x86_64/ enabled=1 diff --git a/packages/utah-packages.repo b/packages/utah-packages.repo index 793d0169..4496fe36 100644 --- a/packages/utah-packages.repo +++ b/packages/utah-packages.repo @@ -2,6 +2,8 @@ # RPMs are authenticated by the pinned package image and its OCI provenance; # the repository itself does not carry an RPM GPG key. [utah-packages] +# utah-install: true +# ci-mirror: https://projectbluefin.github.io/utah-packages/ name=Utah package factory baseurl=file:///etc/utah-packages enabled=1 diff --git a/scripts/check-repo-availability.py b/scripts/check-repo-availability.py index fb1b05e0..b630e9cc 100644 --- a/scripts/check-repo-availability.py +++ b/scripts/check-repo-availability.py @@ -23,13 +23,58 @@ import xml.etree.ElementTree as ET from pathlib import Path -# The same repositories the image installs from, in the same precedence order: -# Hummingbird's own overlay plus the utah-packages factory (its Pages mirror, -# since check-repos runs in CI before the OCI repo is copied into the image). -REPOS = { - "public-hummingbird": "https://packages.redhat.com/api/pulp-content/public-hummingbird/x86_64/", - "utah-packages": "https://projectbluefin.github.io/utah-packages/", -} +def install_repos(repo_dir: Path) -> dict[str, str]: + """The repositories the image's package transaction installs from. + + Derived from packages/*.repo — the same files the build copies into + /etc/yum.repos.d — so a renamed or moved repository changes what this + check queries instead of leaving it validating a stale hardcoded copy. + A repo belongs to the install transaction when its section carries a + `# utah-install: true` marker; nvidia-container-toolkit is enabled on the + image but is consumed only by utah-install-nvidia, so it is unmarked. + + A repo whose baseurl is a file:// path exists only inside the image (the + factory repository is copied in from a pinned OCI image). CI cannot query + that path, so such a section must also carry `# ci-mirror: ` naming + the published mirror to check instead. + """ + repos: dict[str, str] = {} + for repo_file in sorted(repo_dir.glob("*.repo")): + section_name = None + baseurl = mirror = marked = None + for line in repo_file.read_text().splitlines(): + line = line.strip() + if line.startswith("[") and line.endswith("]"): + if section_name and marked: + repos[section_name] = _resolve(section_name, baseurl, mirror, repo_file) + section_name = line[1:-1] + baseurl = mirror = marked = None + elif line.startswith("#"): + comment = line.lstrip("# ") + if comment == "utah-install: true": + marked = True + elif comment.startswith("ci-mirror:"): + mirror = comment.split(":", 1)[1].strip() + elif line.startswith("baseurl="): + baseurl = line.split("=", 1)[1].strip() + if section_name and marked: + repos[section_name] = _resolve(section_name, baseurl, mirror, repo_file) + if not repos: + raise SystemExit(f"no repositories marked '# utah-install: true' under {repo_dir}") + return repos + + +def _resolve(section_name: str, baseurl: str | None, mirror: str | None, repo_file: Path) -> str: + if not baseurl: + raise SystemExit(f"{repo_file}: [{section_name}] is marked utah-install but has no baseurl") + if baseurl.startswith("file://"): + if not mirror: + raise SystemExit( + f"{repo_file}: [{section_name}] has an in-image file:// baseurl; " + "add a '# ci-mirror: ' annotation naming the mirror CI should query" + ) + return mirror + return baseurl def section(path: Path, name: str) -> list[str]: @@ -90,8 +135,11 @@ def main() -> int: | set(section(overlay, "gnome")) | set(section(overlay, "build")) ) + # The manifests live in packages/ beside the .repo files, so the manifest + # path locates the repository definitions — no second hardcoded path. + repos = install_repos(args.manifest.parent) names: set[str] = set() - for label, base in REPOS.items(): + for label, base in repos.items(): found = repo_package_names(base) print(f"{label}: {len(found)} binary packages") names |= found