gunk-dev/the-valley

main.go

sourcef14c339919dfmain's published tip history
7.3 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 or a restack write from anybody not in
9// the grants it writes; this program is the step between the document and
10// those three gates. It also writes the two approval signers files, which
11// no gate reads.
12package main
13
14import (
15 "fmt"
16 "os"
17)
18
19const usage = `usage: identity <command> [flags]
20
21 compile render the registry at a repository's tip into the artifacts
22 the enforcement boundaries check
23 help print this message
24
25The registry is one declared CUE document in the instance repository
26(dcr-b87f6e8), read from that repository's integrated tip and never from a
27working tree: an edit in a branch or a worktree governs nothing until it
28lands. Three artifacts come out of it, and two approval signers files when
29asked for.
30
31The known-signers file is every attestation-capable key, written as the
32note format's verifier keys. It is both the integrator's acceptance list
33and any reader's ` + "`attest verify --known-keys`" + `, so it holds every key that
34signs — the integrator's own included. A key's signing name is recorded per
35key, because the note format's key hash binds the name to the key: the same
36key published under a second name is a second, unrelated verifier key.
37
38The authorized_keys file is every key of every principal holding a grant at
39a boundary of kind "git-push", each line tagging its key with the
40principal's name. The git user's shell reads the tag off the entry of the
41key sshd authenticated and hands it to the pre-receive hook, which is the
42only thing that can tell one pusher from another over a shared git user.
43
44The grants file is every grant the pre-receive hook checks, one line per
45holder: "request <principal>" for each principal holding the approve grant,
46at a boundary of kind "approve" or of kind "request", and "restack
47<principal>" for each holding one at a boundary of kind "restack". The two
48kinds are one grant: the approve grant, also accepted as request. A
49principal holding both is written once, and a registry using either kind
50compiles the same file. The hook takes writes to the integration request
51namespace only from a holder of the approve grant. It takes a version
52added to another principal's ready change, and a restack report, only from
53one named under restack.
54
55The two approval signers files hold the keys whose signed approvals
56count. They are written as the note format's verifier keys, and each line
57is named by the principal who approves with its key. No gate reads them.
58
59approval-signers lists every key of every unexpired human holding the
60approve grant. approval-signers-hardware lists the keys from it whose
61entry carries a YubiKey attestation that verifies and whose touch policy
62is always: the YubiKey asks for a touch before every signature.
63
64An attestation is two PEM certificates: the one the YubiKey wrote for the
65PIV slot holding the key, and the YubiKey's own f9 certificate, which
66signed it. It verifies when the slot certificate chains through the f9
67certificate and Yubico's PIV intermediates to Yubico Attestation Root 1,
68and the key it names is the entry's public key. This program carries that
69root and those intermediates, and a registry cannot add others. An
70attestation that does not verify fails the render. So does one stating a
71PIN or touch policy other than the values Yubico specifies: 1, 2 and 3.
72Each attestation that verifies is reported on stderr with the YubiKey's
73serial number, firmware, PIN policy and touch policy, for whoever reviews
74the enrollment.
75
76A key that approves belongs to one principal: one also listed under
77another principal fails the render.
78
79The registry is read with git's replacement refs off and with no GIT_
80variable or user or system configuration inherited, so the registry
81compiled is the one the tip holds and not an object something else has
82been made to stand in for.
83
84Expiry is enforced here, because a document has no clock. An entry whose
85expiry has arrived is omitted from every artifact and noted on stderr, and
86the rest of the registry still compiles — so access ends at the first
87convergence after expiry.
88
89One key authorized as two principals is refused too, whether both entries
90are the registry's or one is the host's own (--declared-keys). sshd
91authorizes a key by the first entry that names it, so which principal such
92a key pushes as would depend on the order of lines and files.
93
94One state is refused rather than compiled: a registry where, after the
95expiry cut, no remaining principal holds a grant at a boundary of kind
96"registry". Nobody would govern the registry's own stream, so the whole
97render fails with an error naming governanceOrphaned and the last good
98artifacts stand. The rule is here and not in the schema for the same reason
99expiry is — the state is reached by the clock, and a document has none.
100
101A render that fails leaves the last good artifacts exactly as they were.
102All of them are computed in full before any is written, and each is
103replaced by rename. A schema violation, an unreachable repository or a bug
104here costs the compilation and never the git user's access.
105
106flags:
107 --repo DIR the bare instance repository carrying the registry
108 --ref REF the ref whose tip is read (default refs/heads/main)
109 --dir DIR the registry's directory in that tip (default
110 identity)
111 --schema FILE the identity schema (default
112 $VALLEY_IDENTITY_SCHEMA)
113 --known-signers FILE where the verifier keys are written
114 --authorized-keys FILE where the tagged authorized_keys is written
115 --grants FILE where the grants the pre-receive hook checks are
116 written
117 --approval-signers FILE
118 where the verifier keys of every approval key are
119 written. None is written without it.
120 --approval-signers-hardware FILE
121 where the verifier keys of the hardware approval
122 keys are written. None is written without it.
123 --declared-keys FILE the authorized_keys lines the host declares by
124 hand. A registry key that is also declared under
125 another tag, or untagged, fails the render: sshd
126 reads the declared entry first, so the key would
127 never push as its registry principal.
128 --now YYYY-MM-DD the day expiry, and the validity of an
129 attestation's certificates, are judged against
130 (default: today, UTC)
131`
132
133func main() {
134 if len(os.Args) < 2 {
135 fmt.Fprint(os.Stderr, usage)
136 os.Exit(2)
137 }
138 var err error
139 switch os.Args[1] {
140 case "compile":
141 err = compile(os.Args[2:])
142 case "help", "-h", "--help":
143 fmt.Print(usage)
144 return
145 default:
146 fmt.Fprintf(os.Stderr, "identity: unknown command %q\n\n%s", os.Args[1], usage)
147 os.Exit(2)
148 }
149 if err != nil {
150 fmt.Fprintf(os.Stderr, "identity: %v\n", err)
151 os.Exit(1)
152 }
153}