gunk-dev/the-valley

identity.cue

sourcea9174ca371a5main's published tip history
11.2 KiB
1// The identity registry of a valley instance: who the instance grants
2// something to, with which keys, and for how long. Identity is a governed
3// registry (dcr-b87f6e8) — one declared CUE document in the instance
4// repository, changed only through the integration path — and this file is
5// its schema. The schema is the substrate's floor over every instance
6// registry, and a floor mandates properties, never names: mandatory expiry
7// where a raw key is held, no external principal governing the registry,
8// and the genesis entry governing it. Which principals exist, which
9// boundaries the instance runs, and what a grant is called are instance
10// content.
11//
12// One tool reads this file: the compiler (identity/), which renders a
13// registry into the artifacts the enforcement boundaries check — the
14// known-signers file the integrator and `attest verify` read, the git
15// user's authorized_keys, the grants the pre-receive hook checks, and the
16// two approval signers files.
17// Expiry is enforced there rather than here, because a document has no
18// clock: the compiler omits an expired entry, so access ends at the first
19// convergence after expiry.
20//
21// Like the host, event and policy schemas, this file is deliberately not
22// Nix. A registry names principals, keys and boundaries; it never names
23// derivations, systems or store paths, so it travels between machines
24// unchanged.
25//
26// Validate a registry against this schema:
27// cue vet -c schema/identity.cue examples/identity/registry/*.cue
28package identity
29
30// A principal is a named actor the instance grants something to.
31#Principal: {
32 // human: a person. machine: a computer acting for itself. service: a
33 // program the instance runs. An agent run is none of these and holds no
34 // entry — a run acts under authority delegated from a principal
35 // (ida-a8243d2) and is named by its provenance (ida-45178f6), so the
36 // registry holds the top of that chain and never its links.
37 kind: "human" | "machine" | "service"
38
39 // The keys that prove possession, at least one. A bearer secret — a
40 // credential whose possession is the entire proof — is not a key and has
41 // no place here (dcr-b87f6e8).
42 keys: [#Key, ...#Key]
43
44 // What this principal may do, keyed by grant name. The name is instance
45 // content; what makes a grant real is the boundary it names.
46 grants: [#Name]: #Grant
47
48 // The identity an external collaborator already controls — a domain
49 // handle or a decentralized identifier. It is cited, never minted: the
50 // registry decides what that identity may do here, and never becomes the
51 // person's identity. null for a principal of this instance.
52 external: #External | *null
53
54 // The first day this entry no longer counts. The compiler compares it
55 // against the day it runs and omits the entry from every artifact from
56 // that day on, so an expiry is a revocation already scheduled.
57 expires?: #Date
58
59 // Mandatory expiry, the floor's first property. A machine or service
60 // holds its raw key until the certificate issuance service arrives
61 // (dcr-b87f6e8), so the key it holds is one with an end; an external
62 // principal is not this instance's to vouch for indefinitely.
63 if kind != "human" {expires: #Date}
64 if external != null {expires: #Date}
65}
66
67// One key of a principal.
68#Key: {
69 // ed25519 is the only algorithm the note format signs or verifies with
70 // (attest/sign.go) and the only one sshd is asked to accept here. A
71 // passkey is the same class of credential (dcr-b87f6e8) and becomes a
72 // second class the day a surface authenticates against one.
73 class: "ssh-ed25519"
74
75 // What the private half is bound to: hardware a person holds, or one
76 // host. Nothing here is bound to a file that travels.
77 bound: "hardware" | "host"
78
79 // The public half, exactly as `authorized_keys` writes it — the type,
80 // base64 of the SSH wire format, and an optional comment.
81 public: =~"^ssh-ed25519 [A-Za-z0-9+/]+={0,2}( [^\\n]*)?$"
82
83 // The name this key signs notes under, when it signs at all. Per key and
84 // not per entry: the note format's key hash binds the name to the key
85 // (attest/sign.go), so one person signing from two machines under two
86 // names holds two verifier keys, and recording the wrong name compiles a
87 // line no verifier will ever match. A key without it pushes and never
88 // attests.
89 signs?: #SignerName
90
91 // Evidence that the private half was made on a YubiKey and cannot
92 // leave it. The compiler verifies it against the Yubico roots it
93 // carries, and a key whose attestation verifies and says every
94 // signature needs a touch is a hardware approval key. Without one, a
95 // key is never a hardware approval key, whatever bound says. A key
96 // with one is held on a device, so it is bound to hardware.
97 attestation?: #Attestation
98 if attestation != _|_ {bound: "hardware"}
99}
100
101// A YubiKey PIV attestation of one key: two certificates, each PEM as the
102// YubiKey writes it. The schema holds their shape; the compiler checks
103// what they say.
104#Attestation: {
105 // The certificate the YubiKey wrote for the slot holding the key:
106 // `yubico-piv-tool -a attest -s 9c` for slot 9c.
107 slot: #Certificate
108
109 // The YubiKey's own attestation certificate, which signed the slot's:
110 // `yubico-piv-tool -a read-certificate -s f9`.
111 f9: #Certificate
112}
113
114// One PEM certificate and nothing else.
115#Certificate: =~"^-----BEGIN CERTIFICATE-----\n([A-Za-z0-9+/=]+\n)+-----END CERTIFICATE-----\n?$"
116
117// A grant is a named permission.
118#Grant: {
119 // The enforcement boundary that checks it: a key of `boundaries`. A
120 // grant may exist only where a boundary refuses the action when the
121 // grant is absent (dcr-b87f6e8), and naming the boundary is what makes
122 // that checkable — a grant naming a boundary the instance does not run
123 // fails vet.
124 boundary: #Name
125
126 // A grant carries its boundary and nothing else. The decision names a
127 // grant's scope as its stream list; the boundaries that exist today are
128 // compiled host-wide, and push cannot be anything else, because
129 // per-project access is not honestly enforceable over a shared git user
130 // (dcr-0f5d9b1). A stream list here would be a scope nothing checks. It
131 // arrives with the first boundary that checks one — the bus's
132 // per-subject authorization (bd-d853d9c), or the approve boundary once
133 // its compiled grants name a project.
134}
135
136// An enforcement boundary: the point in the running system that refuses an
137// action when the grant is absent.
138#Boundary: {
139 // What the enforcement point is.
140 //
141 // "git-push" — sshd on a host serving the instance's repositories. The
142 // compiler renders the git user's authorized_keys from the grants at
143 // this boundary, tagging each key with its principal's name, and the
144 // pre-receive hook reads that name off the key that pushed
145 // (nix/valley-host.nix).
146 //
147 // "registry" — the integration path that admits a change to the registry
148 // document itself. Governance of the registry's own stream is a grant
149 // here, and the required checks of that path class include human
150 // approval (ida-b7025b5).
151 //
152 // "approve" — the pre-receive hook (valleyhook/) on a host serving the
153 // instance's repositories, checking writes to the integration-request
154 // namespace (refs/the-valley/integration-requests/*). This is the
155 // approve grant, the request verb of dcr-e544f20. "request" is the same
156 // kind under the name it had first, and is also accepted: a grant at a
157 // boundary of either kind is the approve grant. The compiler writes
158 // each holder into the grants file the hook reads, and the hook refuses
159 // a principal it does not name there: it cannot file, replace or
160 // withdraw a request. The grant rides on push — only a key sshd admits
161 // reaches the hook — so a principal that files requests holds a
162 // "git-push" grant too.
163 //
164 // "restack" — the same pre-receive hook, checking the two writes the
165 // host restacker needs beyond an ordinary push: adding one version to
166 // another principal's ready change record, on the branch and under the
167 // title of its active version, and writing restack reports
168 // (refs/the-valley/restack/*). The compiler writes each holder into the
169 // grants file as "restack <principal>". The grant opens nothing else:
170 // no other record transition, and no integration request. It rides on
171 // push too.
172 kind: "git-push" | "registry" | "approve" | "request" | "restack"
173}
174
175// An identity the registry cites rather than mints.
176#External: {
177 // What kind of identity is being cited.
178 kind: "domain" | "did"
179
180 // The handle itself: a domain name, or a decentralized identifier. It is
181 // verified at onboarding and re-verifiable by anyone.
182 handle: =~"^[^\\s]+$"
183}
184
185// A calendar day, UTC.
186#Date: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
187
188// Principal, grant and boundary names. Held to the shape a principal name
189// must have to ride into the pre-receive hook's environment
190// (nix/valley-host.nix), because that is where a compiled name ends up.
191#Name: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$"
192
193// A name a key signs under, held to what a signature line can carry
194// (attest/sign.go): no space, because a space separates the name from the
195// signature, and no plus, because a plus separates the fields of a verifier
196// key.
197#SignerName: =~"^[^\\s+]+$"
198
199// ----------------------------------------------------------------------
200// The registry.
201
202// The enforcement boundaries this instance runs. Every grant names one of
203// these, and the cross-check below adds any name a grant used, so a grant
204// at a boundary the instance does not run fails vet as an incomplete
205// boundary rather than compiling into nothing.
206boundaries: [#Name]: #Boundary
207boundaries: {
208 for _, p in principals for _, g in p.grants {(g.boundary): _}
209}
210
211// The entries.
212principals: [#Name]: #Principal
213
214// The genesis entry: created at instance birth, the anchor later boundaries
215// verify against, and the one structural requirement of a registry.
216genesis: #Name
217
218// Derived: the genesis entry's grants that govern the registry's own
219// stream. A registry whose genesis governs nothing fails vet with an error
220// naming this field — there would be no anchor, and no hand the registry
221// itself is in.
222genesisGovernance: [
223 for gn, g in principals[genesis].grants
224 if boundaries[g.boundary].kind == "registry" {gn},
225]
226genesisGovernance: [_, ...]
227
228// Derived, and empty in every valid registry: the grants at a registry
229// boundary held by a cited identity. The floor forbids them — an external
230// principal governing the registry would put the instance's own membership
231// in a hand the instance does not control — so each one lands here as a
232// sentinel string against a `bool` and fails vet naming the principal and
233// the grant.
234externalGovernance: [string]: bool
235externalGovernance: {
236 for pn, p in principals if p.external != null
237 for gn, g in p.grants if boundaries[g.boundary].kind == "registry" {
238 "\(pn).\(gn)": "INVALID: an external principal may not hold registry governance"
239 }
240}
241
242// A file's top level cannot be closed (embedding a definition would open it
243// instead), so reject stray top-level fields explicitly: anything but the
244// registry's own fields conflicts with this sentinel and fails vet with an
245// error naming the field.
246[
247 !="boundaries" &
248 !="principals" &
249 !="genesis" &
250 !="genesisGovernance" &
251 !="externalGovernance",
252]: "INVALID: unknown top-level field; only \"boundaries\", \"principals\" and \"genesis\" are allowed"