gunk-dev/the-valley

policy.cue

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