gunk-dev/the-valley

policy.cue

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