gunk-dev/the-valley

policy.cue

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