gunk-dev/the-valley

identity.cue

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