From c7be15b1dad9105fc7c7414ec161b2c90b4a17f6 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 22:12:54 +0100 Subject: [PATCH] Exercise a signed pkg upgrade over HTTPS in QEMU --- tests/FEED.md | 2 ++ tests/userland/vpac.sh | 35 ++++++++++++++++++++++++++++++++++- tests/vpac-guest.py | 26 +++++++++++++++++++------- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/tests/FEED.md b/tests/FEED.md index ddb6db2..8fde54f 100644 --- a/tests/FEED.md +++ b/tests/FEED.md @@ -225,6 +225,8 @@ For the public `pkg` command, install `vinix-pkg`, `busybox-init`, `vinix-keyrin 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`. +Add `--upgrade-https` to serve the signed update on guest loopback TLS and switch the disposable guest's vpac repository URL to that endpoint. The fixture uses the packaged curl and OpenSSL, and the upgrade checks vpac's signature validation record with the normal package and database signature requirements enabled. With `--signed-update "$previous_update_feed"`, the runner compares the existing signed package against the build receipt before staging it and its indexes. The first x86_64 HTTPS run installed the signed update on the candidate kernel. Its test disk and roots can be restored using `replay.sha256` and `restore-paths` in `foundation/ports-candidate-https-upgrades-02/amd64`, archive evidence SHA-256 `a9835ee287eaca1832782f70d46c4a59438751230a7955178b1bd41cfde7679f`. + The original ext2 files from `vinix-pkg-guest-01`, `vinix-pkg-upgrade-01` and `vpac-transaction-08` are compressed in `foundation/archived-pkg-fixture-disks-01`. Its `restore.tsv` gives their original paths, uncompressed checksums, modes and timestamps. Restore each needed file with `zstd -d --sparse` before rerunning its disk receipt checks. Each expanded archive matched the original checksum before relocation. The archive receipt manifest has SHA-256 `c5b49fbb69cddfe2fcb3828cd1b7316d48b4f1ef90a155fa369f2ba63a32bbf9`. 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 e1a7a6b..6d05a8b 100644 --- a/tests/userland/vpac.sh +++ b/tests/userland/vpac.sh @@ -3,8 +3,10 @@ set -eu export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/root phase=identity +tls_server= finish() { status=$? + if [ -n "$tls_server" ]; then kill "$tls_server" 2>/dev/null || true; fi if [ "$status" -ne 0 ]; then echo "VPAC TRANSACTION FAIL at $phase with status $status"; fi /sbin/poweroff -f } @@ -92,7 +94,35 @@ 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/" +if [ "${VPAC_TEST_UPGRADE_HTTPS:-0}" = 1 ]; then + phase=upgrade-https-setup + unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY SSL_CERT_FILE SSL_CERT_DIR + tls=$(mktemp -d /tmp/vpac-fixture-tls.XXXXXX) + openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 1 \ + -subj /CN=127.0.0.1 -addext subjectAltName=IP:127.0.0.1 \ + -keyout "$tls/key.pem" -out "$tls/cert.pem" + ( + cd "$reference" + exec openssl s_server -accept 127.0.0.1:28443 -cert "$tls/cert.pem" -key "$tls/key.pem" -WWW + ) >"$tls/server.log" 2>&1 & + tls_server=$! + url=https://127.0.0.1:28443 + tries=0 + until curl --disable --noproxy '*' --fail --silent --show-error --max-time 5 \ + --cacert "$tls/cert.pem" "$url/vinix.db" -o "$tls/remote.db" >"$tls/client.log" 2>&1; do + tries=$((tries + 1)) + if [ "$tries" -ge 5 ]; then cat "$tls/client.log" "$tls/server.log"; exit 1; fi + sleep 1 + done + cmp "$reference/vinix.db" "$tls/remote.db" + trust_hash=$(openssl x509 -in "$tls/cert.pem" -noout -subject_hash) + cp "$tls/cert.pem" "/etc/ssl/certs/$trust_hash.0" + sed -i "s|file:///var/lib/vinix/repository/$arch|$url|" /etc/vpac.d/config.vile + grep -Fq "$url" /etc/vpac.d/config.vile +else + cp "$reference/"* "/var/lib/vinix/repository/$arch/" +fi +phase=upgrade if [ "$package_command" = pkg ]; then pkg upgrade else @@ -107,4 +137,7 @@ 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 +if [ "${VPAC_TEST_UPGRADE_HTTPS:-0}" = 1 ]; then + echo 'VPAC upgraded a signed package over HTTPS' +fi echo 'VPAC FIXTURE GUEST PASS' diff --git a/tests/vpac-guest.py b/tests/vpac-guest.py index 459d066..151d58c 100644 --- a/tests/vpac-guest.py +++ b/tests/vpac-guest.py @@ -56,9 +56,14 @@ def run(args): 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]) + update = args.signed_update or work / "update" + if args.signed_update: + with (update / arch / filename).open("rb") as stream: + if hashlib.file_digest(stream, "sha256").hexdigest() != digest: + raise ValueError("reused signed update differs from its build receipt") + else: + 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() delta.chmod(0o755) @@ -69,13 +74,14 @@ def run(args): target.chmod(0o644) fixture = work / "fixture.sh" - fixture.write_bytes(f"VPAC_TEST_SCENARIO={args.scenario}\nVPAC_TEST_PACKAGE_COMMAND={args.package_command}\n".encode() - + (tests / "userland/vpac.sh").read_bytes()) + settings = (f"VPAC_TEST_SCENARIO={args.scenario}\nVPAC_TEST_PACKAGE_COMMAND={args.package_command}\n" + f"VPAC_TEST_UPGRADE_HTTPS={int(args.upgrade_https)}\n") + fixture.write_bytes(settings.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) + args.iso, args.boot, disk, "--link-inputs"], 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: @@ -88,8 +94,14 @@ if __name__ == "__main__": 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("--upgrade-https", action="store_true", help="serve the signed upgrade over guest loopback TLS") + parser.add_argument("--signed-update", type=lambda path: Path(path).resolve(), + help="reuse an existing signed update repository with the exact upgrade archive") 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()) + args = parser.parse_args() + if args.upgrade_https and args.scenario == "install": + parser.error("--upgrade-https requires an upgrade scenario") + run(args) -- 2.56.1