me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Verify release ISO payloads without temporary extraction

diviocity committed 4 days ago · e28fa26d6d3ec5c6fa3a6fcf2a33aa44326f5356 View patch
Unverified signature 3 files changed +44 -7
tests/FEED.md +2 -0

@@ -164,6 +164,8 @@ Use `$output/initramfs.tar` as `VINIX_AMD64_INITRAMFS` or `VINIX_AARCH64_INITRAM

164164

165165Run `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.

166166

167+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.

168+

167169Both 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`.

168170

169171For 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.

tests/iso-initramfs.py +9 -0

@@ -1,6 +1,7 @@

11import gzip

22import hashlib

33import io

4+import os

45from pathlib import Path

56import runpy

67import tarfile

@@ -49,6 +50,14 @@ class EmbeddedInitramfs(unittest.TestCase):

4950 self.write_embedded()

5051 self.assertEqual(CHECKER["check_payload"](self.prepared, self.embedded), self.checksum)

5152

53+ def test_reads_gzip_from_a_pipe(self):

54+ self.write_embedded()

55+ read_fd, write_fd = os.pipe()

56+ with os.fdopen(read_fd, "rb") as reader:

57+ with os.fdopen(write_fd, "wb") as writer:

58+ writer.write(self.embedded.read_bytes())

59+ self.assertEqual(CHECKER["check_stream"](self.prepared, reader), self.checksum)

60+

5261 def test_rejects_changed_payload_with_original_identity(self):

5362 self.write_embedded(changed=True)

5463 with self.assertRaisesRegex(ValueError, "differs from the prepared tar"):

tools/check-iso-initramfs.py +33 -7

@@ -14,6 +14,16 @@ CHUNK_SIZE = 1024**2

1414IDENTITY = "./.vinix-image-id"

1515

1616

17+class PrefixedReader:

18+ def __init__(self, prefix, stream):

19+ self.prefix = prefix

20+ self.stream = stream

21+

22+ def read(self, size):

23+ prefix, self.prefix = self.prefix[:size], self.prefix[size:]

24+ return prefix + self.stream.read(size - len(prefix))

25+

26+

1727def require_end_of_archive(stream):

1828 if stream.read(2 * BLOCK_SIZE) != bytes(2 * BLOCK_SIZE):

1929 raise ValueError("missing tar end marker")

@@ -22,8 +32,8 @@ def require_end_of_archive(stream):

2232 raise ValueError("unexpected data after the tar end marker")

2333

2434

25-def check_payload(prepared, embedded):

26- with prepared.open("rb") as expected, embedded.open("rb") as compressed:

35+def check_stream(prepared, compressed):

36+ with prepared.open("rb") as expected:

2737 checksum = hashlib.file_digest(expected, "sha256").hexdigest()

2838 identity = checksum[:16].encode()

2939 expected.seek(0)

@@ -36,12 +46,11 @@ def check_payload(prepared, embedded):

3646 require_end_of_archive(expected)

3747 expected.seek(0)

3848

39- header = compressed.read(10)

4049 comment = b"vinix-image-id=" + identity + b"\0"

41- if header[:4] != b"\x1f\x8b\x08\x10" or compressed.read(len(comment)) != comment:

50+ header = compressed.read(10 + len(comment))

51+ if header[:4] != b"\x1f\x8b\x08\x10" or header[10:] != comment:

4252 raise ValueError("ISO gzip header has the wrong image identity")

43- compressed.seek(0)

44- with gzip.GzipFile(fileobj=compressed) as actual:

53+ with gzip.GzipFile(fileobj=PrefixedReader(header, compressed)) as actual:

4554 remaining = payload_end

4655 while remaining:

4756 chunk = expected.read(min(CHUNK_SIZE, remaining))

@@ -57,6 +66,21 @@ def check_payload(prepared, embedded):

5766 return checksum

5867

5968

69+def check_payload(prepared, embedded):

70+ with embedded.open("rb") as compressed:

71+ return check_stream(prepared, compressed)

72+

73+

74+def verify_iso_stream(prepared, iso):

75+ with subprocess.Popen(["bsdtar", "-xOf", iso.resolve(), "boot/initramfs.tar.gz"],

76+ stdout=subprocess.PIPE) as extraction:

77+ with extraction.stdout as compressed:

78+ checksum = check_stream(prepared, compressed)

79+ if extraction.wait():

80+ raise ValueError("could not read the ISO initramfs")

81+ return checksum

82+

83+

6084def verify_iso(prepared, iso):

6185 with tempfile.TemporaryDirectory(prefix="vinix-iso-initramfs-") as temporary:

6286 embedded = Path(temporary) / "initramfs.tar.gz"

@@ -72,9 +96,11 @@ if __name__ == "__main__":

7296 parser = argparse.ArgumentParser(description=__doc__)

7397 parser.add_argument("prepared", type=Path, help="audited uncompressed initramfs.tar")

7498 parser.add_argument("iso", type=Path, help="assembled Vinix release ISO")

99+ parser.add_argument("--stream", action="store_true", help="read the ISO member with bsdtar without a temporary file")

75100 args = parser.parse_args()

76101 try:

77- checksum = verify_iso(args.prepared, args.iso)

102+ verify = verify_iso_stream if args.stream else verify_iso

103+ checksum = verify(args.prepared, args.iso)

78104 except (OSError, EOFError, ValueError, tarfile.TarError) as error:

79105 parser.exit(1, f"{args.iso}: {error}\n")

80106 print(f"{checksum} prepared initramfs verified in {args.iso}")