gunk-dev/the-valley

policy.cue

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