gunk-dev/the-valley

policy.cue

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