gunk-dev/the-valley

identity.cue

source822cb119f57bmain's published tip history
9.4 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 request 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 // "request" — 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 // request verb of dcr-e544f20. The compiler writes each holder into the
130 // grants file the hook reads, and the hook refuses a principal it does
131 // not name there: it cannot file, replace or withdraw a request. The
132 // grant rides on push — only a key sshd admits reaches the hook — so a
133 // principal that files requests holds a "git-push" grant too.
134 kind: "git-push" | "registry" | "request"
135}
136
137// An identity the registry cites rather than mints.
138#External: {
139 // What kind of identity is being cited.
140 kind: "domain" | "did"
141
142 // The handle itself: a domain name, or a decentralized identifier. It is
143 // verified at onboarding and re-verifiable by anyone.
144 handle: =~"^[^\\s]+$"
145}
146
147// A calendar day, UTC.
148#Date: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
149
150// Principal, grant and boundary names. Held to the shape a principal name
151// must have to ride into the pre-receive hook's environment
152// (nix/valley-host.nix), because that is where a compiled name ends up.
153#Name: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$"
154
155// A name a key signs under, held to what a signature line can carry
156// (attest/sign.go): no space, because a space separates the name from the
157// signature, and no plus, because a plus separates the fields of a verifier
158// key.
159#SignerName: =~"^[^\\s+]+$"
160
161// ----------------------------------------------------------------------
162// The registry.
163
164// The enforcement boundaries this instance runs. Every grant names one of
165// these, and the cross-check below adds any name a grant used, so a grant
166// at a boundary the instance does not run fails vet as an incomplete
167// boundary rather than compiling into nothing.
168boundaries: [#Name]: #Boundary
169boundaries: {
170 for _, p in principals for _, g in p.grants {(g.boundary): _}
171}
172
173// The entries.
174principals: [#Name]: #Principal
175
176// The genesis entry: created at instance birth, the anchor later boundaries
177// verify against, and the one structural requirement of a registry.
178genesis: #Name
179
180// Derived: the genesis entry's grants that govern the registry's own
181// stream. A registry whose genesis governs nothing fails vet with an error
182// naming this field — there would be no anchor, and no hand the registry
183// itself is in.
184genesisGovernance: [
185 for gn, g in principals[genesis].grants
186 if boundaries[g.boundary].kind == "registry" {gn},
187]
188genesisGovernance: [_, ...]
189
190// Derived, and empty in every valid registry: the grants at a registry
191// boundary held by a cited identity. The floor forbids them — an external
192// principal governing the registry would put the instance's own membership
193// in a hand the instance does not control — so each one lands here as a
194// sentinel string against a `bool` and fails vet naming the principal and
195// the grant.
196externalGovernance: [string]: bool
197externalGovernance: {
198 for pn, p in principals if p.external != null
199 for gn, g in p.grants if boundaries[g.boundary].kind == "registry" {
200 "\(pn).\(gn)": "INVALID: an external principal may not hold registry governance"
201 }
202}
203
204// A file's top level cannot be closed (embedding a definition would open it
205// instead), so reject stray top-level fields explicitly: anything but the
206// registry's own fields conflicts with this sentinel and fails vet with an
207// error naming the field.
208[
209 !="boundaries" &
210 !="principals" &
211 !="genesis" &
212 !="genesisGovernance" &
213 !="externalGovernance",
214]: "INVALID: unknown top-level field; only \"boundaries\", \"principals\" and \"genesis\" are allowed"