gunk-dev/the-valley

policy.cue

source782170038f7fmain's published tip history
21.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 "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 // Read access: the two consents a reader needs, the evaluator that
289 // intersects them, and the coverage report. readaccess-unit reads both
290 // schemas, so a change to either requires it, and the web publisher
291 // reads its consents through the module, so web-unit runs too.
292 classes: readaccess: {
293 paths: "readaccess/**": true
294 paths: "schema/read.cue": true
295 paths: "schema/identity.cue": true
296 requires: "readaccess-unit": true
297 requires: "web-unit": true
298 }
299
300 // The valley CLI: the script, its Go verbs (status/), the rebase engine
301 // they rebase and read landings with (rebase/), and its completions.
302 // valley-ready drives ready, withdraw, rebase and the verbs that take a
303 // change's handle, valley-changes drives changes and pending,
304 // valley-plan drives plan against the golden files under
305 // status/testdata/plan/, and valley-self-update drives --version and
306 // self-update. derive-unit holds the script's deriver to the Go one.
307 // The web publisher reads the valley through plan, pending and knot
308 // show, and its tests in web-unit run the CLI itself, as web-push-e2e
309 // runs the CLI's package.
310 classes: cli: {
311 paths: "bin/valley": true
312 paths: "status/**": true
313 paths: "rebase/**": true
314 paths: "completions/**": true
315 requires: "valley-go-unit": true
316 requires: "valley-cli": true
317 requires: "review-notes": true
318 requires: "valley-request": true
319 requires: "valley-status": true
320 requires: "valley-ready": true
321 requires: "valley-changes": true
322 requires: "valley-knot": true
323 requires: "valley-plan": true
324 requires: "valley-self-update": true
325 requires: "policy-deriver": true
326 requires: "derive-unit": true
327 requires: "web-unit": true
328 requires: "web-push-e2e": true
329 }
330
331 // The push path as it ships: web-push-e2e runs the publisher, the
332 // receiver, valley-web and the CLI as nix/packages.nix builds and wraps
333 // them, and exports its host declaration under schema/valley.cue. The
334 // web and cli classes require it for the code it runs.
335 classes: "web-push": {
336 paths: "nix/packages.nix": true
337 paths: "schema/valley.cue": true
338 requires: "web-push-e2e": true
339 }
340
341 // Self-update: its module (selfupdate/), the policy the package ships
342 // for its smoke test, and the home-manager module that runs it on a
343 // timer. valley-go-unit builds the verb with the module, and
344 // valley-self-update drives the verb through the package and holds the
345 // units the home-manager module renders.
346 classes: selfupdate: {
347 paths: "selfupdate/**": true
348 paths: "examples/policy/smoke/**": true
349 paths: "nix/home-module.nix": true
350 requires: "selfupdate-unit": true
351 requires: "valley-go-unit": true
352 requires: "valley-self-update": true
353 }
354
355 // The rebase engine, with its own tests over real repositories. The
356 // verbs that run it are the cli class's, so its paths are there too.
357 classes: rebase: {
358 paths: "rebase/**": true
359 requires: "rebase-unit": true
360 }
361
362 // The restacker, with its unit tests and its planner end to end. It
363 // reads origin through the rebase engine and the policy through the
364 // composed-policy reader it shares with the integrator, so a change to
365 // either requires its checks too.
366 classes: restack: {
367 paths: "restack/**": true
368 paths: "composed/**": true
369 paths: "rebase/**": true
370 requires: "restack-unit": true
371 requires: "restack-e2e": true
372 }
373
374 // What a client verifies an integrator's transfer statement with: the
375 // host's publisher and the default name it publishes, the unit that
376 // runs it, the client's reading of the signers, the instance discovery
377 // it reads them through, and the snapshot that asks for them.
378 // signers-e2e drives them together over the real integrator.
379 classes: signers: {
380 paths: "integrator/signers.go": true
381 paths: "integrator/main.go": true
382 paths: "nix/valley-host.nix": true
383 paths: "status/signers.go": true
384 paths: "status/list.go": true
385 paths: "rebase/snapshot.go": true
386 requires: "signers-e2e": true
387 }
388
389 // The web publisher's module, which runs the publisher on a timer in a
390 // sandbox of its own. web-publisher-e2e runs the unit it renders in a
391 // NixOS machine. module-eval, in the nix class, holds what it renders.
392 classes: "web-publisher": {
393 paths: "nix/web-publisher.nix": true
394 requires: "web-publisher-e2e": true
395 }
396
397 // The verification policy: this layer, the pointer to the owning
398 // valley, the schema a policy is written in, and the example policies
399 // the derivers and cue-vet read.
400 classes: policy: {
401 paths: "policy/**": true
402 paths: "schema/verification.cue": true
403 paths: "examples/policy/**": true
404 requires: "policy-deriver": true
405 requires: "derive-unit": true
406 requires: "cue-vet": true
407 requires: "own-policy": true
408 }
409
410 // The flake, the NixOS module, the packages and the check definitions,
411 // and the host declarations the module checks are evaluated over.
412 // own-policy is here because renaming or removing a flake check would
413 // leave this layer naming a check that no longer exists. A change to
414 // flake.nix or flake.lock requires these alone, so a nixpkgs bump boots no
415 // machine.
416 classes: nix: {
417 paths: "nix/**": true
418 paths: "flake.nix": true
419 paths: "flake.lock": true
420 paths: "examples/host.cue": true
421 paths: "examples/hosts/**": true
422 requires: "module-eval": true
423 requires: "valley-darwin-eval": true
424 requires: "cue-vet": true
425 requires: "own-policy": true
426 }
427
428 // The schemas, and the example events, attestations and registries they
429 // are vetted against.
430 classes: schema: {
431 paths: "schema/**": true
432 paths: "examples/events/**": true
433 paths: "examples/attestations/**": true
434 paths: "examples/identity/**": true
435 requires: "cue-vet": true
436 requires: "attest-schema": true
437 requires: "identity-schema": true
438 }
439
440 // The knowledge lint itself: its program, the node schema it holds a
441 // graph to, and the example graphs it must accept and reject. The plan
442 // graph's validator is held to the same two by knot-agree.
443 classes: "knowledge-lint": {
444 paths: "nix/knowledge-lint.*": true
445 paths: "schema/node.cue": true
446 paths: "examples/graphs/**": true
447 requires: "knowledge-lint-consumer": true
448 requires: "knowledge-lint-rejects": true
449 requires: "knot-agree": true
450 }
451
452 // The NixOS module and what its end-to-end checks run. The hook checks
453 // follow the scripts out of the hosts in nix/checks/hosts.nix, which
454 // are made of the three declarations named here; ssh-e2e, publish-e2e,
455 // worker-e2e and restack-host-e2e run the module in NixOS machines.
456 classes: "host-module": {
457 paths: "nix/valley-host.nix": true
458 paths: "nix/checks/hosts.nix": true
459 paths: "examples/hosts/protected.cue": true
460 paths: "examples/hosts/bus.cue": true
461 paths: "examples/hosts/mirrors.cue": true
462 requires: "init-e2e": true
463 requires: "mirror-e2e": true
464 requires: "bus-e2e": true
465 requires: "protect-e2e": true
466 requires: "knots-e2e": true
467 requires: "identity-e2e": true
468 requires: "ssh-e2e": true
469 requires: "publish-e2e": true
470 requires: "worker-e2e": true
471 requires: "restack-host-e2e": true
472 requires: "valley-changes": true
473 }
474
475 // A check's own files require that check: its script,
476 // nix/checks/<name>.sh, and its definition, nix/checks/<name>.nix,
477 // where it has a file of its own. One class per check, named
478 // check-<name>. prose-format is the floor's check, but its script is
479 // here. own-policy fails if a script under nix/checks/ requires no
480 // check.
481 for n in list.Concat([ownChecks, ["prose-format"]]) {
482 classes: ("check-\(n)"): {
483 paths: ("nix/checks/\(n).sh"): true
484 paths: ("nix/checks/\(n).nix"): true
485 requires: (n): true
486 }
487 }
488
489 // The other files under nix/checks/, and the checks that read each: the
490 // definitions of a subject's checks, and the helpers and rejection lists
491 // a check is given. cli.nix, which defines every check of bin/valley,
492 // is left to the nix class, as is nix/checks.nix, which wires them all.
493 let checkFiles = {
494 "attest.nix": ["attest-unit", "attest-conformance", "attest-e2e"]
495 "delta.nix": ["delta-unit"]
496 "derive.nix": ["derive-unit"]
497 "review.nix": ["review-unit"]
498 "identity.nix": ["identity-unit", "identity-e2e"]
499 "integrator.nix": ["integrator-unit", "integrator-e2e"]
500 "signers.nix": ["signers-e2e"]
501 "sigverify.nix": ["sigverify-unit", "sigverify-e2e"]
502 "web.nix": ["web-unit", "web-server-unit", "web-reader-state-crash", "web-receiver-unit", "web-image", "readaccess-unit"]
503 "schema.nix": ["cue-vet", "attest-schema", "identity-schema"]
504 "knowledge.nix": ["knowledge-lint-consumer", "knowledge-lint-rejects", "prose-format"]
505 "hooks.nix": ["valleyhook-unit", "change-unit", "mirror-e2e", "protect-e2e", "init-e2e", "bus-e2e"]
506 "host-module.nix": ["module-eval"]
507 "fail-nth.sh": ["policy-deriver", "valley-request"]
508 "review-notes-editor.sh": ["review-notes"]
509 "cue-vet-rejected.txt": ["cue-vet"]
510 "identity-rejected.txt": ["identity-schema"]
511 "knowledge-lint-rejected.txt": ["knowledge-lint-rejects"]
512 }
513 for f, ns in checkFiles {
514 classes: ("check-file-\(strings.Replace(f, ".", "-", -1))"): {
515 paths: ("nix/checks/\(f)"): true
516 requires: {for n in ns {(n): true}}
517 }
518 }
519
520 // How far an approval carries across a rebase (#Carry in
521 // schema/verification.cue). Every path not named here is same-paths.
522 //
523 // The hook, the integrator, the signature verifier and the identity
524 // compiler enforce who may do what. An approval of a change to one of
525 // them carries only while no landing has touched the same classes:
526 // same-class. The identity compiler's class is its code and the schema
527 // it holds a registry to. It requires nothing, because the identity and
528 // schema classes already require the checks of its paths.
529 classes: valleyhook: carry: "same-class": true
530 classes: integrator: carry: "same-class": true
531 classes: sigverify: carry: "same-class": true
532 classes: "identity-compiler": {
533 paths: "identity/**": true
534 paths: "schema/identity.cue": true
535 carry: "same-class": true
536 }
537
538 // The policy decides what every change requires, so an approval of a
539 // change to it carries across no landing at all: exact. That is this
540 // layer, the pointer to the owning valley, and the schema a policy is
541 // written in. The example policies are fixtures and stay same-paths. Like
542 // identity-compiler, this class requires nothing: the policy class
543 // requires the checks of its paths.
544 //
545 // This tree holds no registry, grant or secret data of its own. The
546 // registries, grants and keys under examples/ and attest/conformance/
547 // are test fixtures, and the instance's registry is in its instance
548 // repository. So nothing else here is exact.
549 classes: "policy-authority": {
550 paths: "policy/**": true
551 paths: "schema/verification.cue": true
552 carry: exact: true
553 }
554
555 // The restacker's cap is the schema's default of 64 automatic versions
556 // per change.
557}
558
559// What no class above covers falls to the floor's `unclassified` rule and
560// requires prose-format alone. That is the research artefacts under research/,
561// the GitHub mirror's workflow under .github/, and editor settings: files
562// no program here reads.