gunk-dev/the-valley

identity.cue

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