gunk-dev/the-valley

main.go

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