gunk-dev/the-valley

policy.cue

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