From 079afeaaf284232615ff2296a7928657eb058ecd Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 18:14:55 +0100 Subject: [PATCH] Assemble X11 sidecars from audited Vinix package roots --- tests/x11/README.md | 8 ++++ tests/x11/bundle.py | 79 +++++++++++++++++++++++++++++++++ tools/bundle-x11.py | 106 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 tests/x11/bundle.py create mode 100644 tools/bundle-x11.py diff --git a/tests/x11/README.md b/tests/x11/README.md index 2ae8dcd..67108a3 100644 --- a/tests/x11/README.md +++ b/tests/x11/README.md @@ -59,6 +59,14 @@ For those checks, install `vinix-release-x11` and `busybox-init` from the signed For the on-demand release test, combine the signed desktop and X11 package lists with `tests/combined-feed.py --publish-only`. Pass the combined feed to `tools/desktop-root.py` to install the desktop metapackage and embed the signed feed. Add the native desktop programs and framebuffer probe as in `tests/desktop-guest.py`. Set `VINIX_DESKTOP_NEXT_FIXTURE` in the desktop fixture to the guest path of `graphics.sh` and set `VINIX_X11_INSTALL_FROM_PKG=1` in that script. With `tests/disk-root.py --desktop-init --space-for "$x11_sdk/root"`, the guest must reach graphical registration, resolve `x11` by exact name, install the signed X11 metapackage, verify the server and Mesa owners, and pass both rendered pixel checks. +Use the same signed feed for the downloadable X11 sidecar. Cold-install `vinix-release-desktop` into one client. Into a second client, cold-install both `vinix-release-desktop` and `vinix-release-x11` with the target font hooks enabled. + +```sh +python3 tools/bundle-x11.py "$arch" "$desktop_client" "$x11_client" "$auditor" "$output" +``` + +The tool audits both clients and checks the package versions, modes, link targets and bytes shared with the desktop. It writes the new paths to a root-owned archive under the published name `vinix-x11-amd64.tar.gz` or `vinix-x11-arm64.tar.gz`, with a matching checksum file. The package manager installs from the signed feed. Run `python3 tests/x11/bundle.py` for the archive layout, link preservation and rejection checks. The worker fixture is in `foundation/x11-bundle-fixture-01`, receipt SHA-256 `0a9abdd8e27a93cc6bb6926b1a95b9c7a46e281274c9fd7015a343c8255781dc`. + Both architectures passed the desktop PID 1 and framebuffer checks from a disposable ext2 image. Those runs used the five checksum-pinned native programs from the November 28 release. The x86_64 chained fixture also ran its second script after registration and verified the larger disk size. A separate test published a signed feed with `--publish-only`, then installed musl and netbase into a clean root using the pinned public key. See `foundation/native-desktop-disk-path-01`, `foundation/native-desktop-chained-fixture-01` and `foundation/combined-publish-only-01`, receipt SHA-256 `86c564cb9415859d2411343f74b8ad8926418c16bedb4a612aab85db46137ccd`, `cb2d6c6afbdf2733676080f49792aa11b10907d1778d2bc3d01ae3317874a7e0` and `afde40678739b96cf16db58803ef87447ae4499a9e70f3425814a244e12d6883`. The complete desktop and X11 transaction still needs both graphics feeds. Set `VINIX_MESA_NATIVE_FILE` to a Meson native machine file whose `pkg_config_path` includes a build-host `wayland-scanner.pc`. The worker reused the source-built x86_64 Wayland scanner from an audited signed root. Meson found the native scanner through that file, found the target Wayland client in the SDK, and generated a protocol header. Mako and Intel CLC run in the build environment. See `xorg/mesa-host-tools-03/generator-check`, receipt SHA-256 `8df63367710d4ead9e968d30fe97eb3c63b45b4eba0f444447f5bf75b0cd4229`. diff --git a/tests/x11/bundle.py b/tests/x11/bundle.py new file mode 100644 index 0000000..eeea040 --- /dev/null +++ b/tests/x11/bundle.py @@ -0,0 +1,79 @@ +"""Test the release overlay layout and rejection of a changed base.""" + +import argparse +import hashlib +from importlib import import_module +import os +from pathlib import Path +import sys +import tarfile +import tempfile +import unittest + + +sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "tools")) +sidecar = import_module("bundle-x11") + + +class BundleTest(unittest.TestCase): + def setUp(self): + work = tempfile.TemporaryDirectory() + self.addCleanup(work.cleanup) + self.base, self.full, self.output = (Path(work.name, name) for name in ("base", "full", "output")) + for client in (self.base, self.full): + self.install_record(client, "vinix-release-desktop", "1-1") + (client / "root/usr/bin").mkdir(parents=True) + (client / "root/usr/bin/pkg").write_bytes(b"desktop package manager") + self.install_record(self.full, "vinix-release-x11", "2-1") + for path in sidecar.RELEASE_COMMANDS: + command = self.full / "root" / path + command.write_bytes(path.encode()) + command.chmod(0o755) + + def install_record(self, client, name, version): + directory = client / "db/local" / f"{name}-{version}" + directory.mkdir(parents=True) + (directory / "desc").write_text(f"%NAME%\n{name}\n\n%VERSION%\n{version}\n\n") + + def write_bundle(self, arch="x86_64"): + # Signature and ELF checks run in the signed-root release fixture. + sidecar.bundle(argparse.Namespace( + desktop=self.base, x11=self.full, output=self.output, auditor="/bin/true", arch=arch)) + + def test_arm64_overlay_preserves_links_and_omits_desktop_paths(self): + drivers = self.full / "root/usr/lib/dri" + drivers.mkdir(parents=True) + driver = drivers / "swrast_dri.so" + driver.write_bytes(b"software driver") + os.link(driver, drivers / "kms_swrast_dri.so") + (drivers / "swrast.so").symlink_to(driver.name) + + self.write_bundle("aarch64") + + archive = self.output / "vinix-x11-arm64.tar.gz" + digest = hashlib.sha256(archive.read_bytes()).hexdigest() + self.assertEqual(archive.with_suffix(".gz.sha256").read_text(), f"{digest} {archive.name}\n") + with tarfile.open(archive) as tar: + self.assertNotIn("./usr/bin/pkg", tar.getnames()) + self.assertNotIn("./usr/bin", tar.getnames()) + self.assertNotIn("./db", tar.getnames()) + binary = tar.getmember("./usr/bin/Xvfb") + self.assertEqual((binary.uid, binary.gid, binary.mode), (0, 0, 0o755)) + self.assertEqual(tar.getmember("./usr/lib/dri/swrast.so").linkname, driver.name) + self.assertTrue(tar.getmember("./usr/lib/dri/swrast_dri.so").islnk()) + + def test_changed_desktop_bytes_prevent_publication(self): + (self.full / "root/usr/bin/pkg").write_bytes(b"replaced package manager") + with self.assertRaisesRegex(ValueError, "changed /usr/bin/pkg"): + self.write_bundle() + self.assertFalse(self.output.exists()) + + def test_missing_glx_server_prevents_publication(self): + (self.full / "root/usr/bin/Xvfb-glx").unlink() + with self.assertRaisesRegex(ValueError, "missing executable /usr/bin/Xvfb-glx"): + self.write_bundle() + self.assertFalse(self.output.exists()) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/bundle-x11.py b/tools/bundle-x11.py new file mode 100644 index 0000000..42ca8dd --- /dev/null +++ b/tools/bundle-x11.py @@ -0,0 +1,106 @@ +"""Assemble a release X11 overlay from two audited vpac clients.""" + +import argparse +import filecmp +import gzip +import hashlib +from importlib import import_module +import os +from pathlib import Path +import stat +import subprocess +import tarfile +import tempfile + +RELEASE_COMMANDS = ( + "usr/bin/Xorg", "usr/bin/Xvfb", "usr/bin/Xvfb-glx", "usr/bin/startx", + "usr/bin/vinix-wine-host", "usr/bin/vinix-xinput", +) + + +def tree(root): + entries = {} + for directory, folders, files in os.walk(root): + # os.walk puts symlinks to directories in folders but does not traverse them. + for name in folders + files: + path = Path(directory, name) + entries[path.relative_to(root).as_posix()] = path.lstat().st_mode + return entries + + +def overlay_paths(base, full): + before, after = tree(base), tree(full) + for path, mode in before.items(): + updated = after.get(path) + if updated is None or mode != updated: + raise ValueError(f"X11 install removed or replaced /{path}") + if stat.S_ISDIR(mode): + continue + original, installed = base / path, full / path + matches = (os.readlink(original) == os.readlink(installed) if stat.S_ISLNK(mode) + else filecmp.cmp(original, installed, shallow=False)) + if not matches: + raise ValueError(f"X11 install changed /{path} from the desktop root") + added = sorted(after.keys() - before.keys()) + for path in added: + mode = after[path] + if not (stat.S_ISREG(mode) or stat.S_ISLNK(mode) or stat.S_ISDIR(mode)): + raise ValueError(f"unexpected sidecar entry type for /{path}") + return added + + +def packages(client): + package_fields = import_module("stage-image").package_fields + records = (client / "db/local").glob("*/desc") + return {record["NAME"]: record["VERSION"] + for record in (package_fields(path.read_text()) for path in records)} + + +def owner_root(entry): + entry.uid = entry.gid = 0 + entry.uname = entry.gname = "root" + return entry + + +def bundle(args): + base, full = args.desktop.resolve(), args.x11.resolve() + output = args.output.resolve() + if output.is_relative_to(base) or output.is_relative_to(full): + raise ValueError("put sidecar output outside both clients") + if output.exists(): + raise FileExistsError(output) + for client in (base, full): + subprocess.run([args.auditor, args.arch, client], check=True) + common, combined = packages(base), packages(full) + if ("vinix-release-desktop" not in common or "vinix-release-x11" in common + or "vinix-release-x11" not in combined or not common.items() < combined.items()): + raise ValueError("expected desktop and desktop-plus-X11 package roots") + base, full = base / "root", full / "root" + paths = overlay_paths(base, full) + for name in RELEASE_COMMANDS: + if name not in paths or not os.access(full / name, os.X_OK): + raise ValueError(f"sidecar is missing executable /{name}") + + suffix = "amd64" if args.arch == "x86_64" else "arm64" + name = f"vinix-x11-{suffix}.tar.gz" + with tempfile.TemporaryDirectory(dir=output.parent) as work: + staging = Path(work, "sidecar") + staging.mkdir(mode=0o755) + archive = staging / name + with archive.open("xb") as data: + with gzip.GzipFile(filename="", mode="wb", fileobj=data, mtime=0) as compressed: + with tarfile.open(fileobj=compressed, mode="w|", format=tarfile.USTAR_FORMAT) as tar: + for path in paths: + tar.add(full / path, arcname=f"./{path}", recursive=False, filter=owner_root) + with archive.open("rb") as data: + digest = hashlib.file_digest(data, "sha256").hexdigest() + (staging / (name + ".sha256")).write_text(f"{digest} {name}\n") + staging.rename(output) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("arch", choices=("x86_64", "aarch64")) + for label in ("desktop", "x11", "auditor", "output"): + parser.add_argument(label, type=Path) + bundle(parser.parse_args()) -- 2.56.1