From 767be81986fb47e5b1a181c510e841faf93ebb55 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 16:00:16 +0100 Subject: [PATCH] Verify release archives against their source recipes --- PROFILES.md | 10 +++ tools/release-archives.py | 128 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 tools/release-archives.py diff --git a/PROFILES.md b/PROFILES.md index b6096ce..b961e92 100644 --- a/PROFILES.md +++ b/PROFILES.md @@ -20,6 +20,16 @@ The next source plan selects GCC 14.2.0-2 and Make 4.4.1-4 for both targets. Its The archive scan of `order-05` verified 138 of the 158 planned x86_64 versions and 122 of the 158 AArch64 versions against the build-worker receipts. Its tables record each planned recipe, archive checksum and outstanding prerequisite in dependency order. See `release-inputs/upstream-7f173671/archive-availability-02`, receipt SHA-256 `2a28bea92b9b979a3f022dd20d9bbea71f90f9684c391bc2c8f4e639cb460f58`. Clean installs and guest acceptance for the complete release roots remain pending. +For `order-06`, `tools/release-archives.py` checks each receipt, the archive's package metadata and the SHA-256 of the planned `PKGBUILD.vile`. It matched 118 x86_64 and 124 AArch64 archives to the exact planned recipes. It flagged 21 x86_64 and three AArch64 packages whose archives named a different recipe hash, 19 and 30 packages with missing receipts, and two AArch64 libxml2 archives with different digests for the same version and recipe. The worker matched 23 of the 24 recipe differences to retained source and recorded the exact paths so the existing builds can be reviewed for reuse. See `release-inputs/upstream-7f173671/archive-provenance-01` and `recipe-reuse-candidates-01`, receipt SHA-256 `82a810cc9f33b2ae2454cb25ddaadd4344e7369bd84fafb188e06cfbc62d0664` and `a870d24b2b331d274366280e794dcbdabdabed33e4a51511b023644c1968ea6f`. + +Run the audit on the worker with the exact source snapshot and the saved receipt pools. The output includes each rejected candidate and the packages waiting on it. The worker tested the successful Make archive, changed recipe bytes and a wrong archive checksum. See `archive-provenance-controls-02`, receipt SHA-256 `ab654bd7de369594a78f6e5cae0ac49dea1a9c248ec92824f4a7699a5015ccad`. + +```sh +python3 tools/release-archives.py "$arch" "$state/order-06/$arch/order.tsv" \ + "$state/source-06" "$report" "$archive_receipts" "$signed_repo/packages.tsv" \ + --extra-recipe "$trusted_keyring_recipe" +``` + Both btop 1.4.0-1 archives were built against the signed Vinix musl and GNU C++ runtime and checked for their target ELF layout. Each published Vinix kernel booted an eight-package signed root, ran btop's version and help commands, and found the installed theme and manual. See `release-inputs/upstream-7f173671/btop-build-01` and `btop-guests-05`, receipt SHA-256 `888b9bec6a542a464a7f22c5689e894188b1fb1bd22ef8704b91b4bf00aa77a9` and `7c67d8d52bd24eee7c800076b3f3a4407e6c4dc7215fdaa91583873ba906cdcc`. The upstream AArch64 init and watchdog were also built from source and passed static linkage and 16 KiB load-segment checks. See `init-arm16-01`, receipt SHA-256 `20ae3a3806e753b35483f30cb9444f2b9c5aaf11d1e0f00f01b9a0660b4a784d`. The new AArch64 init also booted a 15-package signed root on the November 28 kernel. The guest verified the watchdog's checksum and observed its process alongside the native graphical session and first-boot registration screen. The fixture used the five native desktop and service binaries from the checksum-pinned published image. See `release-inputs/upstream-7f173671/desktop-arm16-guest-03`, receipt SHA-256 `ae707d9f87deaa8f6d9492c0039d2c94b9867de821b50b5cc7b709b14d310cdf`. diff --git a/tools/release-archives.py b/tools/release-archives.py new file mode 100644 index 0000000..11b83e4 --- /dev/null +++ b/tools/release-archives.py @@ -0,0 +1,128 @@ +"""Match a Vinix source plan to receipted native package archives.""" + +import argparse +from collections import Counter, defaultdict +import csv +import hashlib +from pathlib import Path +import re +import subprocess + + +def digest(path): + with path.open("rb") as stream: + return hashlib.file_digest(stream, "sha256").hexdigest() + + +def records(path): + with path.open() as stream: + return list(csv.DictReader(stream, delimiter="\t")) + + +def archives(pool, arch): + if pool.suffix == ".tsv": + for row in records(pool): + filename = row["archive"] + if row["arch"] in (arch, "any") and Path(filename).name == filename: + yield pool.parent / arch / filename, row["sha256"] + return + for receipt in sorted(pool.glob("*.sha256")) if pool.is_dir() else [pool]: + for line in receipt.read_text().splitlines(): + fields = line.split(maxsplit=1) + if len(fields) != 2 or not re.fullmatch("[a-f0-9]{64}", fields[0]): + continue + checksum, filename = fields + filename = filename.lstrip("*") + if filename.endswith(".pkg.tar.zst") and Path(filename).name == filename: + yield receipt.parent / filename, checksum + + +def package_field(archive, metadata): + body = subprocess.check_output(["bsdtar", "-xOf", archive, metadata], + stderr=subprocess.DEVNULL, text=True) + return dict(line.split(" = ", 1) for line in body.splitlines() if " = " in line) + + +def verify(archive, checksum, name, version, arch, recipe_hash): + if not archive.is_file(): + return "archive-missing" + try: + if digest(archive) != checksum: + return "checksum-mismatch" + pkg = package_field(archive, ".PKGINFO") + if (pkg.get("pkgname") != name or pkg.get("pkgver") != version + or pkg.get("arch") not in (arch, "any") + or archive.name != f"{name}-{version}-{pkg['arch']}.pkg.tar.zst"): + return "package-metadata-mismatch" + info = package_field(archive, ".BUILDINFO") + except (OSError, subprocess.CalledProcessError, UnicodeError): + return "unreadable-archive" + if info.get("pkgbuild_sha256sum") != recipe_hash: + return "recipe-mismatch" + return "verified" + + +def report(args): + packages = records(args.order) + variants = (args.arch, "any") + paths = defaultdict(set) + for pool in args.pools: + for archive, checksum in archives(pool, args.arch): + paths[archive.name].add((archive, checksum)) + override = {path.parent.name: path for path in args.extra_recipe} + args.output.mkdir() + results = {} + with (args.output / "candidates.tsv").open("x") as stream: + writer = csv.writer(stream, delimiter="\t", lineterminator="\n") + writer.writerow(["package", "archive", "sha256", "result"]) + for row in packages: + name, version = row["package"], row["version"] + source = row["source_recipe"] + recipe = override.get(source, args.recipes / source / "PKGBUILD.vile") + if not recipe.is_file(): + results[name] = "missing-recipe", "", "", "" + continue + recipe_hash = digest(recipe) + valid = {} + rejected = set() + for machine in variants: + for archive, checksum in sorted(paths[f"{name}-{version}-{machine}.pkg.tar.zst"]): + result = verify(archive, checksum, name, version, args.arch, recipe_hash) + writer.writerow([name, archive, checksum, result]) + if result == "verified": + valid.setdefault(checksum, archive) + else: + rejected.add(result) + if len(valid) == 1: + checksum, archive = next(iter(valid.items())) + results[name] = "verified", str(archive), checksum, recipe_hash + elif valid: + results[name] = "archive-conflict", "", "", recipe_hash + else: + status = ",".join(sorted(rejected)) if rejected else "missing-receipt" + results[name] = status, "", "", recipe_hash + with (args.output / "coverage.tsv").open("x") as stream: + writer = csv.writer(stream, delimiter="\t", lineterminator="\n") + writer.writerow(["stage", "package", "version", "source_recipe", "status", "archive", + "archive_sha256", "recipe_sha256", "prerequisites_without_verified_archive"]) + for row in packages: + name = row["package"] + pending = [dep for dep in filter(None, row["depends_on"].split(",")) + if results[dep][0] != "verified"] + writer.writerow([row["stage"], name, row["version"], row["source_recipe"], + *results[name], ",".join(pending)]) + counts = Counter(result[0] for result in results.values()) + print(args.arch, *[f"{state}={count}" for state, count in sorted(counts.items())]) + return int(not packages or counts["verified"] != len(packages)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("arch", choices=("aarch64", "x86_64")) + parser.add_argument("order", type=Path, help="architecture-specific order.tsv") + parser.add_argument("recipes", type=Path, help="exact source snapshot used for the plan") + parser.add_argument("output", type=Path, help="new directory for the coverage reports") + parser.add_argument("pools", type=Path, nargs="+", + help="archive receipt directories, individual receipts, or feed packages.tsv files") + parser.add_argument("--extra-recipe", action="append", type=Path, default=[]) + raise SystemExit(report(parser.parse_args())) -- 2.56.1