| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | export HOME="$TMPDIR" |
| 5 | export GIT_CONFIG_NOSYSTEM=1 |
| 6 | git config --global user.name valley-check |
| 7 | git config --global user.email valley-check@localhost |
| 8 | git config --global init.defaultBranch main |
| 9 | cd "$TMPDIR" || exit 1 |
| 10 | |
| 11 | # A bare instance repository, holding one registry at its tip โ what a host |
| 12 | # serves and what the compiler reads. |
| 13 | serve() { |
| 14 | local name="$1" source="$2" |
| 15 | rm -rf work "$name.git" |
| 16 | git init --quiet --bare "$name.git" |
| 17 | git init --quiet work |
| 18 | mkdir -p work/identity |
| 19 | cp "$source"/*.cue work/identity/ |
| 20 | chmod u+w work/identity/*.cue |
| 21 | git -C work add -A |
| 22 | git -C work commit --quiet -m "$name" |
| 23 | git -C work push --quiet "$TMPDIR/$name.git" main |
| 24 | } |
| 25 | |
| 26 | compile() { |
| 27 | identity compile --repo "$TMPDIR/instance.git" \ |
| 28 | --known-signers "$TMPDIR/signers" --authorized-keys "$TMPDIR/keys" "$@" |
| 29 | } |
| 30 | |
| 31 | # The worked registry compiles to exactly the artifacts checked in beside |
| 32 | # it. This is the whole claim of the compiler, and the artifacts it replaces |
| 33 | # were written by hand โ so the comparison is byte for byte. |
| 34 | serve instance "$registry" |
| 35 | compile --now 2026-08-09 2> first.log || exit 1 |
| 36 | diff -u "$compiled/known-signers" "$TMPDIR/signers" || exit 1 |
| 37 | diff -u "$compiled/authorized_keys" "$TMPDIR/keys" || exit 1 |
| 38 | |
| 39 | # Level-triggered: compiling again converges on the same bytes and touches |
| 40 | # nothing. |
| 41 | compile --now 2026-08-09 2> second.log || exit 1 |
| 42 | if ! grep -q "unchanged" second.log; then |
| 43 | echo "identity-e2e: a second compilation of an unchanged registry rewrote its artifacts" >&2 |
| 44 | cat second.log >&2 |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # The registry is read from the integrated tip and from nowhere else, which |
| 49 | # is the whole of the forcing: an edit on a branch governs nothing. |
| 50 | git -C work checkout --quiet -b topic |
| 51 | cp "$expired"/*.cue work/identity/registry.cue |
| 52 | git -C work commit --quiet -am topic |
| 53 | git -C work push --quiet "$TMPDIR/instance.git" topic |
| 54 | compile --now 2026-08-09 || exit 1 |
| 55 | diff -u "$compiled/known-signers" "$TMPDIR/signers" || exit 1 |
| 56 | |
| 57 | # The compiled verifier line is the one attest writes. The published keys |
| 58 | # above pin the format against a fixed vector; this pins it against the |
| 59 | # implementation that reads it, over a key generated here. |
| 60 | ssh-keygen -q -t ed25519 -N "" -C valley-check -f "$TMPDIR/scratch" |
| 61 | mkdir -p scratch-registry |
| 62 | { |
| 63 | echo 'package identity' |
| 64 | echo 'boundaries: "registry": kind: "registry"' |
| 65 | echo 'genesis: "someone"' |
| 66 | echo 'principals: "someone": {' |
| 67 | echo ' kind: "human"' |
| 68 | echo ' keys: [{' |
| 69 | echo ' class: "ssh-ed25519"' |
| 70 | echo ' bound: "hardware"' |
| 71 | printf '\t\tpublic: "%s"\n' "$(cut -d' ' -f1,2 < "$TMPDIR/scratch.pub")" |
| 72 | echo ' signs: "someone/attestations"' |
| 73 | echo ' }]' |
| 74 | echo ' grants: govern: boundary: "registry"' |
| 75 | echo '}' |
| 76 | } > scratch-registry/registry.cue |
| 77 | serve instance scratch-registry |
| 78 | compile --now 2026-08-09 || exit 1 |
| 79 | attest key --key "$TMPDIR/scratch" --name "someone/attestations" > expected-line |
| 80 | if ! grep -qxFf expected-line "$TMPDIR/signers"; then |
| 81 | echo "identity-e2e: the compiled verifier key is not the line attest writes" >&2 |
| 82 | cat expected-line "$TMPDIR/signers" >&2 |
| 83 | exit 1 |
| 84 | fi |
| 85 | |
| 86 | # An entry past its expiry leaves both artifacts, says so, and costs the |
| 87 | # rest of the registry nothing. The day before, it is still there โ the |
| 88 | # declared day is the first day the entry no longer counts. |
| 89 | serve instance "$expired" |
| 90 | compile --now 2026-09-30 || exit 1 |
| 91 | grep -q "stoned-flynn/attestations" "$TMPDIR/signers" || { |
| 92 | echo "identity-e2e: an unexpired entry was omitted" >&2 |
| 93 | exit 1 |
| 94 | } |
| 95 | compile --now 2026-11-01 2> expired.log || exit 1 |
| 96 | if grep -q "stoned-flynn" "$TMPDIR/signers" "$TMPDIR/keys"; then |
| 97 | echo "identity-e2e: an expired entry stayed in the compiled artifacts" >&2 |
| 98 | cat "$TMPDIR/signers" "$TMPDIR/keys" >&2 |
| 99 | exit 1 |
| 100 | fi |
| 101 | if ! grep -q "stoned-flynn expired 2026-10-01" expired.log; then |
| 102 | echo "identity-e2e: an expired entry was dropped without saying so" >&2 |
| 103 | cat expired.log >&2 |
| 104 | exit 1 |
| 105 | fi |
| 106 | grep -q "patrick" "$TMPDIR/keys" || { |
| 107 | echo "identity-e2e: one expired entry took the rest of the registry with it" >&2 |
| 108 | exit 1 |
| 109 | } |
| 110 | |
| 111 | # The fail-safe. An invalid registry must cost the compilation and nothing |
| 112 | # else: the last good artifacts are what the gates keep reading, because a |
| 113 | # compiler bug that emptied them would lock the git user out of the host. |
| 114 | cp "$TMPDIR/signers" last-good-signers |
| 115 | cp "$TMPDIR/keys" last-good-keys |
| 116 | mkdir -p invalid-registry |
| 117 | cp "$invalid" invalid-registry/registry.cue |
| 118 | serve instance invalid-registry |
| 119 | if compile --now 2026-08-09 2> refused.log; then |
| 120 | echo "identity-e2e: an invalid registry compiled" >&2 |
| 121 | exit 1 |
| 122 | fi |
| 123 | if ! grep -q "externalGovernance" refused.log; then |
| 124 | echo "identity-e2e: the refusal did not name the field that failed" >&2 |
| 125 | cat refused.log >&2 |
| 126 | exit 1 |
| 127 | fi |
| 128 | diff -u last-good-signers "$TMPDIR/signers" || exit 1 |
| 129 | diff -u last-good-keys "$TMPDIR/keys" || exit 1 |
| 130 | |
| 131 | touch "$out" |