From e28fa26d6d3ec5c6fa3a6fcf2a33aa44326f5356 Mon Sep 17 00:00:00 2001 From: diviocity Date: Tue, 1 Dec 2026 02:08:29 +0100 Subject: [PATCH] Verify release ISO payloads without temporary extraction --- tests/FEED.md | 2 ++ tests/iso-initramfs.py | 9 ++++++++ tools/check-iso-initramfs.py | 40 +++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/tests/FEED.md b/tests/FEED.md index 25e001e..8cf5181 100644 --- a/tests/FEED.md +++ b/tests/FEED.md @@ -164,6 +164,8 @@ Use `$output/initramfs.tar` as `VINIX_AMD64_INITRAMFS` or `VINIX_AARCH64_INITRAM Run `python3 tools/check-iso-initramfs.py "$output/initramfs.tar" "$iso"` against each assembled ISO before accepting its release evidence. The checker compares the embedded tar payload byte for byte with the audited input and verifies the image identity that the ISO builder writes into the gzip header and appends to the tar. Run `python3 tests/iso-initramfs.py` to exercise rejection of altered payloads, wrong identities and added tar entries. +Use `--stream` on a worker with `bsdtar` to verify the compressed ISO member without extracting a temporary copy. The same byte and identity checks apply, including when the ISO member arrives through a pipe. + Both architecture-specific Vinix builders assembled test ISOs with the small, signed seed fixtures and the candidate kernels. The checker verified both embedded initramfs files and rejected the x86_64 ISO when given the AArch64 input. See `foundation/ports-candidate-iso-payload-proof-01`, receipt SHA-256 `cec4ae5654fe6a4c9967fd4d6e45ccf654c11902a0c16fa81eb3ab616037b2be`. For the private x86_64 desktop preview, the worker used the candidate kernel and source-built desktop layer, audited 70 installed packages, and verified the signatures and recipe coverage of 152 seed archives. The ISO payload matched the staged initramfs byte for byte, and a live QEMU KVM boot rendered the desktop at 1024×768 with 35 sampled colors. See `foundation/vpac-preview-amd64-01`, receipt SHA-256 `abf20c0c661261dd4e2950a998ace2717b8151a8980d184226aae321adc2311b`. The preview uses the worker's test signer. diff --git a/tests/iso-initramfs.py b/tests/iso-initramfs.py index ae4060d..268ce25 100644 --- a/tests/iso-initramfs.py +++ b/tests/iso-initramfs.py @@ -1,6 +1,7 @@ import gzip import hashlib import io +import os from pathlib import Path import runpy import tarfile @@ -49,6 +50,14 @@ class EmbeddedInitramfs(unittest.TestCase): self.write_embedded() self.assertEqual(CHECKER["check_payload"](self.prepared, self.embedded), self.checksum) + def test_reads_gzip_from_a_pipe(self): + self.write_embedded() + read_fd, write_fd = os.pipe() + with os.fdopen(read_fd, "rb") as reader: + with os.fdopen(write_fd, "wb") as writer: + writer.write(self.embedded.read_bytes()) + self.assertEqual(CHECKER["check_stream"](self.prepared, reader), self.checksum) + def test_rejects_changed_payload_with_original_identity(self): self.write_embedded(changed=True) with self.assertRaisesRegex(ValueError, "differs from the prepared tar"): diff --git a/tools/check-iso-initramfs.py b/tools/check-iso-initramfs.py index 314c183..ba098ac 100644 --- a/tools/check-iso-initramfs.py +++ b/tools/check-iso-initramfs.py @@ -14,6 +14,16 @@ CHUNK_SIZE = 1024**2 IDENTITY = "./.vinix-image-id" +class PrefixedReader: + def __init__(self, prefix, stream): + self.prefix = prefix + self.stream = stream + + def read(self, size): + prefix, self.prefix = self.prefix[:size], self.prefix[size:] + return prefix + self.stream.read(size - len(prefix)) + + def require_end_of_archive(stream): if stream.read(2 * BLOCK_SIZE) != bytes(2 * BLOCK_SIZE): raise ValueError("missing tar end marker") @@ -22,8 +32,8 @@ def require_end_of_archive(stream): raise ValueError("unexpected data after the tar end marker") -def check_payload(prepared, embedded): - with prepared.open("rb") as expected, embedded.open("rb") as compressed: +def check_stream(prepared, compressed): + with prepared.open("rb") as expected: checksum = hashlib.file_digest(expected, "sha256").hexdigest() identity = checksum[:16].encode() expected.seek(0) @@ -36,12 +46,11 @@ def check_payload(prepared, embedded): require_end_of_archive(expected) expected.seek(0) - header = compressed.read(10) comment = b"vinix-image-id=" + identity + b"\0" - if header[:4] != b"\x1f\x8b\x08\x10" or compressed.read(len(comment)) != comment: + header = compressed.read(10 + len(comment)) + if header[:4] != b"\x1f\x8b\x08\x10" or header[10:] != comment: raise ValueError("ISO gzip header has the wrong image identity") - compressed.seek(0) - with gzip.GzipFile(fileobj=compressed) as actual: + with gzip.GzipFile(fileobj=PrefixedReader(header, compressed)) as actual: remaining = payload_end while remaining: chunk = expected.read(min(CHUNK_SIZE, remaining)) @@ -57,6 +66,21 @@ def check_payload(prepared, embedded): return checksum +def check_payload(prepared, embedded): + with embedded.open("rb") as compressed: + return check_stream(prepared, compressed) + + +def verify_iso_stream(prepared, iso): + with subprocess.Popen(["bsdtar", "-xOf", iso.resolve(), "boot/initramfs.tar.gz"], + stdout=subprocess.PIPE) as extraction: + with extraction.stdout as compressed: + checksum = check_stream(prepared, compressed) + if extraction.wait(): + raise ValueError("could not read the ISO initramfs") + return checksum + + def verify_iso(prepared, iso): with tempfile.TemporaryDirectory(prefix="vinix-iso-initramfs-") as temporary: embedded = Path(temporary) / "initramfs.tar.gz" @@ -72,9 +96,11 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("prepared", type=Path, help="audited uncompressed initramfs.tar") parser.add_argument("iso", type=Path, help="assembled Vinix release ISO") + parser.add_argument("--stream", action="store_true", help="read the ISO member with bsdtar without a temporary file") args = parser.parse_args() try: - checksum = verify_iso(args.prepared, args.iso) + verify = verify_iso_stream if args.stream else verify_iso + checksum = verify(args.prepared, args.iso) except (OSError, EOFError, ValueError, tarfile.TarError) as error: parser.exit(1, f"{args.iso}: {error}\n") print(f"{checksum} prepared initramfs verified in {args.iso}") -- 2.56.1