gunk-dev/the-valley

policy.cue

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