| 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 | # Governance the clock orphans. This registry is valid as a document — the |
| 132 | # genesis entry governs — and the only entry governing carries an expiry, so |
| 133 | # whether it compiles depends on the day. The schema cannot see this; the |
| 134 | # compiler can, and refuses the whole render rather than write artifacts |
| 135 | # nobody could ever change again. |
| 136 | mkdir -p orphan-registry |
| 137 | { |
| 138 | echo 'package identity' |
| 139 | echo 'boundaries: {' |
| 140 | echo ' "push": kind: "git-push"' |
| 141 | echo ' "registry": kind: "registry"' |
| 142 | echo '}' |
| 143 | echo 'genesis: "founder"' |
| 144 | echo 'principals: {' |
| 145 | echo ' "founder": {' |
| 146 | echo ' kind: "human"' |
| 147 | echo ' keys: [{' |
| 148 | echo ' class: "ssh-ed25519"' |
| 149 | echo ' bound: "hardware"' |
| 150 | echo ' public: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGCxVUxXoyFYV40QureqqSMSA17CvK9IrFB33BA6UOip"' |
| 151 | echo ' signs: "founder"' |
| 152 | echo ' }]' |
| 153 | echo ' grants: {' |
| 154 | echo ' push: boundary: "push"' |
| 155 | echo ' govern: boundary: "registry"' |
| 156 | echo ' }' |
| 157 | echo ' expires: "2026-10-01"' |
| 158 | echo ' }' |
| 159 | echo ' "runner": {' |
| 160 | echo ' kind: "machine"' |
| 161 | echo ' keys: [{' |
| 162 | echo ' class: "ssh-ed25519"' |
| 163 | echo ' bound: "host"' |
| 164 | echo ' public: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAvpmbUKEDVsejgv2vxWaY/t4xl0JNnjFswb9SxcG9GG"' |
| 165 | echo ' }]' |
| 166 | echo ' grants: push: boundary: "push"' |
| 167 | echo ' expires: "2027-01-01"' |
| 168 | echo ' }' |
| 169 | echo '}' |
| 170 | } > orphan-registry/registry.cue |
| 171 | |
| 172 | # The day before: an ordinary compilation. |
| 173 | serve instance orphan-registry |
| 174 | compile --now 2026-09-30 || exit 1 |
| 175 | grep -q "founder" "$TMPDIR/signers" || { |
| 176 | echo "identity-e2e: the governing entry was omitted while still unexpired" >&2 |
| 177 | exit 1 |
| 178 | } |
| 179 | cp "$TMPDIR/signers" last-good-signers |
| 180 | cp "$TMPDIR/keys" last-good-keys |
| 181 | |
| 182 | # The day it expires, and a day well past it: the same document, refused. The |
| 183 | # entry still pushing does not save it — a grant at another boundary is not |
| 184 | # governance. |
| 185 | for pinned in 2026-10-01 2026-12-01; do |
| 186 | if compile --now "$pinned" 2> orphaned.log; then |
| 187 | echo "identity-e2e: a registry nobody governs on $pinned compiled" >&2 |
| 188 | exit 1 |
| 189 | fi |
| 190 | if ! grep -q "governanceOrphaned" orphaned.log; then |
| 191 | echo "identity-e2e: the refusal on $pinned did not name governanceOrphaned" >&2 |
| 192 | cat orphaned.log >&2 |
| 193 | exit 1 |
| 194 | fi |
| 195 | diff -u last-good-signers "$TMPDIR/signers" || exit 1 |
| 196 | diff -u last-good-keys "$TMPDIR/keys" || exit 1 |
| 197 | done |
| 198 | |
| 199 | touch "$out" |