me

/

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

Seed new vpac roots from a pinned packaged public certificate

diviocity committed 6 days ago · 7dda64bca70f9c3f942ea0bbfa30d9a7880be413 View patch
Unverified signature 3 files changed +130 -0
tests/FEED.md +16 -0

@@ -101,3 +101,19 @@ v -o "$work/boot" tests/busybox/boot.v

101```

1102

2103The x86_64 audit verified 27 signed package records, 9,583 owned files and links, and 110 target ELFs. Inside Vinix, the fixture loaded Zsh modules, edited a file with Vim, ran a Makefile, round-tripped compressed files, resolved pkg-config modules, parsed XML and verified the packaged ISRG root through OpenSSL. The serial log ends with `VPAC USERLAND GUEST PASS`. The worker keeps it under `musl-busybox-CqkBEA/foundation/userland-guest-01/serial.log` (SHA-256 `237592ae4c71ca99438e4fba943472c44c6890f60495a43204202c7ba2eb0837`). Boot harness revision `0a0ab0a` supports this run.

104+

105+### Seed a fresh image with a distributor's verification key

106+

107+Provide a public OpenPGP certificate and its full fingerprint from the trusted release configuration. Choose a new numeric package version each time the public material changes. Prepare the source port in worker state, build it through Vile and install it into the new image using the builder's existing trusted keyring.

108+

109+```sh

110+python3 tools/keyring.py prepare "$public_certificate" "$trusted_fingerprint" "$version" "$work/vinix-keyring"

111+vpac --native-build "$work/vinix-keyring/PKGBUILD.vile" "$work/keyring.manifest"

112+# Include the archive listed in keyring.manifest when publishing the signed feed.

113+feed install "$builder_keys" "$repo" x86_64 "$work/new-client" --fakeroot musl vinix-keyring

114+python3 tools/keyring.py seed "$work/new-client/root" "$trusted_fingerprint"

115+```

116+

117+`vinix-keyring` owns the public certificate and fingerprint in `/usr/share/vpac/keyrings/`. Image assembly initializes the mutable GnuPG keybox and trust database under `/etc/vpac.d/gnupg/`. The seed operation requires a fresh destination. The builder compares the independently supplied fingerprint before packaging and again before seeding.

118+

119+The worker used a disposable test signer in `foundation/keyring-03`. It rejected a wrong pin, installed the signed keyring, verified the signed database with the seeded keyring, and used that keyring alone for an offline vpac install of musl into another empty root. A second seed attempt preserved the existing keyring. The checksum manifest has SHA-256 `9d0868ef14da385aeddbca46b97cb154fdfe9ccd8b69a3e90d5a3c5f7f36ed3c`. The target-vpac guest transaction and provisioning the release signer's public certificate remain release checks.

tools/keyring.py new file +98 -0

@@ -0,0 +1,98 @@

1+"""Package a pinned public certificate or seed a new image's vpac verification keyring."""

2+import argparse

3+import hashlib

4+import os

5+import re

6+import shutil

7+import subprocess

8+import tempfile

9+from pathlib import Path

10+

11+

12+def gpg(home, *arguments, data=None):

13+ return subprocess.run(["gpg", "--homedir", home, "--no-options", "--batch", "--no-tty",

14+ "--no-autostart", *arguments], check=True, input=data, stdout=subprocess.PIPE).stdout

15+

16+

17+def fingerprint(value):

18+ value = value.upper()

19+ if not re.fullmatch(r"(?:[0-9A-F]{40}|[0-9A-F]{64})", value):

20+ raise argparse.ArgumentTypeError("expected the full OpenPGP fingerprint")

21+ return value

22+

23+

24+def import_certificate(home, public_key, expected):

25+ records = gpg(home, "--with-colons", "--import-options", "show-only", "--import", public_key)

26+ types = [line.split(b":", 1)[0] for line in records.splitlines()]

27+ if types.count(b"pub") != 1 or b"sec" in types or b"ssb" in types:

28+ raise ValueError("expected one public OpenPGP certificate")

29+ first = next((line.split(b":")[9].decode() for line in records.splitlines() if line.startswith(b"fpr:")), "")

30+ if first != expected:

31+ raise ValueError("certificate fingerprint differs from the trusted release fingerprint")

32+ gpg(home, "--import", public_key)

33+ if any(line.startswith((b"sec:", b"ssb:")) for line in gpg(home, "--with-colons", "--list-secret-keys").splitlines()):

34+ raise ValueError("secret key found in verification keyring")

35+

36+

37+def prepare(args):

38+ if not re.fullmatch(r"[0-9]+(?:\.[0-9]+)*", args.version):

39+ raise ValueError("expected a numeric keyring package version")

40+ with tempfile.TemporaryDirectory() as directory:

41+ home = Path(directory)

42+ import_certificate(home, args.public_key, args.fingerprint)

43+ public = gpg(home, "--export", args.fingerprint)

44+ if not public:

45+ raise ValueError("could not export public certificate")

46+ pin = (args.fingerprint + "\n").encode()

47+ template = Path(__file__).resolve().parent.parent / "vinix-keyring/PKGBUILD.vile.in"

48+ recipe = (template.read_text().replace("@VERSION@", args.version)

49+ .replace("@PUBLIC_SHA256@", hashlib.sha256(public).hexdigest())

50+ .replace("@FINGERPRINT_SHA256@", hashlib.sha256(pin).hexdigest()))

51+ args.output.mkdir()

52+ (args.output / "vinix.gpg").write_bytes(public)

53+ (args.output / "vinix.fingerprint").write_bytes(pin)

54+ (args.output / "PKGBUILD.vile").write_text(recipe)

55+

56+

57+def seed(args):

58+ # For freshly assembled roots. Upgrading live trust state requires a key rotation policy.

59+ root = args.root.resolve(strict=True)

60+ if root == Path("/") or not root.is_dir():

61+ raise ValueError("expected a staged image directory")

62+ certificates = root / "usr/share/vpac/keyrings"

63+ parent = root / "etc/vpac.d"

64+ for path in (parent, certificates / "vinix.gpg", certificates / "vinix.fingerprint"):

65+ if path.resolve() != path:

66+ raise ValueError(f"unexpected symlink in image keyring path: {path}")

67+ if (certificates / "vinix.fingerprint").read_text().strip() != args.fingerprint:

68+ raise ValueError("installed keyring fingerprint differs from the trusted release fingerprint")

69+ parent.mkdir(parents=True, exist_ok=True)

70+ dest = parent / "gnupg"

71+ if os.path.lexists(dest):

72+ raise ValueError(f"verification keyring already exists: {dest}")

73+ # Long image paths can exceed the Unix socket limit used by GnuPG.

74+ with tempfile.TemporaryDirectory() as directory, tempfile.TemporaryDirectory(dir=parent) as staging:

75+ home = Path(directory)

76+ import_certificate(home, certificates / "vinix.gpg", args.fingerprint)

77+ gpg(home, "--import-ownertrust", data=(args.fingerprint + ":6:\n").encode())

78+ gpg(home, "--check-trustdb")

79+ keybox = "pubring.kbx" if (home / "pubring.kbx").is_file() else "pubring.gpg"

80+ for name in (keybox, "trustdb.gpg"):

81+ shutil.copyfile(home / name, Path(staging) / name)

82+ (Path(staging) / name).chmod(0o600)

83+ Path(staging).rename(dest)

84+

85+

86+if __name__ == "__main__":

87+ parser = argparse.ArgumentParser(description=__doc__)

88+ sub = parser.add_subparsers(dest="command", required=True)

89+ make = sub.add_parser("prepare", help="materialize a reproducible Vile port outside Git")

90+ make.add_argument("public_key", type=Path)

91+ make.add_argument("fingerprint", type=fingerprint)

92+ make.add_argument("version")

93+ make.add_argument("output", type=Path)

94+ image = sub.add_parser("seed", help="initialize trust in a new, signed-package-installed root")

95+ image.add_argument("root", type=Path)

96+ image.add_argument("fingerprint", type=fingerprint)

97+ args = parser.parse_args()

98+ (prepare if args.command == "prepare" else seed)(args)

vinix-keyring/PKGBUILD.vile.in new file +16 -0

@@ -0,0 +1,16 @@

1+; tools/keyring.py prepares this recipe using the distributor's public certificate.

2+defpkgbuild(vinix-keyring,

3+ #:pkgname, "vinix-keyring",

4+ #:pkgver, "@VERSION@",

5+ #:pkgrel, 1,

6+ #:pkgdesc, "Public certificate used to verify the Vinix package repository",

7+ #:arch, [#:any],

8+ #:url, "https://github.com/vlang/vinix",

9+ #:license, "0BSD",

10+ #:source, ["vinix.gpg", "vinix.fingerprint"],

11+ #:sha256sums, ["@PUBLIC_SHA256@", "@FINGERPRINT_SHA256@"],

12+ #:package, fn() {

13+ for-each(fn(file) {

14+ run("install", "-Dm644", file, string-append(pkgdir(), "/usr/share/vpac/keyrings/", file))

15+ }, list("vinix.gpg", "vinix.fingerprint"))

16+ })