feed: verify embedded signatures and install under fakeroot
@@ -13,6 +13,8 @@ v -o "$work/feed" tests/feed.v
13
114Each 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/`.
215
16+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.
17+
318For 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.
419
520```sh
@@ -1,7 +1,8 @@
11// Build an isolated file repository and install its signed packages in a new SDK.
22module main
33
4-import json2
4+import encoding.base64
5+import x.json2
56import net.urllib
67import os
78
@@ -14,7 +15,9 @@ fn output(argv []string) !string {
1415}
1516
1617fn gpg(keyring string, args []string) !string {
17- return output(['gpg', '--homedir', keyring, '--batch', '--no-tty', ...args])
18+ mut cmd := ['gpg', '--homedir', keyring, '--batch', '--no-tty']
19+ cmd << args
20+ return output(cmd)
1821}
1922
2023fn trust_key(state string, key string, fingerprint string) ! {
@@ -70,6 +73,7 @@ fn publish(state string, repo string, arch string, archives []string) ! {
7073 mut names := map[string]bool{}
7174 mut staged := []string{}
7275 mut receipts := ['name\tversion\tarch\tarchive\tsha256']
76+ mut signatures := map[string]string{}
7377 for archive in archives {
7478 name := os.file_name(archive)
7579 target := os.join_path(stage, name)
@@ -85,14 +89,28 @@ fn publish(state string, repo string, arch string, archives []string) ! {
8589 }
8690 names[id] = true
8791 digest := output(['sha256sum', target])!.all_before(' ')
88- receipts << [id, metadata_value(raw, 'pkgver')!, pkg_arch, name, digest].join('\t')
92+ version := metadata_value(raw, 'pkgver')!
93+ receipts << [id, version, pkg_arch, name, digest].join('\t')
8994 gpg(signer, ['--pinentry-mode', 'loopback', '--passphrase', '', '--local-user', fingerprint,
9095 '--output', target + '.sig', '--detach-sign', target])!
9196 gpg(trust, ['--verify', target + '.sig', target])!
97+ signatures['${id}-${version}/desc'] = base64.encode(os.read_bytes(target + '.sig')!)
9298 staged << target
9399 }
94- print(output(['env', 'GNUPGHOME=' + signer, 'repo-add', '--nocolor', '--sign', '--include-sigs',
95- '--key', fingerprint, os.join_path(stage, 'vinix.db.tar.gz'), ...staged])!)
100+ mut repo_add := ['env', 'GNUPGHOME=' + signer, 'repo-add', '--nocolor', '--sign']
101+ // Pacman 6 embeds signatures by default. Pacman 7 accepts an explicit flag.
102+ if output(['repo-add', '--help'])!.contains('--include-sigs') {
103+ repo_add << '--include-sigs'
104+ }
105+ db := os.join_path(stage, 'vinix.db.tar.gz')
106+ repo_add << ['--key', fingerprint, db]
107+ repo_add << staged
108+ print(output(repo_add)!)
109+ for member, signature in signatures {
110+ if !output(['bsdtar', '-xOf', db, member])!.contains('\n%PGPSIG%\n' + signature + '\n') {
111+ return error('signed database is missing the package signature in ${member}')
112+ }
113+ }
96114 for index in ['vinix.db', 'vinix.files'] {
97115 path := os.join_path(stage, index)
98116 gpg(trust, ['--verify', path + '.sig', path])!
@@ -103,7 +121,7 @@ fn publish(state string, repo string, arch string, archives []string) ! {
103121 os.rename(stage, os.join_path(repo, arch))!
104122}
105123
106-fn install(state string, repo string, arch string, client string, packages []string) ! {
124+fn install(state string, repo string, arch string, client string, packages []string, fakeroot bool) ! {
107125 if packages.any(it.len == 0 || it.starts_with('-') || it.contains('/')) {
108126 return error('expected package names from the signed repository')
109127 }
@@ -127,8 +145,8 @@ fn install(state string, repo string, arch string, client string, packages []str
127145 'network-disable-sandbox = true',
128146 'repositories = list(sync-repo("vinix", [' + json2.encode(url) + ']))',
129147 ].join('\n') + '\n')!
130- mut cmd := ['unshare', '-Urn', os.find_abs_path_of_executable('vpac')!, '--config', config,
131- 'i', '--noconfirm']
148+ mut cmd := if fakeroot { ['fakeroot', '--'] } else { ['unshare', '-Urn'] }
149+ cmd << [os.find_abs_path_of_executable('vpac')!, '--config', config, 'i', '--noconfirm']
132150 cmd << packages
133151 result := os.exec(cmd)
134152 os.write_file(os.join_path(client, 'install.log'), result.output)!
@@ -156,14 +174,20 @@ fn command(args []string) ! {
156174 return
157175 }
158176 if args[0] == 'install' && args.len >= 6 {
159- install(state, repo, args[3], os.abs_path(args[4]), args[5..])!
177+ fakeroot := args[5] == '--fakeroot'
178+ first_package := if fakeroot { 6 } else { 5 }
179+ packages := args[first_package..]
180+ if packages.len == 0 {
181+ return error('expected at least one package name')
182+ }
183+ install(state, repo, args[3], os.abs_path(args[4]), packages, fakeroot)!
160184 return
161185 }
162186 }
163187 eprintln('usage: feed keys NEW_KEY_STATE')
164188 eprintln(' feed trust NEW_CLIENT_KEY_STATE PUBLIC_KEY EXPECTED_FINGERPRINT')
165189 eprintln(' feed publish KEY_STATE NEW_REPO ARCH PACKAGE_ARCHIVE...')
166- eprintln(' feed install KEY_STATE REPO ARCH NEW_CLIENT PACKAGE_NAME...')
190+ eprintln(' feed install KEY_STATE REPO ARCH NEW_CLIENT [--fakeroot] PACKAGE_NAME...')
167191 exit(2)
168192}
169193