gunk-dev/the-valley

policy.cue

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