me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Verify release archives against their source recipes

diviocity committed 5 days ago · 767be81986fb47e5b1a181c510e841faf93ebb55 View patch
Unverified signature 2 files changed +138 -0
PROFILES.md +10 -0

@@ -20,6 +20,16 @@ The next source plan selects GCC 14.2.0-2 and Make 4.4.1-4 for both targets. Its

2020

2121The 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.

2222

23+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`.

24+

25+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`.

26+

27+```sh

28+python3 tools/release-archives.py "$arch" "$state/order-06/$arch/order.tsv" \

29+ "$state/source-06" "$report" "$archive_receipts" "$signed_repo/packages.tsv" \

30+ --extra-recipe "$trusted_keyring_recipe"

31+```

32+

2333Both 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`.

2434

2535The 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`.

tools/release-archives.py new file +128 -0

@@ -0,0 +1,128 @@

1+"""Match a Vinix source plan to receipted native package archives."""

2+

3+import argparse

4+from collections import Counter, defaultdict

5+import csv

6+import hashlib

7+from pathlib import Path

8+import re

9+import subprocess

10+

11+

12+def digest(path):

13+ with path.open("rb") as stream:

14+ return hashlib.file_digest(stream, "sha256").hexdigest()

15+

16+

17+def records(path):

18+ with path.open() as stream:

19+ return list(csv.DictReader(stream, delimiter="\t"))

20+

21+

22+def archives(pool, arch):

23+ if pool.suffix == ".tsv":

24+ for row in records(pool):

25+ filename = row["archive"]

26+ if row["arch"] in (arch, "any") and Path(filename).name == filename:

27+ yield pool.parent / arch / filename, row["sha256"]

28+ return

29+ for receipt in sorted(pool.glob("*.sha256")) if pool.is_dir() else [pool]:

30+ for line in receipt.read_text().splitlines():

31+ fields = line.split(maxsplit=1)

32+ if len(fields) != 2 or not re.fullmatch("[a-f0-9]{64}", fields[0]):

33+ continue

34+ checksum, filename = fields

35+ filename = filename.lstrip("*")

36+ if filename.endswith(".pkg.tar.zst") and Path(filename).name == filename:

37+ yield receipt.parent / filename, checksum

38+

39+

40+def package_field(archive, metadata):

41+ body = subprocess.check_output(["bsdtar", "-xOf", archive, metadata],

42+ stderr=subprocess.DEVNULL, text=True)

43+ return dict(line.split(" = ", 1) for line in body.splitlines() if " = " in line)

44+

45+

46+def verify(archive, checksum, name, version, arch, recipe_hash):

47+ if not archive.is_file():

48+ return "archive-missing"

49+ try:

50+ if digest(archive) != checksum:

51+ return "checksum-mismatch"

52+ pkg = package_field(archive, ".PKGINFO")

53+ if (pkg.get("pkgname") != name or pkg.get("pkgver") != version

54+ or pkg.get("arch") not in (arch, "any")

55+ or archive.name != f"{name}-{version}-{pkg['arch']}.pkg.tar.zst"):

56+ return "package-metadata-mismatch"

57+ info = package_field(archive, ".BUILDINFO")

58+ except (OSError, subprocess.CalledProcessError, UnicodeError):

59+ return "unreadable-archive"

60+ if info.get("pkgbuild_sha256sum") != recipe_hash:

61+ return "recipe-mismatch"

62+ return "verified"

63+

64+

65+def report(args):

66+ packages = records(args.order)

67+ variants = (args.arch, "any")

68+ paths = defaultdict(set)

69+ for pool in args.pools:

70+ for archive, checksum in archives(pool, args.arch):

71+ paths[archive.name].add((archive, checksum))

72+ override = {path.parent.name: path for path in args.extra_recipe}

73+ args.output.mkdir()

74+ results = {}

75+ with (args.output / "candidates.tsv").open("x") as stream:

76+ writer = csv.writer(stream, delimiter="\t", lineterminator="\n")

77+ writer.writerow(["package", "archive", "sha256", "result"])

78+ for row in packages:

79+ name, version = row["package"], row["version"]

80+ source = row["source_recipe"]

81+ recipe = override.get(source, args.recipes / source / "PKGBUILD.vile")

82+ if not recipe.is_file():

83+ results[name] = "missing-recipe", "", "", ""

84+ continue

85+ recipe_hash = digest(recipe)

86+ valid = {}

87+ rejected = set()

88+ for machine in variants:

89+ for archive, checksum in sorted(paths[f"{name}-{version}-{machine}.pkg.tar.zst"]):

90+ result = verify(archive, checksum, name, version, args.arch, recipe_hash)

91+ writer.writerow([name, archive, checksum, result])

92+ if result == "verified":

93+ valid.setdefault(checksum, archive)

94+ else:

95+ rejected.add(result)

96+ if len(valid) == 1:

97+ checksum, archive = next(iter(valid.items()))

98+ results[name] = "verified", str(archive), checksum, recipe_hash

99+ elif valid:

100+ results[name] = "archive-conflict", "", "", recipe_hash

101+ else:

102+ status = ",".join(sorted(rejected)) if rejected else "missing-receipt"

103+ results[name] = status, "", "", recipe_hash

104+ with (args.output / "coverage.tsv").open("x") as stream:

105+ writer = csv.writer(stream, delimiter="\t", lineterminator="\n")

106+ writer.writerow(["stage", "package", "version", "source_recipe", "status", "archive",

107+ "archive_sha256", "recipe_sha256", "prerequisites_without_verified_archive"])

108+ for row in packages:

109+ name = row["package"]

110+ pending = [dep for dep in filter(None, row["depends_on"].split(","))

111+ if results[dep][0] != "verified"]

112+ writer.writerow([row["stage"], name, row["version"], row["source_recipe"],

113+ *results[name], ",".join(pending)])

114+ counts = Counter(result[0] for result in results.values())

115+ print(args.arch, *[f"{state}={count}" for state, count in sorted(counts.items())])

116+ return int(not packages or counts["verified"] != len(packages))

117+

118+

119+if __name__ == "__main__":

120+ parser = argparse.ArgumentParser(description=__doc__)

121+ parser.add_argument("arch", choices=("aarch64", "x86_64"))

122+ parser.add_argument("order", type=Path, help="architecture-specific order.tsv")

123+ parser.add_argument("recipes", type=Path, help="exact source snapshot used for the plan")

124+ parser.add_argument("output", type=Path, help="new directory for the coverage reports")

125+ parser.add_argument("pools", type=Path, nargs="+",

126+ help="archive receipt directories, individual receipts, or feed packages.tsv files")

127+ parser.add_argument("--extra-recipe", action="append", type=Path, default=[])

128+ raise SystemExit(report(parser.parse_args()))