gunk-dev/the-valley

main.go

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