gunk-dev/the-valley

policy.cue

sourcedfa994caaeb3main's published tip history
13.7 KiB
1// the-valley's project layer: what this one project declares above the
2// floor. The floor is the owning valley's (qinling policy/instance); this
3// layer binds the-valley alone, and a project can only add to its own
4// layer (dcr-f41f718).
5package verification
6
7import (
8 "list"
9 "strings"
10)
11
12project: {
13 // the-valley takes no knowledge lint of its own tree. The docs
14 // template's lint checks a knowledge graph kept in the source, and
15 // the-valley's source holds none: its plan graph is project storage, at
16 // refs/the-valley/knots, and the push hook holds it to the knot
17 // module's rules. The nodes under archive/.the-valley/ are history that
18 // never changes, so linting them against today's schema protects
19 // nothing. The lint itself stays covered: the knowledge-lint class
20 // below requires its consumer and rejection checks.
21
22 // Every check below is the flake check of the same name in
23 // nix/checks.nix, built for the runner's own system. own-policy holds
24 // this list to that: a name here that the flake does not define fails
25 // it.
26 let ownChecks = [
27 "valleyhook-unit",
28 "protect-e2e",
29 "knots-e2e",
30 "note-unit",
31 "change-unit",
32 "knot-unit",
33 "knot-agree",
34 "delta-unit",
35 "attest-unit",
36 "attest-conformance",
37 "attest-e2e",
38 "identity-unit",
39 "identity-e2e",
40 "integrator-unit",
41 "integrator-e2e",
42 "sigverify-unit",
43 "sigverify-e2e",
44 "rebase-unit",
45 "valley-go-unit",
46 "valley-cli",
47 "review-notes",
48 "valley-request",
49 "valley-status",
50 "valley-ready",
51 "valley-changes",
52 "valley-knot",
53 "valley-plan",
54 "valley-darwin-eval",
55 "policy-deriver",
56 "own-policy",
57 "module-eval",
58 "cue-vet",
59 "attest-schema",
60 "identity-schema",
61 "knowledge-lint-consumer",
62 "knowledge-lint-rejects",
63 "init-e2e",
64 "mirror-e2e",
65 "bus-e2e",
66 "ssh-e2e",
67 "publish-e2e",
68 ]
69 for n in ownChecks {
70 checks: (n): {
71 runner: "nix"
72 attribute: n
73 }
74 }
75
76 // The integrator's scenarios take about a minute, and ssh-e2e and
77 // publish-e2e boot NixOS machines. Every other check here takes seconds
78 // once its packages are built.
79 checks: "integrator-e2e": cost: "slow"
80 checks: "ssh-e2e": cost: "slow"
81 checks: "publish-e2e": cost: "slow"
82
83 // Each class below is one part of the tree and the checks that read it.
84 // A path in two classes requires both sets. A Go module's unit check is its
85 // package, whose checkPhase runs `go test`.
86
87 // The pre-receive hook and the git user's login shell. protect-e2e
88 // pushes to bare repositories wired with the hook a host renders,
89 // valley-ready pushes change records through that hook, and knots-e2e
90 // pushes the plan graph through it.
91 classes: valleyhook: {
92 paths: "valleyhook/**": true
93 requires: "valleyhook-unit": true
94 requires: "protect-e2e": true
95 requires: "valley-ready": true
96 requires: "knots-e2e": true
97 }
98
99 // The change record, which the hook guards, the CLI's Go verbs and the
100 // rebase engine write, and the integrator reads. Each reads a record
101 // through it, so a change to it requires their tests as well as its own.
102 classes: change: {
103 paths: "change/**": true
104 requires: "change-unit": true
105 requires: "valleyhook-unit": true
106 requires: "protect-e2e": true
107 requires: "rebase-unit": true
108 requires: "valley-go-unit": true
109 requires: "valley-ready": true
110 requires: "valley-changes": true
111 requires: "integrator-unit": true
112 requires: "integrator-e2e": true
113 }
114
115 // The plan graph's module, which the CLI's Go verbs write the graph
116 // with and the hook validates it with. knot-agree holds its validator
117 // to the node schema and the knowledge lint, valley-knot and
118 // valley-plan drive the verbs that use it, and knots-e2e pushes
119 // through the hook.
120 classes: knot: {
121 paths: "knot/**": true
122 requires: "knot-unit": true
123 requires: "knot-agree": true
124 requires: "valley-go-unit": true
125 requires: "valley-knot": true
126 requires: "valley-plan": true
127 requires: "valleyhook-unit": true
128 requires: "knots-e2e": true
129 }
130
131 // valley-delta-v1, which the CLI's Go verbs compare a version with its
132 // approved version through. delta-unit holds it to its conformance
133 // vectors, valley-go-unit builds the verbs with it, and valley-ready and
134 // review-notes drive review over the comparison.
135 classes: delta: {
136 paths: "delta/**": true
137 requires: "delta-unit": true
138 requires: "valley-go-unit": true
139 requires: "valley-ready": true
140 requires: "review-notes": true
141 }
142
143 // The note envelope. The hook and attest both read notes through it, so
144 // a change to it requires their tests as well as its own.
145 classes: note: {
146 paths: "note/**": true
147 requires: "note-unit": true
148 requires: "valleyhook-unit": true
149 requires: "protect-e2e": true
150 requires: "attest-unit": true
151 requires: "attest-e2e": true
152 }
153
154 // The attestation helper, and the conformance vectors under
155 // attest/conformance/ that hold its written form fixed.
156 classes: attest: {
157 paths: "attest/**": true
158 requires: "attest-unit": true
159 requires: "attest-conformance": true
160 requires: "attest-e2e": true
161 }
162
163 // The identity registry compiler, and the registries it is driven over.
164 classes: identity: {
165 paths: "identity/**": true
166 paths: "examples/identity/**": true
167 requires: "identity-unit": true
168 requires: "identity-e2e": true
169 }
170
171 // The integrator, the end-to-end scenarios under integrator/e2e/, and the
172 // verification schema, which the integrator composes every policy under
173 // and both checks read.
174 classes: integrator: {
175 paths: "integrator/**": true
176 paths: "schema/verification.cue": true
177 requires: "integrator-unit": true
178 requires: "integrator-e2e": true
179 }
180
181 // The security-key signature verifier.
182 classes: sigverify: {
183 paths: "sigverify/**": true
184 requires: "sigverify-unit": true
185 requires: "sigverify-e2e": true
186 }
187
188 // The valley CLI: the script, its Go verbs (status/), the rebase engine
189 // they rebase and read landings with (rebase/), and its completions.
190 // valley-ready drives ready, withdraw, rebase and the verbs that take a
191 // change's handle, valley-changes drives changes and pending, and
192 // valley-plan drives plan against the golden files under
193 // status/testdata/plan/.
194 classes: cli: {
195 paths: "bin/valley": true
196 paths: "status/**": true
197 paths: "rebase/**": true
198 paths: "completions/**": true
199 requires: "valley-go-unit": true
200 requires: "valley-cli": true
201 requires: "review-notes": true
202 requires: "valley-request": true
203 requires: "valley-status": true
204 requires: "valley-ready": true
205 requires: "valley-changes": true
206 requires: "valley-knot": true
207 requires: "valley-plan": true
208 requires: "policy-deriver": true
209 }
210
211 // The rebase engine, with its own tests over real repositories. The
212 // verbs that run it are the cli class's, so its paths are there too.
213 classes: rebase: {
214 paths: "rebase/**": true
215 requires: "rebase-unit": true
216 }
217
218 // The verification policy: this layer, the pointer to the owning
219 // valley, the schema a policy is written in, and the example policies
220 // the deriver and cue-vet read.
221 classes: policy: {
222 paths: "policy/**": true
223 paths: "schema/verification.cue": true
224 paths: "examples/policy/**": true
225 requires: "policy-deriver": true
226 requires: "cue-vet": true
227 requires: "own-policy": true
228 }
229
230 // The flake, the NixOS module, the packages and the check definitions,
231 // and the host declarations the module checks are evaluated over.
232 // own-policy is here because renaming or removing a flake check would
233 // leave this layer naming a check that no longer exists. A change to
234 // flake.nix or flake.lock requires these alone, so a nixpkgs bump boots no
235 // machine.
236 classes: nix: {
237 paths: "nix/**": true
238 paths: "flake.nix": true
239 paths: "flake.lock": true
240 paths: "examples/host.cue": true
241 paths: "examples/hosts/**": true
242 requires: "module-eval": true
243 requires: "valley-darwin-eval": true
244 requires: "cue-vet": true
245 requires: "own-policy": true
246 }
247
248 // The schemas, and the example events, attestations and registries they
249 // are vetted against.
250 classes: schema: {
251 paths: "schema/**": true
252 paths: "examples/events/**": true
253 paths: "examples/attestations/**": true
254 paths: "examples/identity/**": true
255 requires: "cue-vet": true
256 requires: "attest-schema": true
257 requires: "identity-schema": true
258 }
259
260 // The knowledge lint itself: its program, the node schema it holds a
261 // graph to, and the example graphs it must accept and reject. The plan
262 // graph's validator is held to the same two by knot-agree.
263 classes: "knowledge-lint": {
264 paths: "nix/knowledge-lint.*": true
265 paths: "schema/node.cue": true
266 paths: "examples/graphs/**": true
267 requires: "knowledge-lint-consumer": true
268 requires: "knowledge-lint-rejects": true
269 requires: "knot-agree": true
270 }
271
272 // The NixOS module and what its end-to-end checks run. The hook checks
273 // follow the scripts out of the hosts in nix/checks/hosts.nix, which
274 // are made of the three declarations named here; ssh-e2e and
275 // publish-e2e run the module in NixOS machines.
276 classes: "host-module": {
277 paths: "nix/valley-host.nix": true
278 paths: "nix/checks/hosts.nix": true
279 paths: "examples/hosts/protected.cue": true
280 paths: "examples/hosts/bus.cue": true
281 paths: "examples/hosts/mirrors.cue": true
282 requires: "init-e2e": true
283 requires: "mirror-e2e": true
284 requires: "bus-e2e": true
285 requires: "protect-e2e": true
286 requires: "knots-e2e": true
287 requires: "identity-e2e": true
288 requires: "ssh-e2e": true
289 requires: "publish-e2e": true
290 requires: "valley-changes": true
291 }
292
293 // A check's own files require that check: its script,
294 // nix/checks/<name>.sh, and its definition, nix/checks/<name>.nix,
295 // where it has a file of its own. One class per check, named
296 // check-<name>. prose-format is the floor's check, but its script is
297 // here. own-policy fails if a script under nix/checks/ requires no
298 // check.
299 for n in list.Concat([ownChecks, ["prose-format"]]) {
300 classes: ("check-\(n)"): {
301 paths: ("nix/checks/\(n).sh"): true
302 paths: ("nix/checks/\(n).nix"): true
303 requires: (n): true
304 }
305 }
306
307 // The other files under nix/checks/, and the checks that read each: the
308 // definitions of a subject's checks, and the helpers and rejection lists
309 // a check is given. cli.nix, which defines every check of bin/valley,
310 // is left to the nix class, as is nix/checks.nix, which wires them all.
311 let checkFiles = {
312 "attest.nix": ["attest-unit", "attest-conformance", "attest-e2e"]
313 "delta.nix": ["delta-unit"]
314 "identity.nix": ["identity-unit", "identity-e2e"]
315 "integrator.nix": ["integrator-unit", "integrator-e2e"]
316 "sigverify.nix": ["sigverify-unit", "sigverify-e2e"]
317 "schema.nix": ["cue-vet", "attest-schema", "identity-schema"]
318 "knowledge.nix": ["knowledge-lint-consumer", "knowledge-lint-rejects", "prose-format"]
319 "hooks.nix": ["valleyhook-unit", "change-unit", "mirror-e2e", "protect-e2e", "init-e2e", "bus-e2e"]
320 "host-module.nix": ["module-eval"]
321 "fail-nth.sh": ["policy-deriver", "valley-request"]
322 "review-notes-editor.sh": ["review-notes"]
323 "cue-vet-rejected.txt": ["cue-vet"]
324 "identity-rejected.txt": ["identity-schema"]
325 "knowledge-lint-rejected.txt": ["knowledge-lint-rejects"]
326 }
327 for f, ns in checkFiles {
328 classes: ("check-file-\(strings.Replace(f, ".", "-", -1))"): {
329 paths: ("nix/checks/\(f)"): true
330 requires: {for n in ns {(n): true}}
331 }
332 }
333
334 // How far an approval carries across a rebase (#Carry in
335 // schema/verification.cue). Every path not named here is same-paths.
336 //
337 // The hook, the integrator, the signature verifier and the identity
338 // compiler enforce who may do what. An approval of a change to one of
339 // them carries only while no landing has touched the same classes:
340 // same-class. The identity compiler's class is its code and the schema
341 // it holds a registry to. It requires nothing, because the identity and
342 // schema classes already require the checks of its paths.
343 classes: valleyhook: carry: "same-class": true
344 classes: integrator: carry: "same-class": true
345 classes: sigverify: carry: "same-class": true
346 classes: "identity-compiler": {
347 paths: "identity/**": true
348 paths: "schema/identity.cue": true
349 carry: "same-class": true
350 }
351
352 // The policy decides what every change requires, so an approval of a
353 // change to it carries across no landing at all: exact. That is this
354 // layer, the pointer to the owning valley, and the schema a policy is
355 // written in. The example policies are fixtures and stay same-paths. Like
356 // identity-compiler, this class requires nothing: the policy class
357 // requires the checks of its paths.
358 //
359 // This tree holds no registry, grant or secret data of its own. The
360 // registries, grants and keys under examples/ and attest/conformance/
361 // are test fixtures, and the instance's registry is in its instance
362 // repository. So nothing else here is exact.
363 classes: "policy-authority": {
364 paths: "policy/**": true
365 paths: "schema/verification.cue": true
366 carry: exact: true
367 }
368
369 // The restacker's cap is the schema's default of 64 automatic versions
370 // per change.
371}
372
373// What no class above covers falls to the floor's `unclassified` rule and
374// requires prose-format alone. That is the research artefacts under research/,
375// the GitHub mirror's workflow under .github/, and editor settings: files
376// no program here reads.