From ff8f3dfb38f20d7e12eb006d82f9b724ceef8d06 Mon Sep 17 00:00:00 2001 From: diviocity Date: Sun, 29 Nov 2026 23:50:39 +0100 Subject: [PATCH] feed: verify embedded signatures and install under fakeroot --- tests/FEED.md | 2 ++ tests/feed.v | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/tests/FEED.md b/tests/FEED.md index 1800ec0..0731c5c 100644 --- a/tests/FEED.md +++ b/tests/FEED.md @@ -13,6 +13,8 @@ v -o "$work/feed" tests/feed.v Each destination must be new. The publisher verifies each package signature, embeds signatures in the signed repository database, verifies both index signatures and records archive SHA-256 values in `repo/packages.tsv`. The installer checks the database and package signatures through vpac while syncing and resolving package names. Its isolated client keeps the root, database, cache, configuration and log under `sdk/`. +A builder with its own unprivileged service account and private state directory can use `feed install KEY_STATE REPO ARCH NEW_CLIENT --fakeroot PACKAGE_NAME...` when user namespaces are unavailable. This runs vpac under fakeroot and keeps the same signed file repository and new client directory. + For a separate consumer, transfer the repository directory and obtain the expected fingerprint independently from the test owner. Import the public key into a client-only keyring. ```sh diff --git a/tests/feed.v b/tests/feed.v index 1e9e174..f1461e1 100644 --- a/tests/feed.v +++ b/tests/feed.v @@ -1,7 +1,8 @@ // Build an isolated file repository and install its signed packages in a new SDK. module main -import json2 +import encoding.base64 +import x.json2 import net.urllib import os @@ -14,7 +15,9 @@ fn output(argv []string) !string { } fn gpg(keyring string, args []string) !string { - return output(['gpg', '--homedir', keyring, '--batch', '--no-tty', ...args]) + mut cmd := ['gpg', '--homedir', keyring, '--batch', '--no-tty'] + cmd << args + return output(cmd) } fn trust_key(state string, key string, fingerprint string) ! { @@ -70,6 +73,7 @@ fn publish(state string, repo string, arch string, archives []string) ! { mut names := map[string]bool{} mut staged := []string{} mut receipts := ['name\tversion\tarch\tarchive\tsha256'] + mut signatures := map[string]string{} for archive in archives { name := os.file_name(archive) target := os.join_path(stage, name) @@ -85,14 +89,28 @@ fn publish(state string, repo string, arch string, archives []string) ! { } names[id] = true digest := output(['sha256sum', target])!.all_before(' ') - receipts << [id, metadata_value(raw, 'pkgver')!, pkg_arch, name, digest].join('\t') + version := metadata_value(raw, 'pkgver')! + receipts << [id, version, pkg_arch, name, digest].join('\t') gpg(signer, ['--pinentry-mode', 'loopback', '--passphrase', '', '--local-user', fingerprint, '--output', target + '.sig', '--detach-sign', target])! gpg(trust, ['--verify', target + '.sig', target])! + signatures['${id}-${version}/desc'] = base64.encode(os.read_bytes(target + '.sig')!) staged << target } - print(output(['env', 'GNUPGHOME=' + signer, 'repo-add', '--nocolor', '--sign', '--include-sigs', - '--key', fingerprint, os.join_path(stage, 'vinix.db.tar.gz'), ...staged])!) + mut repo_add := ['env', 'GNUPGHOME=' + signer, 'repo-add', '--nocolor', '--sign'] + // Pacman 6 embeds signatures by default. Pacman 7 accepts an explicit flag. + if output(['repo-add', '--help'])!.contains('--include-sigs') { + repo_add << '--include-sigs' + } + db := os.join_path(stage, 'vinix.db.tar.gz') + repo_add << ['--key', fingerprint, db] + repo_add << staged + print(output(repo_add)!) + for member, signature in signatures { + if !output(['bsdtar', '-xOf', db, member])!.contains('\n%PGPSIG%\n' + signature + '\n') { + return error('signed database is missing the package signature in ${member}') + } + } for index in ['vinix.db', 'vinix.files'] { path := os.join_path(stage, index) gpg(trust, ['--verify', path + '.sig', path])! @@ -103,7 +121,7 @@ fn publish(state string, repo string, arch string, archives []string) ! { os.rename(stage, os.join_path(repo, arch))! } -fn install(state string, repo string, arch string, client string, packages []string) ! { +fn install(state string, repo string, arch string, client string, packages []string, fakeroot bool) ! { if packages.any(it.len == 0 || it.starts_with('-') || it.contains('/')) { return error('expected package names from the signed repository') } @@ -127,8 +145,8 @@ fn install(state string, repo string, arch string, client string, packages []str 'network-disable-sandbox = true', 'repositories = list(sync-repo("vinix", [' + json2.encode(url) + ']))', ].join('\n') + '\n')! - mut cmd := ['unshare', '-Urn', os.find_abs_path_of_executable('vpac')!, '--config', config, - 'i', '--noconfirm'] + mut cmd := if fakeroot { ['fakeroot', '--'] } else { ['unshare', '-Urn'] } + cmd << [os.find_abs_path_of_executable('vpac')!, '--config', config, 'i', '--noconfirm'] cmd << packages result := os.exec(cmd) os.write_file(os.join_path(client, 'install.log'), result.output)! @@ -156,14 +174,20 @@ fn command(args []string) ! { return } if args[0] == 'install' && args.len >= 6 { - install(state, repo, args[3], os.abs_path(args[4]), args[5..])! + fakeroot := args[5] == '--fakeroot' + first_package := if fakeroot { 6 } else { 5 } + packages := args[first_package..] + if packages.len == 0 { + return error('expected at least one package name') + } + install(state, repo, args[3], os.abs_path(args[4]), packages, fakeroot)! return } } eprintln('usage: feed keys NEW_KEY_STATE') eprintln(' feed trust NEW_CLIENT_KEY_STATE PUBLIC_KEY EXPECTED_FINGERPRINT') eprintln(' feed publish KEY_STATE NEW_REPO ARCH PACKAGE_ARCHIVE...') - eprintln(' feed install KEY_STATE REPO ARCH NEW_CLIENT PACKAGE_NAME...') + eprintln(' feed install KEY_STATE REPO ARCH NEW_CLIENT [--fakeroot] PACKAGE_NAME...') exit(2) } -- 2.56.1