| 1 | // identity compiles a valley instance's identity registry — the declared |
| 2 | // CUE document naming who the instance grants something to (dcr-b87f6e8) — |
| 3 | // into the artifacts its enforcement boundaries check. |
| 4 | // |
| 5 | // It renders, and enforces nothing itself. sshd refuses a key that is not |
| 6 | // in the authorized_keys it writes, the integrator refuses evidence signed |
| 7 | // by nobody in the known-signers it writes, and the pre-receive hook |
| 8 | // refuses an integration request from anybody not in the grants it writes; |
| 9 | // this program is the step between the document and those three gates. |
| 10 | package main |
| 11 | |
| 12 | import ( |
| 13 | "fmt" |
| 14 | "os" |
| 15 | ) |
| 16 | |
| 17 | const usage = `usage: identity <command> [flags] |
| 18 | |
| 19 | compile render the registry at a repository's tip into the artifacts |
| 20 | the enforcement boundaries check |
| 21 | help print this message |
| 22 | |
| 23 | The registry is one declared CUE document in the instance repository |
| 24 | (dcr-b87f6e8), read from that repository's integrated tip and never from a |
| 25 | working tree: an edit in a branch or a worktree governs nothing until it |
| 26 | lands. Three artifacts come out of it. |
| 27 | |
| 28 | The known-signers file is every attestation-capable key, written as the |
| 29 | note format's verifier keys. It is both the integrator's acceptance list |
| 30 | and any reader's ` + "`attest verify --known-keys`" + `, so it holds every key that |
| 31 | signs — the integrator's own included. A key's signing name is recorded per |
| 32 | key, because the note format's key hash binds the name to the key: the same |
| 33 | key published under a second name is a second, unrelated verifier key. |
| 34 | |
| 35 | The authorized_keys file is every key of every principal holding a grant at |
| 36 | a boundary of kind "git-push", each line tagging its key with the |
| 37 | principal's name. sshd puts that tag in the environment of the receive-pack |
| 38 | the pre-receive hook runs under, which is the only thing that can tell one |
| 39 | pusher from another over a shared git user. |
| 40 | |
| 41 | The grants file is every grant the pre-receive hook checks, one line per |
| 42 | holder: "request <principal>" for each principal holding a grant at a |
| 43 | boundary of kind "request". The hook takes writes to the integration |
| 44 | request namespace only from a principal named there. |
| 45 | |
| 46 | The registry is read with git's replacement refs off and with no GIT_ |
| 47 | variable or user or system configuration inherited, so the registry |
| 48 | compiled is the one the tip holds and not an object something else has |
| 49 | been made to stand in for. |
| 50 | |
| 51 | Expiry is enforced here, because a document has no clock. An entry whose |
| 52 | expiry has arrived is omitted from every artifact and noted on stderr, and |
| 53 | the rest of the registry still compiles — so access ends at the first |
| 54 | convergence after expiry. |
| 55 | |
| 56 | One state is refused rather than compiled: a registry where, after the |
| 57 | expiry cut, no remaining principal holds a grant at a boundary of kind |
| 58 | "registry". Nobody would govern the registry's own stream, so the whole |
| 59 | render fails with an error naming governanceOrphaned and the last good |
| 60 | artifacts stand. The rule is here and not in the schema for the same reason |
| 61 | expiry is — the state is reached by the clock, and a document has none. |
| 62 | |
| 63 | A render that fails leaves the last good artifacts exactly as they were. |
| 64 | All of them are computed in full before any is written, and each is |
| 65 | replaced by rename. A schema violation, an unreachable repository or a bug |
| 66 | here costs the compilation and never the git user's access. |
| 67 | |
| 68 | flags: |
| 69 | --repo DIR the bare instance repository carrying the registry |
| 70 | --ref REF the ref whose tip is read (default refs/heads/main) |
| 71 | --dir DIR the registry's directory in that tip (default |
| 72 | identity) |
| 73 | --schema FILE the identity schema (default |
| 74 | $VALLEY_IDENTITY_SCHEMA) |
| 75 | --known-signers FILE where the verifier keys are written |
| 76 | --authorized-keys FILE where the tagged authorized_keys is written |
| 77 | --grants FILE where the grants the pre-receive hook checks are |
| 78 | written |
| 79 | --now YYYY-MM-DD the day expiry is judged against (default: today, |
| 80 | UTC) |
| 81 | ` |
| 82 | |
| 83 | func main() { |
| 84 | if len(os.Args) < 2 { |
| 85 | fmt.Fprint(os.Stderr, usage) |
| 86 | os.Exit(2) |
| 87 | } |
| 88 | var err error |
| 89 | switch os.Args[1] { |
| 90 | case "compile": |
| 91 | err = compile(os.Args[2:]) |
| 92 | case "help", "-h", "--help": |
| 93 | fmt.Print(usage) |
| 94 | return |
| 95 | default: |
| 96 | fmt.Fprintf(os.Stderr, "identity: unknown command %q\n\n%s", os.Args[1], usage) |
| 97 | os.Exit(2) |
| 98 | } |
| 99 | if err != nil { |
| 100 | fmt.Fprintf(os.Stderr, "identity: %v\n", err) |
| 101 | os.Exit(1) |
| 102 | } |
| 103 | } |