From 18a90ba9e356116fbb222898ba48422b083aa2c4 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 15:03:39 +0100 Subject: [PATCH] Verify signed upgrades through the Vinix pkg command --- tests/FEED.md | 2 ++ tests/userland/vpac.sh | 25 ++++++++++++++++++++++--- tests/vpac-guest.py | 33 ++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/tests/FEED.md b/tests/FEED.md index b7f52bb..70703ec 100644 --- a/tests/FEED.md +++ b/tests/FEED.md @@ -159,4 +159,6 @@ Run the target vpac binary on the release kernel with `python3 tests/vpac-guest. For the public `pkg` command, install `vinix-pkg`, `busybox-init`, `vinix-keyring`, `vinix-accounts` and `vinix-filesystem` from a signed feed that also contains `netbase`. Stage the installed root under `umask 077` and boot it using `python3 tests/disk-root.py "$arch" "$image/root" tests/userland/pkg.sh "$iso" "$boot" "$output"`. The x86_64 guest refreshed the signed seed index, looked up an exact name and an unmatched prefix, installed `netbase` with signature validation, checked file ownership, and removed the package. The worker verified 41 signed installed records and a 43-package seed. The directory and index modes allow the unprivileged downloader to read the seed and reach its sync work directory. The GnuPG home has mode 0700. See `foundation/vinix-pkg-guest-02`, receipt SHA-256 `695cd4c4b62a2554363b733683985ea7d655bc848e24ecec7368a944eb551c47`. +Run `vpac-guest.py` with `--scenario upgrade --package-command pkg` to exercise the public upgrade path. The initial feed needs `vinix-pkg`. Pass `--staged-root "$image/root"` to reuse a clean staged image from the same signed feed on the build volume. The x86_64 replay upgraded the CA bundle to `20261020-3` and checked the signature validation record, the new certificate link and its owner. The original staged root retained release 2. The runner rejected a staged root with a different signed database before creating a guest image. See `foundation/vinix-pkg-upgrade-01` and `foundation/vinix-pkg-upgrade-mismatched-root-01`, receipt SHA-256 `efa7b96701b2f2aeb7afd3ac8398adb3859b818d1dbf90efc1856e44f9059038` and `b670332301bc1005b8dff21a1a6e4342147015a9e6723da2e0b09ddd35f3fe7b`. + To exercise the original release binaries against the installed libraries on a worker of the same architecture, run `python3 tests/exec-linkage.py "$arch" "$client" "$auditor" --proot "$proot" --release "$archive" "$sha256" "$report"`. The probe binds one original executable over its guest path and runs the installed musl loader with `--list`. A negative control changed a library import in the original input and verified that the installed loader diagnosed the changed SONAME. In the 129-package x86_64 root, 52 of 95 dynamic image executables relocated, 27 reported failures and 16 fixed-address executables needed direct execution. Twelve of 17 X11 sidecar executables relocated. See `foundation/release-binary-relocation-02`, receipt SHA-256 `8483666ef4294f1ac5d44c1eb637a8f5200be4e613e635d835ef4f86e7ffa37b`. Directly starting the release `cpp` and `cc1` in that root expanded `__SIZEOF_POINTER__` to 8. See `foundation/release-original-exec-02`, receipt SHA-256 `b9f1659e4669df9f3d4aeddea37fd9b85abc40f9d55045fff1fc7096f091a209`. diff --git a/tests/userland/vpac.sh b/tests/userland/vpac.sh index e185630..e1a7a6b 100644 --- a/tests/userland/vpac.sh +++ b/tests/userland/vpac.sh @@ -15,6 +15,21 @@ vpac q -F name,validation local/musl >/tmp/musl grep -Eq '^validation[[:space:]]+signature$' /tmp/musl vpac o /bin/busybox | grep -q busybox arch=$(uname -m) +package_command=${VPAC_TEST_PACKAGE_COMMAND:-vpac} +case "$package_command" in + vpac) ;; + pkg) vpac o /usr/bin/pkg | grep -q vinix-pkg ;; + *) echo "unknown test package command $package_command" >&2; exit 2 ;; +esac + +install_netbase() { + if [ "$package_command" = pkg ]; then + pkg install netbase + else + vpac i --noconfirm netbase + fi +} + install_test() { test ! -e /etc/services set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst @@ -28,7 +43,7 @@ install_test() { test "$(wc -c <"$archive")" = "$(wc -c /tmp/reject.log 2>&1 || status=$? + install_netbase >/tmp/reject.log 2>&1 || status=$? cat /tmp/reject.log test "$status" -ne 0 grep -Fiq 'invalid or corrupted package (PGP signature)' /tmp/reject.log @@ -37,7 +52,7 @@ install_test() { mv /tmp/netbase-original "$archive" phase=install - vpac i --noconfirm netbase + install_netbase echo 'VPAC transaction installed authentic netbase' phase=installed-ownership vpac o /etc/services | grep -q netbase @@ -78,7 +93,11 @@ test ! -e /etc/ssl1.1/cert.pem vpac q -F version local/ca-certificates-bundle >/tmp/bundle grep -Eq '^version[[:space:]]+20261020-2$' /tmp/bundle cp "$reference/"* "/var/lib/vinix/repository/$arch/" -vpac u --sync --noconfirm +if [ "$package_command" = pkg ]; then + pkg upgrade +else + vpac u --sync --noconfirm +fi phase=upgraded-record vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded diff --git a/tests/vpac-guest.py b/tests/vpac-guest.py index ccba632..459d066 100644 --- a/tests/vpac-guest.py +++ b/tests/vpac-guest.py @@ -1,5 +1,6 @@ """Boot a staged vpac image and test rejection, install and upgrade using the guest binary.""" import argparse +from filecmp import cmp import hashlib import os import shutil @@ -10,6 +11,8 @@ from pathlib import Path def run(args): work = args.work + if args.staged_root and work.is_relative_to(args.staged_root): + raise ValueError("put test output outside the staged root") work.mkdir() arch = args.arch tests = Path(__file__).resolve().parent @@ -18,20 +21,30 @@ def run(args): repo = args.repo client = work / "client" image = work / "image" + root = image / "root" def log(name, argv, **options): with (work / (name + ".log")).open("x") as output: subprocess.run(argv, stdout=output, stderr=subprocess.STDOUT, check=True, **options) log("trust", ["feed", "trust", trust, repo / "test-signer.asc", pin]) - log("install", ["feed", "install", trust, repo, arch, client, "--fakeroot", - "vpac", "busybox-init", "vinix-keyring", "vinix-accounts", "vinix-filesystem"]) - log("stage", [sys.executable, tests.parent / "tools/stage-image.py", arch, client, repo, - image, args.auditor, pin]) + if args.staged_root: + seed = args.staged_root / "var/lib/vinix/repository" / arch + for file in ("vinix.db", "vinix.db.sig"): + if not cmp(seed / file, repo / arch / file, shallow=False): + raise ValueError(f"staged root has a different seed {file}") + log("staged-input", ["sha256sum", seed / "vinix.db", seed / "vinix.db.sig"]) + # The disk runner copies this tree before the guest writes to it. + shutil.copytree(args.staged_root, root, symlinks=True, copy_function=os.link) + else: + package = "vinix-pkg" if args.package_command == "pkg" else "vpac" + log("install", ["feed", "install", trust, repo, arch, client, "--fakeroot", + package, "busybox-init", "vinix-keyring", "vinix-accounts", "vinix-filesystem"]) + log("stage", [sys.executable, tests.parent / "tools/stage-image.py", arch, client, repo, + image, args.auditor, pin]) # The updater receives a second complete signed index. Only its changed files # have to be added to the guest image alongside the first verified snapshot. - root = image / "root" initial = root / "var/lib/vinix/repository" / arch old = initial / "ca-certificates-bundle-20261020-2-any.pkg.tar.zst" if not old.is_file() or not list(initial.glob("netbase-*.pkg.tar.zst")): @@ -48,12 +61,15 @@ def run(args): log("publish-update", ["feed", "publish", args.keys, update, arch, new, *siblings]) delta = root / "var/lib/vinix/test-update" delta.mkdir() + delta.chmod(0o755) for base in ("vinix.db", "vinix.files", new.name): for name in (base, base + ".sig"): - shutil.copyfile(update / arch / name, delta / name) + target = delta / name + shutil.copyfile(update / arch / name, target) + target.chmod(0o644) fixture = work / "fixture.sh" - fixture.write_bytes(f"VPAC_TEST_SCENARIO={args.scenario}\n".encode() + fixture.write_bytes(f"VPAC_TEST_SCENARIO={args.scenario}\nVPAC_TEST_PACKAGE_COMMAND={args.package_command}\n".encode() + (tests / "userland/vpac.sh").read_bytes()) disk = work / "disk" env = os.environ.copy() @@ -71,6 +87,9 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("arch", choices=("x86_64", "aarch64")) parser.add_argument("--scenario", choices=("all", "install", "upgrade"), default="all") + parser.add_argument("--package-command", choices=("vpac", "pkg"), default="vpac") + parser.add_argument("--staged-root", type=lambda path: Path(path).resolve(), + help="reuse a staged root from the same feed and build volume") for option in ("repo", "keys", "fingerprint", "update_receipt", "auditor", "boot", "iso", "work"): parser.add_argument(option, type=lambda path: Path(path).resolve()) run(parser.parse_args()) -- 2.56.1