| 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, and the integrator refuses evidence |
| 7 | // signed by nobody in the known-signers it writes; this program is the step |
| 8 | // between the document and those two gates. |
| 9 | package main |
| 10 | |
| 11 | import ( |
| 12 | "fmt" |
| 13 | "os" |
| 14 | ) |
| 15 | |
| 16 | const usage = `usage: identity <command> [flags] |
| 17 | |
| 18 | compile render the registry at a repository's tip into the artifacts |
| 19 | the enforcement boundaries check |
| 20 | help print this message |
| 21 | |
| 22 | The registry is one declared CUE document in the instance repository |
| 23 | (dcr-b87f6e8), read from that repository's integrated tip and never from a |
| 24 | working tree: an edit in a branch or a worktree governs nothing until it |
| 25 | lands. Two artifacts come out of it. |
| 26 | |
| 27 | The known-signers file is every attestation-capable key, written as the |
| 28 | note format's verifier keys. It is both the integrator's acceptance list |
| 29 | and any reader's ` + "`attest verify --known-keys`" + `, so it holds every key that |
| 30 | signs — the integrator's own included. A key's signing name is recorded per |
| 31 | key, because the note format's key hash binds the name to the key: the same |
| 32 | key published under a second name is a second, unrelated verifier key. |
| 33 | |
| 34 | The authorized_keys file is every key of every principal holding a grant at |
| 35 | a boundary of kind "git-push", each line tagging its key with the |
| 36 | principal's name. sshd puts that tag in the environment of the receive-pack |
| 37 | the pre-receive hook runs under, which is the only thing that can tell one |
| 38 | pusher from another over a shared git user. |
| 39 | |
| 40 | Expiry is enforced here, because a document has no clock. An entry whose |
| 41 | expiry has arrived is omitted from both artifacts and noted on stderr, and |
| 42 | the rest of the registry still compiles — so access ends at the first |
| 43 | convergence after expiry. |
| 44 | |
| 45 | A render that fails leaves the last good artifacts exactly as they were. |
| 46 | Both are computed in full before either is written, and each is replaced by |
| 47 | rename. A schema violation, an unreachable repository or a bug here costs |
| 48 | the compilation and never the git user's access. |
| 49 | |
| 50 | flags: |
| 51 | --repo DIR the bare instance repository carrying the registry |
| 52 | --ref REF the ref whose tip is read (default refs/heads/main) |
| 53 | --dir DIR the registry's directory in that tip (default |
| 54 | identity) |
| 55 | --schema FILE the identity schema (default |
| 56 | $VALLEY_IDENTITY_SCHEMA) |
| 57 | --known-signers FILE where the verifier keys are written |
| 58 | --authorized-keys FILE where the tagged authorized_keys is written |
| 59 | --now YYYY-MM-DD the day expiry is judged against (default: today, |
| 60 | UTC) |
| 61 | ` |
| 62 | |
| 63 | func main() { |
| 64 | if len(os.Args) < 2 { |
| 65 | fmt.Fprint(os.Stderr, usage) |
| 66 | os.Exit(2) |
| 67 | } |
| 68 | var err error |
| 69 | switch os.Args[1] { |
| 70 | case "compile": |
| 71 | err = compile(os.Args[2:]) |
| 72 | case "help", "-h", "--help": |
| 73 | fmt.Print(usage) |
| 74 | return |
| 75 | default: |
| 76 | fmt.Fprintf(os.Stderr, "identity: unknown command %q\n\n%s", os.Args[1], usage) |
| 77 | os.Exit(2) |
| 78 | } |
| 79 | if err != nil { |
| 80 | fmt.Fprintf(os.Stderr, "identity: %v\n", err) |
| 81 | os.Exit(1) |
| 82 | } |
| 83 | } |