gunk-dev/the-valley

signers-e2e.sh

sourcecfedff357a41main's published tip history
27.8 KiB
1# shellcheck shell=bash
2# The signers publication, end to end. The publisher the module renders
3# writes it into an instance repository, and fresh clones of a project
4# that names that instance verify a landing with it. Both repositories run
5# the fixture host's rendered pre-receive hook. The integrator is the real
6# one, driving the nix stand-in of integrator/e2e, and it signs under its
7# default name, as a host that sets no signing name has it do.
8#
9# Two things are written on disk rather than pushed, as the host's
10# machinery writes them: valley-init's project list, and the publication
11# itself. The hook refuses a push to either. Each is marked where it is
12# made.
13# Paths and fixtures come from the derivation environment.
14# shellcheck disable=SC2154
15set -euo pipefail
16
17w="$TMPDIR/signers-e2e"
18mkdir -p "$w"
19export HOME="$w"
20export GIT_CONFIG_NOSYSTEM=1
21unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER VALLEY_PRINCIPAL
22git config --global user.name signers-e2e
23git config --global user.email signers-e2e@localhost
24git config --global init.defaultBranch main
25git config --global advice.detachedHead false
26
27fail() {
28 printf 'signers-e2e: %s\n' "$*" >&2
29 for f in "$w"/out "$w"/err; do
30 if [ -s "$f" ]; then cat "$f" >&2; fi
31 done
32 exit 1
33}
34
35cp -r "$integratorE2e" "$w/stand-ins"
36chmod -R +w "$w/stand-ins"
37patchShebangs "$w/stand-ins" > /dev/null
38export PATH="$w/stand-ins:$PATH" VALLEY_FAKE_STORE="$w/store"
39
40mkdir -p "$w/keys"
41for who in contributor integrator rotated; do install -m 600 "$keys/$who" "$w/keys/$who"; done
42contributor=contributor.valley.invalid/attestations
43# The name the controller signs under: the binary's default, which is this
44# machine's name.
45name="$(uname -n)/attestations"
46# The file the controller is given as --known-signers. signers_for writes it
47# for the integrator key given.
48signers="$w/known-signers"
49signers_for() {
50 {
51 attest key --key "$w/keys/contributor" --name "$contributor"
52 attest key --key "$1" --name "$name"
53 } > "$signers"
54}
55signers_for "$w/keys/integrator"
56
57hook="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)"
58test -x "$hook"
59instance="$w/instance.git"
60served="$w/served.git"
61for repo in "$instance" "$served"; do
62 git init --quiet --bare "$repo"
63 cp "$hook" "$repo/hooks/pre-receive"
64 chmod +x "$repo/hooks/pre-receive"
65done
66
67# The publisher as the module renders it for a host that serves sealed as
68# its instance repository and sets no signing name, pointed at this test's
69# instance repository and signers file.
70read -ra publish <<< "$publishCommand"
71publish=("${publish[@]//\/srv\/git\/sealed.git/$instance}")
72publish=("${publish[@]//\/var\/lib\/valley-instance\/known_signers/$signers}")
73case " ${publish[*]} " in
74 *" publish-signers --instance-repo $instance --known-signers $signers ") ;;
75 *) fail "the rendered publisher is not the one this test drives: $publishCommand" ;;
76esac
77
78# The instance repository carries the floor, and the project names it at
79# policy/valley.
80mkdir -p "$w/floor"
81printf 'package verification\n\nfloor: {\n\tchecks: {}\n\tclasses: {}\n\tunclassified: {}\n}\n' > "$w/floor/floor.cue"
82git init --quiet "$w/seed"
83mkdir -p "$w/seed/policy/instance"
84cp "$w/floor/floor.cue" "$w/seed/policy/instance/"
85git -C "$w/seed" add -A
86git -C "$w/seed" commit --quiet -m 'the floor'
87git -C "$w/seed" push --quiet "$instance" main
88# Written on disk, as valley-init writes it: the host's project list.
89projects="$(printf '%s\n' instance served | git -C "$instance" hash-object -w --stdin)"
90git -C "$instance" update-ref refs/the-valley/projects "$projects"
91
92git init --quiet "$w/fixture"
93cd "$w/fixture"
94git remote add origin "$served"
95mkdir -p docs src checks policy/project
96printf '%s\n' "$instance" > policy/valley
97echo "the readme" > docs/readme.md
98echo "the source" > src/main.txt
99echo docs > checks/prose-format.inputs
100echo src > checks/code-build.inputs
101cat > policy/project/policy.cue << 'CUE'
102package verification
103
104project: {
105 checks: {
106 "prose-format": {runner: "nix", attribute: "prose-format"}
107 "code-build": {runner: "nix", attribute: "code-build"}
108 }
109 classes: {
110 prose: {paths: "docs/**": true, requires: "prose-format": true}
111 code: {paths: "src/**": true, requires: "code-build": true}
112 }
113 unclassified: {}
114}
115CUE
116git add -A
117git commit --quiet -m 'seed the project'
118git push --quiet origin main
119
120as() {
121 local who="$1"
122 shift
123 git config valley.principal "$who"
124 VALLEY_PRINCIPAL="$who" "$@"
125}
126ok() { "$@" > "$w/out" 2> "$w/err" || fail "$* failed"; }
127id() { sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$w/out"; }
128# readied <branch>: alice's change, pushed and readied; prints the change ID.
129readied() {
130 as alice git push --quiet origin "$1"
131 ok as alice valley ready
132 id
133}
134# attested <branch> <check>: readied, with its evidence signed by the
135# contributor's key and pushed with it through the hook.
136attested() {
137 as alice attest run --repo . --key "$w/keys/contributor" --name "$contributor" \
138 --push origin --branch "$1" --check "$2" > "$w/out" 2> "$w/err" || fail "attest run on $1 failed"
139 ok as alice valley ready
140 id
141}
142# moves: main moves on, so a later landing is no fast-forward.
143moves() {
144 git checkout --quiet -B main origin/main
145 echo "$1" >> moved.txt
146 git add moved.txt
147 git commit --quiet -m "main moves on: $1"
148 git push --quiet origin main
149 git fetch --quiet origin
150}
151
152git fetch --quiet origin
153# quick lands by fast-forward. waiting is ready and never requested.
154git checkout --quiet -b quick origin/main
155echo "a quick note" > docs/quick.md
156git add docs/quick.md
157git commit --quiet -m 'a change that lands by fast-forward'
158quick="$(readied quick)"
159git push --quiet origin quick:main
160git fetch --quiet origin
161git checkout --quiet -b waiting origin/main
162echo "waiting" > docs/waiting.md
163git add docs/waiting.md
164git commit --quiet -m 'a change nobody approves'
165waiting="$(readied waiting)"
166# lands is landed by the integrator after main moves, so by a commit of
167# its own. above is a change on top of it.
168git checkout --quiet -b lands origin/main
169echo "a second source line" >> src/main.txt
170git commit --quiet -am 'a change the integrator lands'
171lands="$(attested lands code-build)"
172git checkout --quiet -b above lands
173echo "above" > src/above.txt
174git add src/above.txt
175git commit --quiet -m 'a change on top of lands'
176above="$(readied above)"
177moves one
178
179integrate() {
180 integrator reconcile --repo "$served" --key "$1" --known-signers "$signers" --instance "$w/floor" \
181 --schema "$SCHEMA_VERIFICATION" --attest-schema "$SCHEMA_ATTESTATION" --event-schema "$SCHEMA_EVENTS" \
182 > "$w/integrator.out" 2>&1 || fail "the integrator failed: $(cat "$w/integrator.out")"
183 grep -q "^c-$2 -> refs/heads/main .*: land\$" "$w/integrator.out" \
184 || fail "the integrator did not land c-$2: $(cat "$w/integrator.out")"
185}
186as requester git push --quiet origin "lands:refs/the-valley/integration-requests/main/c-$lands"
187integrate "$w/keys/integrator" "$lands"
188landed="$(git -C "$served" rev-parse main)"
189[ "$(git -C "$served" rev-parse main^)" = "$(git rev-parse origin/main)" ] \
190 || fail 'the integrator did not land lands by a commit on the moved main'
191
192# client: a fresh clone of the project, with a cache of its own, and
193# neither variable set. listing runs a command in it, with any variables
194# given first, into out and err.
195n=0
196client() {
197 n=$((n + 1))
198 c="$w/client-$n"
199 git clone --quiet "$served" "$c"
200 git -C "$c" config valley.principal alice
201 export XDG_CACHE_HOME="$w/cache-$n"
202}
203listing() { (cd "$c" && env "$@") > "$w/out" 2> "$w/err"; }
204changes() { listing "$@" valley changes --all --json || fail "valley changes failed"; }
205landing() {
206 jq -r --arg id "$1" '.repos[] | select(.repo == "served") | .changes[] | select(.change_id == $id) | .versions[-1].landing' "$w/out"
207}
208expect() {
209 local got
210 got="$(landing "$1")"
211 [ "$got" = "$2" ] || fail "$3: $1 reads $got, not $2"
212}
213# Every version's landing, one line each.
214landings() {
215 jq -r '.repos[] | .repo as $r | .changes[] | .change_id as $id | .versions[] | "\($r) \($id) v\(.n) \(.landing)"' "$w/out" | LC_ALL=C sort
216}
217said() { grep -qF -- "$1" "$w/err" || fail "stderr does not say: $1"; }
218quiet() { if grep -qF -- "$1" "$w/err"; then fail "stderr says: $1"; fi; }
219
220# ----------------------------------------------------------------------
221# With nothing published and nothing set, the landing reads uncertain and
222# the command says why. Every other landing reads as it always did.
223client
224changes
225expect "$lands" uncertain 'with nothing published and nothing set'
226expect "$quick" landed 'a fast-forward'
227expect "$waiting" not-landed 'a change nobody approved'
228said 'could not be verified'
229landings > "$w/unpublished"
230listing valley status --json "$lands" || fail 'valley status failed'
231[ "$(jq -r .landing "$w/out")" = uncertain ] || fail "status reads lands as $(jq -r .landing "$w/out")"
232stack() { cut -f4 "$w/out" | tr '\n' ' '; }
233listing valley stack "$above" || fail 'valley stack failed'
234[ "$(stack)" = "$(git rev-parse lands) $(git rev-parse above) " ] \
235 || fail "the stack under above is not lands and above: $(cat "$w/out")"
236# The variables still verify it, as they did before there was a
237# publication.
238changes VALLEY_KNOWN_SIGNERS="$signers" VALLEY_INTEGRATOR_SIGNER="$name"
239expect "$lands" landed-recorded 'with both variables set'
240
241# ----------------------------------------------------------------------
242# The publisher refuses a file that is not verifier keys, and publishes
243# nothing.
244echo 'not a verifier key' > "$w/garbage"
245if integrator publish-signers --instance-repo "$instance" --known-signers "$w/garbage" > "$w/out" 2> "$w/err"; then
246 fail 'the publisher published a file that is not verifier keys'
247fi
248said 'the known-signers file does not read'
249[ -z "$(git -C "$instance" for-each-ref refs/the-valley/signers)" ] || fail 'a refused run published something'
250
251# Written on disk, as the host's publisher writes it: one tree holding the
252# controller's signers file and the name it signs under, beside the
253# approval signers files, empty on a host that compiles no registry, and
254# the instance's identity. The clients below read it as they read a tree
255# of the first two alone.
256"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed'
257published="$(git -C "$instance" rev-parse refs/the-valley/signers)"
258[ "$(git -C "$instance" cat-file -t "$published")" = tree ] || fail 'the publication is not a tree'
259[ "$(git -C "$instance" ls-tree --name-only "$published" | tr '\n' ' ')" = "approval-signers approval-signers-hardware instance-id integrator-name known-signers " ] \
260 || fail "the publication holds $(git -C "$instance" ls-tree --name-only "$published")"
261[ "$(git -C "$instance" cat-file blob "$published:integrator-name")" = "$name" ] \
262 || fail 'the publication does not name the signer the controller signs under'
263git -C "$instance" cat-file blob "$published:known-signers" | cmp -s - "$signers" \
264 || fail "the publication does not hold the controller's signers file"
265"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed the second time'
266[ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$published" ] \
267 || fail 'publishing what is already published moved the ref'
268grep -q 'already publishes' "$w/out" || fail 'the publisher did not say nothing changed'
269
270# ----------------------------------------------------------------------
271# A fresh client with nothing set reads the landing as landed-recorded,
272# and says nothing about verifying. Every other landing reads as it did
273# with nothing published.
274client
275changes
276expect "$lands" landed-recorded 'on a fresh client with nothing set'
277quiet 'could not be verified'
278quiet 'no transfer statement is verified'
279landings | sed "s/^served $lands v1 landed-recorded\$/served $lands v1 uncertain/" > "$w/published"
280diff "$w/unpublished" "$w/published" > /dev/null \
281 || fail "the publication changed another landing: $(diff "$w/unpublished" "$w/published")"
282[ "$(jq -r --arg id "$lands" '.repos[] | .changes[] | select(.change_id == $id) | .versions[-1].landed_commit' "$w/out")" = "$landed" ] \
283 || fail 'the landing does not name the commit it landed as'
284listing valley status --json "$lands" || fail 'valley status failed'
285[ "$(jq -r .landing "$w/out")" = landed-recorded ] || fail "status reads lands as $(jq -r .landing "$w/out")"
286quiet 'could not be verified'
287# lands is no layer under above any more, and rebase drops its commits:
288# above's own commit goes onto main alone.
289listing valley stack "$above" || fail 'valley stack failed'
290[ "$(stack)" = "$(git rev-parse above) " ] \
291 || fail "the stack under above still holds more than above: $(cat "$w/out")"
292listing VALLEY_PRINCIPAL=alice valley rebase "$above" || fail 'valley rebase failed'
293[ "$(git -C "$served" rev-parse above^)" = "$landed" ] || fail 'above was not rebased onto the landing'
294[ "$(git -C "$served" diff --name-only main above)" = src/above.txt ] \
295 || fail "above carries more than its own commit: $(git -C "$served" diff --name-only main above)"
296
297# ----------------------------------------------------------------------
298# Overrides. A variable beats the publication: a file that reads, under a
299# name it holds a key for, is used, and verifies nothing here.
300attest key --key "$w/keys/rotated" --name other.valley.invalid/attestations > "$w/other-signers"
301other=(VALLEY_KNOWN_SIGNERS="$w/other-signers" VALLEY_INTEGRATOR_SIGNER=other.valley.invalid/attestations)
302changes "${other[@]}"
303expect "$lands" uncertain 'with both variables naming another signer'
304quiet 'no transfer statement is verified'
305# A flag beats a variable.
306listing "${other[@]}" valley changes --all --json --known-signers "$signers" --integrator-name "$name" \
307 || fail 'changes failed with the flags'
308expect "$lands" landed-recorded 'with the flags set over the variables'
309listing "${other[@]}" valley status --json --known-signers="$signers" --integrator-name="$name" "$lands" \
310 || fail 'status failed with the flags'
311[ "$(jq -r .landing "$w/out")" = landed-recorded ] || fail "status with the flags reads lands as $(jq -r .landing "$w/out")"
312# Each value comes from its own first source: a name from the variable,
313# with the published file, which holds no key under it, is reported.
314changes VALLEY_INTEGRATOR_SIGNER=other.valley.invalid/attestations
315expect "$lands" uncertain 'with the published file and another name'
316said "the known-signers file published at refs/the-valley/signers in $instance holds no key under the integrator name other.valley.invalid/attestations (from VALLEY_INTEGRATOR_SIGNER), so no transfer statement is verified"
317# An override that does not read is reported, and the publication is not
318# used in its place.
319changes VALLEY_KNOWN_SIGNERS="$w/missing"
320expect "$lands" uncertain 'with a variable naming no file'
321said "the known-signers file $w/missing (from VALLEY_KNOWN_SIGNERS) cannot be read"
322listing valley changes --all --json --known-signers "$w/garbage" || fail 'changes failed with a garbage file'
323expect "$lands" uncertain 'with a flag naming a file that is not verifier keys'
324said "the known-signers file $w/garbage (from --known-signers) does not read as verifier keys"
325if listing valley changes --all --json --integrator-name; then fail 'a flag with no value was taken'; fi
326said '--integrator-name needs a value'
327
328# ----------------------------------------------------------------------
329# No push replaces the publication or deletes it, forced or not, whatever
330# the pusher holds: requester holds the request and restack grants.
331cd "$c"
332for refspec in "+HEAD^{tree}:refs/the-valley/signers" "+HEAD:refs/the-valley/signers" ":refs/the-valley/signers"; do
333 if VALLEY_PRINCIPAL=requester git push "$instance" "$refspec" > "$w/out" 2> "$w/err"; then
334 fail "the push of $refspec was taken"
335 fi
336 said 'refs/the-valley/signers is written only by the machinery on the host, and no push may write it'
337 [ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$published" ] \
338 || fail "the push of $refspec moved the publication"
339done
340cd "$w/fixture"
341
342# ----------------------------------------------------------------------
343# A signer the signer projects file names is never this host's integrator.
344# The publisher refuses a list that names the name it publishes. A client
345# refuses one too, however it came to be published, and a published list
346# that does not read or is not a file: it verifies no transfer statement.
347# A list naming only a worker leaves the landing as it was. Each list is
348# written on disk beside the published signers, as no publisher writes it.
349printf '%s served\n' "$name" > "$w/restricts-the-integrator"
350if integrator publish-signers --instance-repo "$instance" --known-signers "$signers" \
351 --signer-projects "$w/restricts-the-integrator" > "$w/out" 2> "$w/err"; then
352 fail 'the publisher published a signer projects file that restricts the integrator name'
353fi
354said "names $name, the name the integrator signs under"
355[ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$published" ] || fail 'a refused run moved the publication'
356# with_list <file>: the publication, with the file beside the signers.
357with_list() {
358 local blob
359 blob="$(git -C "$instance" hash-object -w "$1")"
360 { git -C "$instance" ls-tree "$published" && printf '100644 blob %s\tsigner-projects\n' "$blob"; } \
361 | git -C "$instance" mktree > "$w/tree"
362 git -C "$instance" update-ref refs/the-valley/signers "$(cat "$w/tree")"
363}
364with_list "$w/restricts-the-integrator"
365client
366changes
367expect "$lands" uncertain 'with a published list that restricts the integrator name'
368said "is restricted to projects by the published signer-projects"
369printf 'worker.valley.invalid/attestations served\302\240instance\n' > "$w/unreadable-list"
370with_list "$w/unreadable-list"
371client
372changes
373expect "$lands" uncertain 'with a published list that does not read'
374said "signer-projects in refs/the-valley/signers in $instance does not read"
375# An entry that is a tree, not a file, would restrict nobody if it were
376# read as absent.
377{ git -C "$instance" ls-tree "$published" \
378 && printf '040000 tree %s\tsigner-projects\n' "$(git -C "$instance" mktree < /dev/null)"; } \
379 | git -C "$instance" mktree > "$w/tree"
380git -C "$instance" update-ref refs/the-valley/signers "$(cat "$w/tree")"
381client
382changes
383expect "$lands" uncertain 'with a published signer-projects that is a tree'
384said "signer-projects in refs/the-valley/signers in $instance is not a file"
385printf 'worker.valley.invalid/attestations served\n' > "$w/worker-list"
386with_list "$w/worker-list"
387client
388changes
389expect "$lands" landed-recorded 'with a published list that restricts only a worker'
390quiet 'could not be verified'
391git -C "$instance" update-ref refs/the-valley/signers "$published"
392
393# ----------------------------------------------------------------------
394# The integrator's key is rotated: the signers file now holds the new key
395# under the same name, and the next landing is signed with it. Until the
396# publisher runs again, a fresh client cannot verify that landing. After
397# it, the client reads it landed-recorded.
398cp "$signers" "$w/before-rotation"
399signers_for "$w/keys/rotated"
400git fetch --quiet origin
401git checkout --quiet -b second origin/main
402echo "a third source line" >> src/main.txt
403git commit --quiet -am 'a change landed after the rotation'
404second="$(attested second code-build)"
405moves two
406as requester git push --quiet origin "second:refs/the-valley/integration-requests/main/c-$second"
407integrate "$w/keys/rotated" "$second"
408client
409changes
410expect "$second" uncertain 'before the rotated signers are published'
411"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed after the rotation'
412rotated="$(git -C "$instance" rev-parse refs/the-valley/signers)"
413[ "$rotated" != "$published" ] || fail 'the rotated signers were not published'
414git -C "$instance" cat-file blob "$rotated:known-signers" | cmp -s - "$signers" \
415 || fail 'the publication does not hold the rotated signers file'
416client
417changes
418expect "$second" landed-recorded 'after the rotated signers are published'
419
420# ----------------------------------------------------------------------
421# Two runs at once take turns, so an older run cannot undo the rotation.
422# The older run reads the signers file as it was before the rotation. It
423# reads it from a FIFO, so it stops mid-read, holding the lock, until the
424# test writes the file and closes the FIFO. Once it has the FIFO open, the
425# path holds that file, which the run reads again after it publishes. The newer run, the host's,
426# reads the rotated file. It must wait for the older run's lock rather
427# than publish first, so it publishes last and the rotation stands.
428# Without the lock, the newer run would publish while the older one
429# reads, and the older one would then put the old keys back.
430#
431# flocked <pid> <holds|waits>: /proc/locks shows the process holding a
432# flock, or waiting for one.
433flocked() {
434 local arrow=''
435 if [ "$2" = waits ]; then arrow='-> '; fi
436 grep -Eq "^[0-9]+: ${arrow}FLOCK +ADVISORY +WRITE +$1 " /proc/locks
437}
438# running <pid>: the process has not ended.
439running() { [ -e "/proc/$1" ] && [ "$(sed 's/.*) //' "/proc/$1/stat" | cut -d' ' -f1)" != Z ]; }
440# until_flocked <pid> <holds|waits> <what>: waits a minute at most for
441# flocked to say so, and fails if the process ends first.
442until_flocked() {
443 for _ in $(seq 600); do
444 if flocked "$1" "$2"; then return 0; fi
445 running "$1" || fail "$3"
446 sleep 0.1
447 done
448 fail "$3, after a minute"
449}
450mkfifo "$w/stale"
451integrator publish-signers --instance-repo "$instance" --known-signers "$w/stale" > "$w/older.out" 2>&1 &
452older=$!
453until_flocked "$older" holds "the older run held no lock while it read the signers file: $(cat "$w/older.out")"
454# This returns once the older run has opened the FIFO to read it. The
455# newer run is not given the FIFO, which would keep the older run's read
456# from ending.
457exec 3> "$w/stale"
458rm "$w/stale" && cp "$w/before-rotation" "$w/stale"
459"${publish[@]}" > "$w/newer.out" 2>&1 3>&- &
460newer=$!
461until_flocked "$newer" waits "the newer run did not wait for the older run: $(cat "$w/newer.out")"
462cat "$w/before-rotation" >&3
463exec 3>&-
464wait "$older" || fail "the older run failed: $(cat "$w/older.out")"
465wait "$newer" || fail "the newer run failed: $(cat "$w/newer.out")"
466grep -q 'now publishes' "$w/newer.out" || fail "the newer run did not publish after the older run: $(cat "$w/newer.out")"
467git -C "$instance" cat-file blob refs/the-valley/signers:known-signers | cmp -s - "$signers" \
468 || fail 'an older run put back the signers the rotation replaced'
469client
470changes
471expect "$second" landed-recorded 'after two runs at once'
472
473# ----------------------------------------------------------------------
474# Every signing key is revoked. The registry in the instance repository
475# keeps the integrator's key but no longer lets it sign, and nobody else
476# signs either, so the compiler renders a known-signers file with no key
477# in it. The host publishes that file all the same. A fresh clone, with
478# the cache the last client filled as it verified the landing signed
479# with the rotated key, then verifies no transfer statement, so both
480# landings proved only by one read uncertain, not landed-recorded.
481public() { cut -d' ' -f1,2 < "$keys/$1.pub"; }
482mkdir -p "$w/seed/identity"
483cat > "$w/seed/identity/registry.cue" << CUE
484package identity
485
486boundaries: "registry": kind: "registry"
487genesis: "operator"
488principals: {
489 "operator": {
490 kind: "human"
491 keys: [{class: "ssh-ed25519", bound: "host", public: "$(public contributor)"}]
492 grants: govern: boundary: "registry"
493 }
494 "integrator": {
495 kind: "service"
496 keys: [{class: "ssh-ed25519", bound: "host", public: "$(public rotated)"}]
497 expires: "2099-01-01"
498 }
499}
500CUE
501git -C "$w/seed" add -A
502git -C "$w/seed" commit --quiet -m 'revoke every signing key'
503git -C "$w/seed" push --quiet "$instance" main
504identity compile --repo "$instance" --known-signers "$signers" --authorized-keys "$w/authorized_keys" \
505 --grants "$w/grants" --now 2026-10-21 > "$w/out" 2> "$w/err" || fail 'the registry did not compile'
506if grep -v '^#' "$signers" > "$w/out"; then fail 'the compiled signers file still holds a key'; fi
507"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher refused a signers file with no key'
508said "holds no key under $name"
509revoked="$(git -C "$instance" rev-parse refs/the-valley/signers)"
510[ "$revoked" != "$rotated" ] || fail 'the signers file with no key was not published'
511git -C "$instance" cat-file blob "$revoked:known-signers" | cmp -s - "$signers" \
512 || fail 'the publication does not hold the signers file with no key'
513warm="$XDG_CACHE_HOME"
514client
515export XDG_CACHE_HOME="$warm"
516changes
517expect "$second" uncertain 'after every signing key is revoked'
518expect "$lands" uncertain 'after every signing key is revoked'
519expect "$quick" landed 'a fast-forward, after every signing key is revoked'
520said "holds no key under the integrator name $name"
521
522# ----------------------------------------------------------------------
523# A host that restricts a worker's signer to projects gives its publisher
524# the signer projects file it gives the controllers, and the publication
525# carries it beside the signers. The file is in the publisher's command, so
526# a changed list is a changed unit, which an activation runs again. Here
527# each host's command runs as an activation would run it.
528# publish_as <command>: the rendered publisher, pointed at this test's
529# instance repository and signers file.
530publish_as() {
531 local -a cmd
532 read -ra cmd <<< "$1"
533 cmd=("${cmd[@]//\/srv\/git\/sealed.git/$instance}")
534 cmd=("${cmd[@]//\/var\/lib\/valley-instance\/known_signers/$signers}")
535 "${cmd[@]}" > "$w/out" 2> "$w/err" || fail "the publisher failed: $1"
536}
537# list_of <command>: the signer projects file the command is given.
538list_of() { grep -o -- '--signer-projects [^ ]*' <<< "$1" | cut -d' ' -f2; }
539names() { git -C "$instance" ls-tree --name-only "$1" | tr '\n' ' '; }
540
541restricted_list="$(list_of "$restrictedPublishCommand")"
542[ -n "$restricted_list" ] || fail "the restricting host's publisher is given no signer projects file: $restrictedPublishCommand"
543[ "$(cat "$restricted_list")" = "$(printf '%s\n' 'retired.valley.invalid/attestations' 'worker.valley.invalid/attestations guarded sealed')" ] \
544 || fail "the rendered signer projects file holds: $(cat "$restricted_list")"
545publish_as "$restrictedPublishCommand"
546listed="$(git -C "$instance" rev-parse refs/the-valley/signers)"
547[ "$(names "$listed")" = "approval-signers approval-signers-hardware instance-id integrator-name known-signers signer-projects " ] \
548 || fail "the publication of a restricting host holds $(names "$listed")"
549git -C "$instance" cat-file blob "$listed:signer-projects" | cmp -s - "$restricted_list" \
550 || fail 'the publication does not hold the signer projects file the controllers read'
551git -C "$instance" cat-file blob "$listed:known-signers" | cmp -s - "$signers" \
552 || fail 'the signers file changed with the list'
553
554changed_list="$(list_of "$changedPublishCommand")"
555[ -n "$changed_list" ] && [ "$changed_list" != "$restricted_list" ] \
556 || fail 'a changed list renders the same publisher command, so no activation would run it again'
557publish_as "$changedPublishCommand"
558changed="$(git -C "$instance" rev-parse refs/the-valley/signers)"
559[ "$changed" != "$listed" ] || fail 'the changed list was not published'
560git -C "$instance" cat-file blob "$changed:signer-projects" | cmp -s - "$changed_list" \
561 || fail 'the publication does not hold the changed list'
562
563# A list that does not read publishes nothing, and the last publication
564# stands.
565printf '%s\n' 'worker.valley.invalid/attestations sealed' 'worker.valley.invalid/attestations guarded' > "$w/named-twice"
566if integrator publish-signers --instance-repo "$instance" --known-signers "$signers" \
567 --signer-projects "$w/named-twice" > "$w/out" 2> "$w/err"; then
568 fail 'the publisher published a signer projects file that names a signer twice'
569fi
570said "the signer projects file $w/named-twice does not read"
571[ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$changed" ] || fail 'a refused run moved the publication'
572
573# A host that restricts nobody publishes no list.
574"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed once the list was gone'
575[ "$(names refs/the-valley/signers)" = "approval-signers approval-signers-hardware instance-id integrator-name known-signers " ] \
576 || fail "the list outlived the restriction: the publication holds $(names refs/the-valley/signers)"
577
578touch "$out"