gunk-dev/the-valley

policy.cue

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