gunk-dev/the-valley

policy.cue

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