gunk-dev/the-valley

policy.cue

sourceea038b6f45c6main's published tip history
19.1 KiB
1// the-valley's project layer: what this one project declares above the
2// floor. The floor is the owning valley's 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 "derive-unit",
36 "review-unit",
37 "attest-unit",
38 "attest-conformance",
39 "attest-e2e",
40 "identity-unit",
41 "identity-e2e",
42 "integrator-unit",
43 "integrator-e2e",
44 "restack-unit",
45 "restack-e2e",
46 "signers-e2e",
47 "sigverify-unit",
48 "sigverify-e2e",
49 "web-unit",
50 "web-server-unit",
51 "readaccess-unit",
52 "rebase-unit",
53 "valley-go-unit",
54 "valley-cli",
55 "review-notes",
56 "valley-request",
57 "valley-status",
58 "valley-ready",
59 "valley-changes",
60 "valley-knot",
61 "valley-plan",
62 "valley-darwin-eval",
63 "selfupdate-unit",
64 "valley-self-update",
65 "policy-deriver",
66 "own-policy",
67 "module-eval",
68 "cue-vet",
69 "attest-schema",
70 "identity-schema",
71 "knowledge-lint-consumer",
72 "knowledge-lint-rejects",
73 "init-e2e",
74 "mirror-e2e",
75 "bus-e2e",
76 "ssh-e2e",
77 "publish-e2e",
78 "worker-e2e",
79 "restack-host-e2e",
80 "web-publisher-e2e",
81 ]
82 for n in ownChecks {
83 checks: (n): {
84 runner: "nix"
85 attribute: n
86 }
87 }
88
89 // The integrator's scenarios take about a minute, and ssh-e2e,
90 // publish-e2e, worker-e2e, restack-host-e2e and web-publisher-e2e boot
91 // NixOS machines.
92 // Every other check here takes seconds once its packages are built.
93 checks: "integrator-e2e": cost: "slow"
94 checks: "ssh-e2e": cost: "slow"
95 checks: "publish-e2e": cost: "slow"
96 checks: "worker-e2e": cost: "slow"
97 checks: "restack-host-e2e": cost: "slow"
98 checks: "web-publisher-e2e": cost: "slow"
99
100 // Each class below is one part of the tree and the checks that read it.
101 // A path in two classes requires both sets. A Go module's unit check is
102 // its package built again with its tests, which runs `go test`. The
103 // package itself runs no tests (nix/packages.nix).
104
105 // The pre-receive hook and the git user's login shell. protect-e2e
106 // pushes to bare repositories wired with the hook a host renders,
107 // valley-ready pushes change records through that hook, and knots-e2e
108 // pushes the plan graph through it.
109 classes: valleyhook: {
110 paths: "valleyhook/**": true
111 requires: "valleyhook-unit": true
112 requires: "protect-e2e": true
113 requires: "valley-ready": true
114 requires: "knots-e2e": true
115 }
116
117 // The change record, which the hook guards, the CLI's Go verbs and the
118 // rebase engine write, and the integrator and the review module read.
119 // Each reads a record through it, so a change to it requires their tests
120 // as well as its own.
121 classes: change: {
122 paths: "change/**": true
123 requires: "change-unit": true
124 requires: "review-unit": true
125 requires: "valleyhook-unit": true
126 requires: "protect-e2e": true
127 requires: "rebase-unit": true
128 requires: "valley-go-unit": true
129 requires: "valley-ready": true
130 requires: "valley-changes": true
131 requires: "integrator-unit": true
132 requires: "integrator-e2e": true
133 }
134
135 // The plan graph's module, which the CLI's Go verbs write the graph
136 // with and the hook validates it with. knot-agree holds its validator
137 // to the node schema and the knowledge lint, valley-knot and
138 // valley-plan drive the verbs that use it, and knots-e2e pushes
139 // through the hook. The web export reads names and knot IDs by its
140 // rules, and the web server reads a claim's age by them, so
141 // web-unit and web-server-unit are here too.
142 classes: knot: {
143 paths: "knot/**": true
144 requires: "knot-unit": true
145 requires: "knot-agree": true
146 requires: "valley-go-unit": true
147 requires: "valley-knot": true
148 requires: "valley-plan": true
149 requires: "valleyhook-unit": true
150 requires: "knots-e2e": true
151 requires: "web-unit": true
152 requires: "web-server-unit": true
153 }
154
155 // valley-delta-v1, which the CLI's Go verbs compare a version with its
156 // approved version through, and which the review module recomputes a
157 // review's binding with. delta-unit holds it to its conformance vectors,
158 // valley-go-unit builds the verbs with it, valley-ready and review-notes
159 // drive review over the comparison, and review-unit binds reviews with
160 // its bounded reading.
161 classes: delta: {
162 paths: "delta/**": true
163 requires: "delta-unit": true
164 requires: "valley-go-unit": true
165 requires: "valley-ready": true
166 requires: "review-notes": true
167 requires: "review-unit": true
168 }
169
170 // Review records: the record, its binding to the version it judged, and
171 // its append-only history. review-unit runs its tests against real git.
172 classes: review: {
173 paths: "review/**": true
174 requires: "review-unit": true
175 }
176
177 // The deriver of required checks, and the composed-policy reader it reads
178 // the whole policy through. derive-unit holds the deriver to bin/valley's,
179 // and valley-go-unit builds the verb that prints its answer with both.
180 classes: derive: {
181 paths: "derive/**": true
182 paths: "composed/**": true
183 requires: "derive-unit": true
184 requires: "valley-go-unit": true
185 }
186
187 // The note envelope. The hook and attest both read notes through it,
188 // the identity compiler reads its approval files back with it, and the
189 // web export's manifest is a note, which the web server builds with,
190 // so a change to it requires their tests as well as its own.
191 classes: note: {
192 paths: "note/**": true
193 requires: "note-unit": true
194 requires: "valleyhook-unit": true
195 requires: "protect-e2e": true
196 requires: "attest-unit": true
197 requires: "attest-e2e": true
198 requires: "identity-unit": true
199 requires: "web-unit": true
200 requires: "web-server-unit": true
201 }
202
203 // The attestation helper, and the conformance vectors under
204 // attest/conformance/ that hold its written form fixed.
205 classes: attest: {
206 paths: "attest/**": true
207 requires: "attest-unit": true
208 requires: "attest-conformance": true
209 requires: "attest-e2e": true
210 }
211
212 // The identity registry compiler, and the registries it is driven over.
213 classes: identity: {
214 paths: "identity/**": true
215 paths: "examples/identity/**": true
216 requires: "identity-unit": true
217 requires: "identity-e2e": true
218 }
219
220 // The integrator, the end-to-end scenarios under integrator/e2e/, and the
221 // verification schema, which the integrator composes every policy under
222 // and both checks read.
223 classes: integrator: {
224 paths: "integrator/**": true
225 paths: "composed/**": true
226 paths: "schema/verification.cue": true
227 requires: "integrator-unit": true
228 requires: "integrator-e2e": true
229 }
230
231 // The security-key signature verifier.
232 classes: sigverify: {
233 paths: "sigverify/**": true
234 requires: "sigverify-unit": true
235 requires: "sigverify-e2e": true
236 }
237
238 // The web UI's module: the export contract, its shared fixture, the
239 // publisher, and the server. The publisher's tests also read each
240 // project's policy/read and the instance's registry under the read and
241 // identity schemas. Changes require both checks.
242 classes: web: {
243 paths: "web/**": true
244 paths: "schema/read.cue": true
245 paths: "schema/identity.cue": true
246 requires: "web-unit": true
247 requires: "web-server-unit": true
248 }
249
250 // Read access: the two consents a reader needs, the evaluator that
251 // intersects them, and the coverage report. readaccess-unit reads both
252 // schemas, so a change to either requires it, and the web publisher
253 // reads its consents through the module, so web-unit runs too.
254 classes: readaccess: {
255 paths: "readaccess/**": true
256 paths: "schema/read.cue": true
257 paths: "schema/identity.cue": true
258 requires: "readaccess-unit": true
259 requires: "web-unit": true
260 }
261
262 // The valley CLI: the script, its Go verbs (status/), the rebase engine
263 // they rebase and read landings with (rebase/), and its completions.
264 // valley-ready drives ready, withdraw, rebase and the verbs that take a
265 // change's handle, valley-changes drives changes and pending,
266 // valley-plan drives plan against the golden files under
267 // status/testdata/plan/, and valley-self-update drives --version and
268 // self-update. derive-unit holds the script's deriver to the Go one.
269 // The web publisher reads the valley through plan, pending and knot
270 // show, and its tests in web-unit run the CLI itself.
271 classes: cli: {
272 paths: "bin/valley": true
273 paths: "status/**": true
274 paths: "rebase/**": true
275 paths: "completions/**": true
276 requires: "valley-go-unit": true
277 requires: "valley-cli": true
278 requires: "review-notes": true
279 requires: "valley-request": true
280 requires: "valley-status": true
281 requires: "valley-ready": true
282 requires: "valley-changes": true
283 requires: "valley-knot": true
284 requires: "valley-plan": true
285 requires: "valley-self-update": true
286 requires: "policy-deriver": true
287 requires: "derive-unit": true
288 requires: "web-unit": true
289 }
290
291 // Self-update: its module (selfupdate/), the policy the package ships
292 // for its smoke test, and the home-manager module that runs it on a
293 // timer. valley-go-unit builds the verb with the module, and
294 // valley-self-update drives the verb through the package and holds the
295 // units the home-manager module renders.
296 classes: selfupdate: {
297 paths: "selfupdate/**": true
298 paths: "examples/policy/smoke/**": true
299 paths: "nix/home-module.nix": true
300 requires: "selfupdate-unit": true
301 requires: "valley-go-unit": true
302 requires: "valley-self-update": true
303 }
304
305 // The rebase engine, with its own tests over real repositories. The
306 // verbs that run it are the cli class's, so its paths are there too.
307 classes: rebase: {
308 paths: "rebase/**": true
309 requires: "rebase-unit": true
310 }
311
312 // The restacker, with its unit tests and its planner end to end. It
313 // reads origin through the rebase engine and the policy through the
314 // composed-policy reader it shares with the integrator, so a change to
315 // either requires its checks too.
316 classes: restack: {
317 paths: "restack/**": true
318 paths: "composed/**": true
319 paths: "rebase/**": true
320 requires: "restack-unit": true
321 requires: "restack-e2e": true
322 }
323
324 // What a client verifies an integrator's transfer statement with: the
325 // host's publisher and the default name it publishes, the unit that
326 // runs it, the client's reading of the signers, the instance discovery
327 // it reads them through, and the snapshot that asks for them.
328 // signers-e2e drives them together over the real integrator.
329 classes: signers: {
330 paths: "integrator/signers.go": true
331 paths: "integrator/main.go": true
332 paths: "nix/valley-host.nix": true
333 paths: "status/signers.go": true
334 paths: "status/list.go": true
335 paths: "rebase/snapshot.go": true
336 requires: "signers-e2e": true
337 }
338
339 // The web publisher's module, which runs the publisher on a timer in a
340 // sandbox of its own. web-publisher-e2e runs the unit it renders in a
341 // NixOS machine. module-eval, in the nix class, holds what it renders.
342 classes: "web-publisher": {
343 paths: "nix/web-publisher.nix": true
344 requires: "web-publisher-e2e": true
345 }
346
347 // The verification policy: this layer, the pointer to the owning
348 // valley, the schema a policy is written in, and the example policies
349 // the derivers and cue-vet read.
350 classes: policy: {
351 paths: "policy/**": true
352 paths: "schema/verification.cue": true
353 paths: "examples/policy/**": true
354 requires: "policy-deriver": true
355 requires: "derive-unit": true
356 requires: "cue-vet": true
357 requires: "own-policy": true
358 }
359
360 // The flake, the NixOS module, the packages and the check definitions,
361 // and the host declarations the module checks are evaluated over.
362 // own-policy is here because renaming or removing a flake check would
363 // leave this layer naming a check that no longer exists. A change to
364 // flake.nix or flake.lock requires these alone, so a nixpkgs bump boots no
365 // machine.
366 classes: nix: {
367 paths: "nix/**": true
368 paths: "flake.nix": true
369 paths: "flake.lock": true
370 paths: "examples/host.cue": true
371 paths: "examples/hosts/**": true
372 requires: "module-eval": true
373 requires: "valley-darwin-eval": true
374 requires: "cue-vet": true
375 requires: "own-policy": true
376 }
377
378 // The schemas, and the example events, attestations and registries they
379 // are vetted against.
380 classes: schema: {
381 paths: "schema/**": true
382 paths: "examples/events/**": true
383 paths: "examples/attestations/**": true
384 paths: "examples/identity/**": true
385 requires: "cue-vet": true
386 requires: "attest-schema": true
387 requires: "identity-schema": true
388 }
389
390 // The knowledge lint itself: its program, the node schema it holds a
391 // graph to, and the example graphs it must accept and reject. The plan
392 // graph's validator is held to the same two by knot-agree.
393 classes: "knowledge-lint": {
394 paths: "nix/knowledge-lint.*": true
395 paths: "schema/node.cue": true
396 paths: "examples/graphs/**": true
397 requires: "knowledge-lint-consumer": true
398 requires: "knowledge-lint-rejects": true
399 requires: "knot-agree": true
400 }
401
402 // The NixOS module and what its end-to-end checks run. The hook checks
403 // follow the scripts out of the hosts in nix/checks/hosts.nix, which
404 // are made of the three declarations named here; ssh-e2e, publish-e2e,
405 // worker-e2e and restack-host-e2e run the module in NixOS machines.
406 classes: "host-module": {
407 paths: "nix/valley-host.nix": true
408 paths: "nix/checks/hosts.nix": true
409 paths: "examples/hosts/protected.cue": true
410 paths: "examples/hosts/bus.cue": true
411 paths: "examples/hosts/mirrors.cue": true
412 requires: "init-e2e": true
413 requires: "mirror-e2e": true
414 requires: "bus-e2e": true
415 requires: "protect-e2e": true
416 requires: "knots-e2e": true
417 requires: "identity-e2e": true
418 requires: "ssh-e2e": true
419 requires: "publish-e2e": true
420 requires: "worker-e2e": true
421 requires: "restack-host-e2e": true
422 requires: "valley-changes": true
423 }
424
425 // A check's own files require that check: its script,
426 // nix/checks/<name>.sh, and its definition, nix/checks/<name>.nix,
427 // where it has a file of its own. One class per check, named
428 // check-<name>. prose-format is the floor's check, but its script is
429 // here. own-policy fails if a script under nix/checks/ requires no
430 // check.
431 for n in list.Concat([ownChecks, ["prose-format"]]) {
432 classes: ("check-\(n)"): {
433 paths: ("nix/checks/\(n).sh"): true
434 paths: ("nix/checks/\(n).nix"): true
435 requires: (n): true
436 }
437 }
438
439 // The other files under nix/checks/, and the checks that read each: the
440 // definitions of a subject's checks, and the helpers and rejection lists
441 // a check is given. cli.nix, which defines every check of bin/valley,
442 // is left to the nix class, as is nix/checks.nix, which wires them all.
443 let checkFiles = {
444 "attest.nix": ["attest-unit", "attest-conformance", "attest-e2e"]
445 "delta.nix": ["delta-unit"]
446 "derive.nix": ["derive-unit"]
447 "review.nix": ["review-unit"]
448 "identity.nix": ["identity-unit", "identity-e2e"]
449 "integrator.nix": ["integrator-unit", "integrator-e2e"]
450 "signers.nix": ["signers-e2e"]
451 "sigverify.nix": ["sigverify-unit", "sigverify-e2e"]
452 "web.nix": ["web-unit", "web-server-unit", "readaccess-unit"]
453 "schema.nix": ["cue-vet", "attest-schema", "identity-schema"]
454 "knowledge.nix": ["knowledge-lint-consumer", "knowledge-lint-rejects", "prose-format"]
455 "hooks.nix": ["valleyhook-unit", "change-unit", "mirror-e2e", "protect-e2e", "init-e2e", "bus-e2e"]
456 "host-module.nix": ["module-eval"]
457 "fail-nth.sh": ["policy-deriver", "valley-request"]
458 "review-notes-editor.sh": ["review-notes"]
459 "cue-vet-rejected.txt": ["cue-vet"]
460 "identity-rejected.txt": ["identity-schema"]
461 "knowledge-lint-rejected.txt": ["knowledge-lint-rejects"]
462 }
463 for f, ns in checkFiles {
464 classes: ("check-file-\(strings.Replace(f, ".", "-", -1))"): {
465 paths: ("nix/checks/\(f)"): true
466 requires: {for n in ns {(n): true}}
467 }
468 }
469
470 // How far an approval carries across a rebase (#Carry in
471 // schema/verification.cue). Every path not named here is same-paths.
472 //
473 // The hook, the integrator, the signature verifier and the identity
474 // compiler enforce who may do what. An approval of a change to one of
475 // them carries only while no landing has touched the same classes:
476 // same-class. The identity compiler's class is its code and the schema
477 // it holds a registry to. It requires nothing, because the identity and
478 // schema classes already require the checks of its paths.
479 classes: valleyhook: carry: "same-class": true
480 classes: integrator: carry: "same-class": true
481 classes: sigverify: carry: "same-class": true
482 classes: "identity-compiler": {
483 paths: "identity/**": true
484 paths: "schema/identity.cue": true
485 carry: "same-class": true
486 }
487
488 // The policy decides what every change requires, so an approval of a
489 // change to it carries across no landing at all: exact. That is this
490 // layer, the pointer to the owning valley, and the schema a policy is
491 // written in. The example policies are fixtures and stay same-paths. Like
492 // identity-compiler, this class requires nothing: the policy class
493 // requires the checks of its paths.
494 //
495 // This tree holds no registry, grant or secret data of its own. The
496 // registries, grants and keys under examples/ and attest/conformance/
497 // are test fixtures, and the instance's registry is in its instance
498 // repository. So nothing else here is exact.
499 classes: "policy-authority": {
500 paths: "policy/**": true
501 paths: "schema/verification.cue": true
502 carry: exact: true
503 }
504
505 // The restacker's cap is the schema's default of 64 automatic versions
506 // per change.
507}
508
509// What no class above covers falls to the floor's `unclassified` rule and
510// requires prose-format alone. That is the research artefacts under research/,
511// the GitHub mirror's workflow under .github/, and editor settings: files
512// no program here reads.