gunk-dev/the-valley

signers-e2e.sh

sourcef5c9a830d01emain's published tip history
27.2 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-go stack "$above" || fail 'valley-go 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.
253"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed'
254published="$(git -C "$instance" rev-parse refs/the-valley/signers)"
255[ "$(git -C "$instance" cat-file -t "$published")" = tree ] || fail 'the publication is not a tree'
256[ "$(git -C "$instance" ls-tree --name-only "$published" | tr '\n' ' ')" = "integrator-name known-signers " ] \
257 || fail "the publication holds $(git -C "$instance" ls-tree --name-only "$published")"
258[ "$(git -C "$instance" cat-file blob "$published:integrator-name")" = "$name" ] \
259 || fail 'the publication does not name the signer the controller signs under'
260git -C "$instance" cat-file blob "$published:known-signers" | cmp -s - "$signers" \
261 || fail "the publication does not hold the controller's signers file"
262"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed the second time'
263[ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$published" ] \
264 || fail 'publishing what is already published moved the ref'
265grep -q 'already publishes' "$w/out" || fail 'the publisher did not say nothing changed'
266
267# ----------------------------------------------------------------------
268# A fresh client with nothing set reads the landing as landed-recorded,
269# and says nothing about verifying. Every other landing reads as it did
270# with nothing published.
271client
272changes
273expect "$lands" landed-recorded 'on a fresh client with nothing set'
274quiet 'could not be verified'
275quiet 'no transfer statement is verified'
276landings | sed "s/^served $lands v1 landed-recorded\$/served $lands v1 uncertain/" > "$w/published"
277diff "$w/unpublished" "$w/published" > /dev/null \
278 || fail "the publication changed another landing: $(diff "$w/unpublished" "$w/published")"
279[ "$(jq -r --arg id "$lands" '.repos[] | .changes[] | select(.change_id == $id) | .versions[-1].landed_commit' "$w/out")" = "$landed" ] \
280 || fail 'the landing does not name the commit it landed as'
281listing valley status --json "$lands" || fail 'valley status failed'
282[ "$(jq -r .landing "$w/out")" = landed-recorded ] || fail "status reads lands as $(jq -r .landing "$w/out")"
283quiet 'could not be verified'
284# lands is no layer under above any more, and rebase drops its commits:
285# above's own commit goes onto main alone.
286listing valley-go stack "$above" || fail 'valley-go stack failed'
287[ "$(stack)" = "$(git rev-parse above) " ] \
288 || fail "the stack under above still holds more than above: $(cat "$w/out")"
289listing VALLEY_PRINCIPAL=alice valley rebase "$above" || fail 'valley rebase failed'
290[ "$(git -C "$served" rev-parse above^)" = "$landed" ] || fail 'above was not rebased onto the landing'
291[ "$(git -C "$served" diff --name-only main above)" = src/above.txt ] \
292 || fail "above carries more than its own commit: $(git -C "$served" diff --name-only main above)"
293
294# ----------------------------------------------------------------------
295# Overrides. A variable beats the publication: a file that reads, under a
296# name it holds a key for, is used, and verifies nothing here.
297attest key --key "$w/keys/rotated" --name other.valley.invalid/attestations > "$w/other-signers"
298other=(VALLEY_KNOWN_SIGNERS="$w/other-signers" VALLEY_INTEGRATOR_SIGNER=other.valley.invalid/attestations)
299changes "${other[@]}"
300expect "$lands" uncertain 'with both variables naming another signer'
301quiet 'no transfer statement is verified'
302# A flag beats a variable.
303listing "${other[@]}" valley changes --all --json --known-signers "$signers" --integrator-name "$name" \
304 || fail 'changes failed with the flags'
305expect "$lands" landed-recorded 'with the flags set over the variables'
306listing "${other[@]}" valley status --json --known-signers="$signers" --integrator-name="$name" "$lands" \
307 || fail 'status failed with the flags'
308[ "$(jq -r .landing "$w/out")" = landed-recorded ] || fail "status with the flags reads lands as $(jq -r .landing "$w/out")"
309# Each value comes from its own first source: a name from the variable,
310# with the published file, which holds no key under it, is reported.
311changes VALLEY_INTEGRATOR_SIGNER=other.valley.invalid/attestations
312expect "$lands" uncertain 'with the published file and another name'
313said "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"
314# An override that does not read is reported, and the publication is not
315# used in its place.
316changes VALLEY_KNOWN_SIGNERS="$w/missing"
317expect "$lands" uncertain 'with a variable naming no file'
318said "the known-signers file $w/missing (from VALLEY_KNOWN_SIGNERS) cannot be read"
319listing valley changes --all --json --known-signers "$w/garbage" || fail 'changes failed with a garbage file'
320expect "$lands" uncertain 'with a flag naming a file that is not verifier keys'
321said "the known-signers file $w/garbage (from --known-signers) does not read as verifier keys"
322if listing valley changes --all --json --integrator-name; then fail 'a flag with no value was taken'; fi
323said '--integrator-name needs a value'
324
325# ----------------------------------------------------------------------
326# No push replaces the publication or deletes it, forced or not, whatever
327# the pusher holds: requester holds the request and restack grants.
328cd "$c"
329for refspec in "+HEAD^{tree}:refs/the-valley/signers" "+HEAD:refs/the-valley/signers" ":refs/the-valley/signers"; do
330 if VALLEY_PRINCIPAL=requester git push "$instance" "$refspec" > "$w/out" 2> "$w/err"; then
331 fail "the push of $refspec was taken"
332 fi
333 said 'refs/the-valley/signers is written only by the machinery on the host, and no push may write it'
334 [ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$published" ] \
335 || fail "the push of $refspec moved the publication"
336done
337cd "$w/fixture"
338
339# ----------------------------------------------------------------------
340# A signer the signer projects file names is never this host's integrator.
341# The publisher refuses a list that names the name it publishes. A client
342# refuses one too, however it came to be published, and a published list
343# that does not read or is not a file: it verifies no transfer statement.
344# A list naming only a worker leaves the landing as it was. Each list is
345# written on disk beside the published signers, as no publisher writes it.
346printf '%s served\n' "$name" > "$w/restricts-the-integrator"
347if integrator publish-signers --instance-repo "$instance" --known-signers "$signers" \
348 --signer-projects "$w/restricts-the-integrator" > "$w/out" 2> "$w/err"; then
349 fail 'the publisher published a signer projects file that restricts the integrator name'
350fi
351said "names $name, the name the integrator signs under"
352[ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$published" ] || fail 'a refused run moved the publication'
353# with_list <file>: the publication, with the file beside the signers.
354with_list() {
355 local blob
356 blob="$(git -C "$instance" hash-object -w "$1")"
357 { git -C "$instance" ls-tree "$published" && printf '100644 blob %s\tsigner-projects\n' "$blob"; } \
358 | git -C "$instance" mktree > "$w/tree"
359 git -C "$instance" update-ref refs/the-valley/signers "$(cat "$w/tree")"
360}
361with_list "$w/restricts-the-integrator"
362client
363changes
364expect "$lands" uncertain 'with a published list that restricts the integrator name'
365said "is restricted to projects by the published signer-projects"
366printf 'worker.valley.invalid/attestations served\302\240instance\n' > "$w/unreadable-list"
367with_list "$w/unreadable-list"
368client
369changes
370expect "$lands" uncertain 'with a published list that does not read'
371said "signer-projects in refs/the-valley/signers in $instance does not read"
372# An entry that is a tree, not a file, would restrict nobody if it were
373# read as absent.
374{ git -C "$instance" ls-tree "$published" \
375 && printf '040000 tree %s\tsigner-projects\n' "$(git -C "$instance" mktree < /dev/null)"; } \
376 | git -C "$instance" mktree > "$w/tree"
377git -C "$instance" update-ref refs/the-valley/signers "$(cat "$w/tree")"
378client
379changes
380expect "$lands" uncertain 'with a published signer-projects that is a tree'
381said "signer-projects in refs/the-valley/signers in $instance is not a file"
382printf 'worker.valley.invalid/attestations served\n' > "$w/worker-list"
383with_list "$w/worker-list"
384client
385changes
386expect "$lands" landed-recorded 'with a published list that restricts only a worker'
387quiet 'could not be verified'
388git -C "$instance" update-ref refs/the-valley/signers "$published"
389
390# ----------------------------------------------------------------------
391# The integrator's key is rotated: the signers file now holds the new key
392# under the same name, and the next landing is signed with it. Until the
393# publisher runs again, a fresh client cannot verify that landing. After
394# it, the client reads it landed-recorded.
395cp "$signers" "$w/before-rotation"
396signers_for "$w/keys/rotated"
397git fetch --quiet origin
398git checkout --quiet -b second origin/main
399echo "a third source line" >> src/main.txt
400git commit --quiet -am 'a change landed after the rotation'
401second="$(attested second code-build)"
402moves two
403as requester git push --quiet origin "second:refs/the-valley/integration-requests/main/c-$second"
404integrate "$w/keys/rotated" "$second"
405client
406changes
407expect "$second" uncertain 'before the rotated signers are published'
408"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed after the rotation'
409rotated="$(git -C "$instance" rev-parse refs/the-valley/signers)"
410[ "$rotated" != "$published" ] || fail 'the rotated signers were not published'
411git -C "$instance" cat-file blob "$rotated:known-signers" | cmp -s - "$signers" \
412 || fail 'the publication does not hold the rotated signers file'
413client
414changes
415expect "$second" landed-recorded 'after the rotated signers are published'
416
417# ----------------------------------------------------------------------
418# Two runs at once take turns, so an older run cannot undo the rotation.
419# The older run reads the signers file as it was before the rotation. It
420# reads it from a FIFO, so it stops mid-read, holding the lock, until the
421# test writes the file and closes the FIFO. The newer run, the host's,
422# reads the rotated file. It must wait for the older run's lock rather
423# than publish first, so it publishes last and the rotation stands.
424# Without the lock, the newer run would publish while the older one
425# reads, and the older one would then put the old keys back.
426#
427# flocked <pid> <holds|waits>: /proc/locks shows the process holding a
428# flock, or waiting for one.
429flocked() {
430 local arrow=''
431 if [ "$2" = waits ]; then arrow='-> '; fi
432 grep -Eq "^[0-9]+: ${arrow}FLOCK +ADVISORY +WRITE +$1 " /proc/locks
433}
434# running <pid>: the process has not ended.
435running() { [ -e "/proc/$1" ] && [ "$(sed 's/.*) //' "/proc/$1/stat" | cut -d' ' -f1)" != Z ]; }
436# until_flocked <pid> <holds|waits> <what>: waits a minute at most for
437# flocked to say so, and fails if the process ends first.
438until_flocked() {
439 for _ in $(seq 600); do
440 if flocked "$1" "$2"; then return 0; fi
441 running "$1" || fail "$3"
442 sleep 0.1
443 done
444 fail "$3, after a minute"
445}
446mkfifo "$w/stale"
447integrator publish-signers --instance-repo "$instance" --known-signers "$w/stale" > "$w/older.out" 2>&1 &
448older=$!
449until_flocked "$older" holds "the older run held no lock while it read the signers file: $(cat "$w/older.out")"
450# This returns once the older run has opened the FIFO to read it. The
451# newer run is not given the FIFO, which would keep the older run's read
452# from ending.
453exec 3> "$w/stale"
454"${publish[@]}" > "$w/newer.out" 2>&1 3>&- &
455newer=$!
456until_flocked "$newer" waits "the newer run did not wait for the older run: $(cat "$w/newer.out")"
457cat "$w/before-rotation" >&3
458exec 3>&-
459wait "$older" || fail "the older run failed: $(cat "$w/older.out")"
460wait "$newer" || fail "the newer run failed: $(cat "$w/newer.out")"
461grep -q 'now publishes' "$w/newer.out" || fail "the newer run did not publish after the older run: $(cat "$w/newer.out")"
462git -C "$instance" cat-file blob refs/the-valley/signers:known-signers | cmp -s - "$signers" \
463 || fail 'an older run put back the signers the rotation replaced'
464client
465changes
466expect "$second" landed-recorded 'after two runs at once'
467
468# ----------------------------------------------------------------------
469# Every signing key is revoked. The registry in the instance repository
470# keeps the integrator's key but no longer lets it sign, and nobody else
471# signs either, so the compiler renders a known-signers file with no key
472# in it. The host publishes that file all the same. A fresh client then
473# verifies no transfer statement, so both landings proved only by one
474# read uncertain, not landed-recorded.
475public() { cut -d' ' -f1,2 < "$keys/$1.pub"; }
476mkdir -p "$w/seed/identity"
477cat > "$w/seed/identity/registry.cue" << CUE
478package identity
479
480boundaries: "registry": kind: "registry"
481genesis: "operator"
482principals: {
483 "operator": {
484 kind: "human"
485 keys: [{class: "ssh-ed25519", bound: "host", public: "$(public contributor)"}]
486 grants: govern: boundary: "registry"
487 }
488 "integrator": {
489 kind: "service"
490 keys: [{class: "ssh-ed25519", bound: "host", public: "$(public rotated)"}]
491 expires: "2099-01-01"
492 }
493}
494CUE
495git -C "$w/seed" add -A
496git -C "$w/seed" commit --quiet -m 'revoke every signing key'
497git -C "$w/seed" push --quiet "$instance" main
498identity compile --repo "$instance" --known-signers "$signers" --authorized-keys "$w/authorized_keys" \
499 --grants "$w/grants" --now 2026-10-21 > "$w/out" 2> "$w/err" || fail 'the registry did not compile'
500if grep -v '^#' "$signers" > "$w/out"; then fail 'the compiled signers file still holds a key'; fi
501"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher refused a signers file with no key'
502said "holds no key under $name"
503revoked="$(git -C "$instance" rev-parse refs/the-valley/signers)"
504[ "$revoked" != "$rotated" ] || fail 'the signers file with no key was not published'
505git -C "$instance" cat-file blob "$revoked:known-signers" | cmp -s - "$signers" \
506 || fail 'the publication does not hold the signers file with no key'
507client
508changes
509expect "$second" uncertain 'after every signing key is revoked'
510expect "$lands" uncertain 'after every signing key is revoked'
511expect "$quick" landed 'a fast-forward, after every signing key is revoked'
512said "holds no key under the integrator name $name"
513
514# ----------------------------------------------------------------------
515# A host that restricts a worker's signer to projects gives its publisher
516# the signer projects file it gives the controllers, and the publication
517# carries it beside the signers. The file is in the publisher's command, so
518# a changed list is a changed unit, which an activation runs again. Here
519# each host's command runs as an activation would run it.
520# publish_as <command>: the rendered publisher, pointed at this test's
521# instance repository and signers file.
522publish_as() {
523 local -a cmd
524 read -ra cmd <<< "$1"
525 cmd=("${cmd[@]//\/srv\/git\/sealed.git/$instance}")
526 cmd=("${cmd[@]//\/var\/lib\/valley-instance\/known_signers/$signers}")
527 "${cmd[@]}" > "$w/out" 2> "$w/err" || fail "the publisher failed: $1"
528}
529# list_of <command>: the signer projects file the command is given.
530list_of() { grep -o -- '--signer-projects [^ ]*' <<< "$1" | cut -d' ' -f2; }
531names() { git -C "$instance" ls-tree --name-only "$1" | tr '\n' ' '; }
532
533restricted_list="$(list_of "$restrictedPublishCommand")"
534[ -n "$restricted_list" ] || fail "the restricting host's publisher is given no signer projects file: $restrictedPublishCommand"
535[ "$(cat "$restricted_list")" = "$(printf '%s\n' 'retired.valley.invalid/attestations' 'worker.valley.invalid/attestations guarded sealed')" ] \
536 || fail "the rendered signer projects file holds: $(cat "$restricted_list")"
537publish_as "$restrictedPublishCommand"
538listed="$(git -C "$instance" rev-parse refs/the-valley/signers)"
539[ "$(names "$listed")" = "integrator-name known-signers signer-projects " ] \
540 || fail "the publication of a restricting host holds $(names "$listed")"
541git -C "$instance" cat-file blob "$listed:signer-projects" | cmp -s - "$restricted_list" \
542 || fail 'the publication does not hold the signer projects file the controllers read'
543git -C "$instance" cat-file blob "$listed:known-signers" | cmp -s - "$signers" \
544 || fail 'the signers file changed with the list'
545
546changed_list="$(list_of "$changedPublishCommand")"
547[ -n "$changed_list" ] && [ "$changed_list" != "$restricted_list" ] \
548 || fail 'a changed list renders the same publisher command, so no activation would run it again'
549publish_as "$changedPublishCommand"
550changed="$(git -C "$instance" rev-parse refs/the-valley/signers)"
551[ "$changed" != "$listed" ] || fail 'the changed list was not published'
552git -C "$instance" cat-file blob "$changed:signer-projects" | cmp -s - "$changed_list" \
553 || fail 'the publication does not hold the changed list'
554
555# A list that does not read publishes nothing, and the last publication
556# stands.
557printf '%s\n' 'worker.valley.invalid/attestations sealed' 'worker.valley.invalid/attestations guarded' > "$w/named-twice"
558if integrator publish-signers --instance-repo "$instance" --known-signers "$signers" \
559 --signer-projects "$w/named-twice" > "$w/out" 2> "$w/err"; then
560 fail 'the publisher published a signer projects file that names a signer twice'
561fi
562said "the signer projects file $w/named-twice does not read"
563[ "$(git -C "$instance" rev-parse refs/the-valley/signers)" = "$changed" ] || fail 'a refused run moved the publication'
564
565# A host that restricts nobody publishes no list.
566"${publish[@]}" > "$w/out" 2> "$w/err" || fail 'the publisher failed once the list was gone'
567[ "$(names refs/the-valley/signers)" = "integrator-name known-signers " ] \
568 || fail "the list outlived the restriction: the publication holds $(names refs/the-valley/signers)"
569
570touch "$out"