From f98dcf28a458c2e1c6e7a36657c62fe25a86cd41 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 14:12:14 +0100 Subject: [PATCH] Verify signed vpac installs and upgrades in Vinix guests --- BOOTSTRAP.md | 2 +- tests/FEED.md | 2 + tests/busybox/boot.v | 9 ++++- tests/userland/vpac.sh | 91 ++++++++++++++++++++++++++++++++++++++++++ tests/vpac-guest.py | 76 +++++++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 tests/userland/vpac.sh create mode 100644 tests/vpac-guest.py diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 9eab10b..800fbc7 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -80,7 +80,7 @@ The published x86_64 Vinix kernel booted that 22-package root. Both `gpgv` and t The x86_64 vpac recipe uses V at `597b0f6`, targets musl explicitly, and embeds the Vile resources. Its configuration check temporarily removes both input Scheme files and queries an installed signed musl record. The recipe uses the locked `nobody` account from `vinix-accounts` and keeps package and database signature checks enabled. The build peaked at 2,281,107,456 bytes with zero cgroup OOM events. The resulting `vpac-1.0.0-1-x86_64.pkg.tar.zst` has SHA-256 `f6aa20508a8bc62b5da8b5134657f8d12b1ff5c1609a87e2d7eae02759ea7786`. The worker recorded the pinned source trees in `foundation/vpac-vcs-pins-01`, receipt SHA-256 `2124cc24c72459f7274eb4a74c0d1fa4ec30896a35183e31e6786e9060666014`. -Release 2 handles the Vinix kernel's `ENOSYS` response to the Landlock ABI query. Downloads retain the locked account, no-new-privs and seccomp, and the transaction still verifies the signed package. The x86_64 guest refused a same-length modification of the signed netbase archive, installed the authentic archive, and verified its local owner and signature. A separate boot queried the signed repository record by exact name. See `foundation/vpac-transaction-08/disk/guest/serial.log` and `foundation/vpac-remote-query-01/disk/receipts.sha256`, receipt SHA-256 `0d0569ad76f9828fadac877bf1f67ae505eceab3231546b30a13423826f48891`. The combined test still times out during repository lookup after installation. The upgrade fixture reaches package verification and extraction and still needs to pass its post-upgrade checks. +Release 2 handles the Vinix kernel's `ENOSYS` response to the Landlock ABI query. Downloads retain the locked account, no-new-privs and seccomp, and the transaction still verifies the signed package. The x86_64 install scenario refused a same-length modification of the signed netbase archive, installed the authentic archive, and verified its owner, signature and repository lookup. The separate upgrade scenario installed CA bundle release 3 over release 2 and verified the new record, signature, symlink, contents and owner. See `foundation/vpac-install-scenario-01` and `foundation/vpac-upgrade-runtime-01/replay`, receipt SHA-256 `8aadaa39401e58548c4df2d50cc7147277df26d51a92920d23bf3cf7cdace8f5` and `e3dbc2800cabf2cee08dc91a2a7656e3ec031860da4a3a796fc0c917fab5866b`. The combined x86_64 replay reported a completed upgrade and timed out before the fixture passed. The AArch64 target-vpac trials remain pending. For later builds, `tools/build-queue.py` uses the source order and a verified bootstrap feed. Place the input archives and a `NAME.sha256` receipt for each in `$work/artifacts`. Configure the host compiler and signing tools as for a single native build, then select the ports to build. The worker uses this command form. diff --git a/tests/FEED.md b/tests/FEED.md index 6d81599..9c93d1a 100644 --- a/tests/FEED.md +++ b/tests/FEED.md @@ -155,4 +155,6 @@ Changing the netbase archive after signing caused assembly to fail its signed in The installed-root auditor checks each nonempty ELF load segment against the released kernel page size, 4 KiB on x86_64 and 16 KiB on aarch64. It also checks required symbol-version namespaces against the actual resolved package-owned provider using GNU readelf and objdump. The 106-package x86_64 root and the corrected arm64 loader passed. An old arm64 BusyBox failed its segment congruence check. An x86_64 libcrypto with its original SONAME and a changed version tag failed the OpenSSL consumer check. See `foundation/load-and-versions-02`, receipt SHA-256 `fd32f6b69db215ff6b79ec1f58c8457cf7f514dd162fbde410d9f6882072b979`. Use `tests/exec-linkage.py` as well to exercise actual dynamic symbol resolution. +Run the target vpac binary on the release kernel with `python3 tests/vpac-guest.py "$arch" "$repo" "$test_keys" "$fingerprint_file" "$update_receipt" "$auditor" "$boot" "$iso" "$output"`. Use a signed initial feed containing netbase and CA bundle release 2 and pass the receipt for CA bundle release 3. The guest has no network interface. The fixture tests a same-length package modification, authentic installation, local and remote lookup, and a signed in-place upgrade. Pass `--scenario install` or `--scenario upgrade` to replay either operation on a fresh copy of the same image inputs. The runner defaults to 720 seconds under QEMU TCG. `VINIX_QEMU_TIMEOUT` overrides that limit in seconds. + 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/busybox/boot.v b/tests/busybox/boot.v index ede2489..96995da 100644 --- a/tests/busybox/boot.v +++ b/tests/busybox/boot.v @@ -4,6 +4,7 @@ module main import crypto.sha256 import os +import strconv fn run(argv []string) ! { result := os.exec(argv) @@ -13,6 +14,12 @@ fn run(argv []string) ! { } fn boot_image(root string, iso string, output string, mode string, fixture string, disk string) ! { + deadline := strconv.atoi(os.getenv_opt('VINIX_QEMU_TIMEOUT') or { '120' }) or { + return error('VINIX_QEMU_TIMEOUT must be a positive integer in seconds') + } + if deadline <= 0 { + return error('VINIX_QEMU_TIMEOUT must be a positive integer in seconds') + } shell := mode == '--shell' arm := mode.starts_with('--aarch64-') userland := mode in ['--userland', '--aarch64-userland'] || fixture != '' @@ -127,7 +134,7 @@ fn boot_image(root string, iso string, output string, mode string, fixture strin } emulator << ['-accel', 'tcg', '-cpu', 'max', '-m', memory, '-smp', '2', '-nic', 'none', '-display', 'none', '-monitor', 'none', '-serial', 'file:' + log, '-no-reboot'] - run(['timeout', '120s', ...emulator])! + run(['timeout', '${deadline}s', ...emulator])! lines := os.read_lines(log)!.map(it.trim_space()) if disk != '' { id := os.read_file(os.join_path(root, '.vinix-image-id'))!.trim_space() diff --git a/tests/userland/vpac.sh b/tests/userland/vpac.sh new file mode 100644 index 0000000..e185630 --- /dev/null +++ b/tests/userland/vpac.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# Boot a root with target vpac installed and netbase available only in the embedded feed. +set -eu +export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/root +phase=identity +finish() { + status=$? + if [ "$status" -ne 0 ]; then echo "VPAC TRANSACTION FAIL at $phase with status $status"; fi + /sbin/poweroff -f +} +trap finish EXIT +test "$(uname -o)" = Vinix +mkdir -p /tmp +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) +install_test() { + test ! -e /etc/services + set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst + test "$#" -eq 1 && test -s "$1" + archive=$1 + + phase=reject + cp "$archive" /tmp/netbase-original + # Change the Zstd magic without changing the signed archive's byte count. + printf '\000' | dd of="$archive" bs=1 count=1 conv=notrunc 2>/dev/null + test "$(wc -c <"$archive")" = "$(wc -c /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 + test ! -e /etc/services + for record in /var/lib/vpac/local/netbase-*; do test ! -d "$record"; done + mv /tmp/netbase-original "$archive" + + phase=install + vpac i --noconfirm netbase + echo 'VPAC transaction installed authentic netbase' + phase=installed-ownership + vpac o /etc/services | grep -q netbase + phase=installed-record + vpac q -F name,validation local/netbase >/tmp/netbase + grep -Eq '^name[[:space:]]+netbase$' /tmp/netbase + grep -Eq '^validation[[:space:]]+signature$' /tmp/netbase + grep -Eq '^ssh[[:space:]]+22/tcp' /etc/services + + echo 'VPAC transaction verified installed owner and signature' + phase=remote-record + vpac q --noconfirm -F name,version vinix/netbase >/tmp/exact + grep -Eq '^name[[:space:]]+netbase$' /tmp/exact + echo 'VPAC transaction resolved the exact repository record' + phase=local-search + vpac s --noconfirm --local --quiet netbase >/tmp/local-names + grep -Fxq netbase /tmp/local-names + echo 'VPAC transaction searched installed packages' + phase=remote-search + vpac s --noconfirm --remote --quiet netbase >/tmp/remote-names + grep -Fxq netbase /tmp/remote-names + vpac s --noconfirm --remote --quiet vinix-fixture-absent-port >/tmp/unknown + test ! -s /tmp/unknown + + echo 'VPAC transaction verified package lookup' +} + +mode=${VPAC_TEST_SCENARIO:-all} +case "$mode" in + install) install_test; echo 'VPAC FIXTURE GUEST PASS'; exit 0 ;; + all) install_test ;; + upgrade) ;; + *) echo "unknown test scenario $mode" >&2; exit 2 ;; +esac +phase=upgrade +reference=/var/lib/vinix/test-update +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 +phase=upgraded-record +vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded +grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded +grep -Eq '^validation[[:space:]]+signature$' /tmp/upgraded +test ! -d /var/lib/vpac/local/ca-certificates-bundle-20261020-2 +phase=upgraded-files +test "$(readlink /etc/ssl1.1/cert.pem)" = ../ssl/cert.pem +cmp /etc/ssl1.1/cert.pem /etc/ssl/certs/ca-certificates.crt +vpac o /etc/ssl1.1/cert.pem | grep -q ca-certificates-bundle +echo 'VPAC FIXTURE GUEST PASS' diff --git a/tests/vpac-guest.py b/tests/vpac-guest.py new file mode 100644 index 0000000..ccba632 --- /dev/null +++ b/tests/vpac-guest.py @@ -0,0 +1,76 @@ +"""Boot a staged vpac image and test rejection, install and upgrade using the guest binary.""" +import argparse +import hashlib +import os +import shutil +import subprocess +import sys +from pathlib import Path + + +def run(args): + work = args.work + work.mkdir() + arch = args.arch + tests = Path(__file__).resolve().parent + pin = args.fingerprint.read_text().strip() + trust = work / "client-keys" + repo = args.repo + client = work / "client" + image = work / "image" + + 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]) + + # 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")): + raise ValueError("initial feed needs CA bundle release 2 and netbase") + digest, filename = args.update_receipt.read_text().strip().split() + if filename != "ca-certificates-bundle-20261020-3-any.pkg.tar.zst": + raise ValueError("expected CA bundle release 3 in the update receipt") + new = args.update_receipt.parent / filename + with new.open("rb") as stream: + if hashlib.file_digest(stream, "sha256").hexdigest() != digest: + raise ValueError("update archive differs from its build receipt") + update = work / "update" + siblings = sorted(path for path in initial.glob("*.pkg.tar.zst") if path != old) + log("publish-update", ["feed", "publish", args.keys, update, arch, new, *siblings]) + delta = root / "var/lib/vinix/test-update" + delta.mkdir() + for base in ("vinix.db", "vinix.files", new.name): + for name in (base, base + ".sig"): + shutil.copyfile(update / arch / name, delta / name) + + fixture = work / "fixture.sh" + fixture.write_bytes(f"VPAC_TEST_SCENARIO={args.scenario}\n".encode() + + (tests / "userland/vpac.sh").read_bytes()) + disk = work / "disk" + env = os.environ.copy() + env.setdefault("VINIX_QEMU_TIMEOUT", "720") + log("boot", [sys.executable, tests / "disk-root.py", arch, root, fixture, + args.iso, args.boot, disk], env=env) + files = sorted(work.glob("*.log")) + [fixture, disk / "guest/serial.log", disk / "receipts.sha256"] + with (work / "receipts.sha256").open("x") as report: + for file in files: + with file.open("rb") as stream: + report.write(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {file.relative_to(work)}\n") + + +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") + 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