gunk-dev/the-valley

policy.cue

source4f919451c78bmain's published tip history
16.8 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,
173 // and the identity compiler reads its approval files back with it, so a
174 // change to it requires their tests as well as its own.
175 classes: note: {
176 paths: "note/**": true
177 requires: "note-unit": true
178 requires: "valleyhook-unit": true
179 requires: "protect-e2e": true
180 requires: "attest-unit": true
181 requires: "attest-e2e": true
182 requires: "identity-unit": true
183 }
184
185 // The attestation helper, and the conformance vectors under
186 // attest/conformance/ that hold its written form fixed.
187 classes: attest: {
188 paths: "attest/**": true
189 requires: "attest-unit": true
190 requires: "attest-conformance": true
191 requires: "attest-e2e": true
192 }
193
194 // The identity registry compiler, and the registries it is driven over.
195 classes: identity: {
196 paths: "identity/**": true
197 paths: "examples/identity/**": true
198 requires: "identity-unit": true
199 requires: "identity-e2e": true
200 }
201
202 // The integrator, the end-to-end scenarios under integrator/e2e/, and the
203 // verification schema, which the integrator composes every policy under
204 // and both checks read.
205 classes: integrator: {
206 paths: "integrator/**": true
207 paths: "composed/**": true
208 paths: "schema/verification.cue": true
209 requires: "integrator-unit": true
210 requires: "integrator-e2e": true
211 }
212
213 // The security-key signature verifier.
214 classes: sigverify: {
215 paths: "sigverify/**": true
216 requires: "sigverify-unit": true
217 requires: "sigverify-e2e": true
218 }
219
220 // The valley CLI: the script, its Go verbs (status/), the rebase engine
221 // they rebase and read landings with (rebase/), and its completions.
222 // valley-ready drives ready, withdraw, rebase and the verbs that take a
223 // change's handle, valley-changes drives changes and pending,
224 // valley-plan drives plan against the golden files under
225 // status/testdata/plan/, and valley-self-update drives --version and
226 // self-update. derive-unit holds the script's deriver to the Go one.
227 classes: cli: {
228 paths: "bin/valley": true
229 paths: "status/**": true
230 paths: "rebase/**": true
231 paths: "completions/**": true
232 requires: "valley-go-unit": true
233 requires: "valley-cli": true
234 requires: "review-notes": true
235 requires: "valley-request": true
236 requires: "valley-status": true
237 requires: "valley-ready": true
238 requires: "valley-changes": true
239 requires: "valley-knot": true
240 requires: "valley-plan": true
241 requires: "valley-self-update": true
242 requires: "policy-deriver": true
243 requires: "derive-unit": true
244 }
245
246 // Self-update: its module (selfupdate/), the policy the package ships
247 // for its smoke test, and the home-manager module that runs it on a
248 // timer. valley-go-unit builds the verb with the module, and
249 // valley-self-update drives the verb through the package and holds the
250 // units the home-manager module renders.
251 classes: selfupdate: {
252 paths: "selfupdate/**": true
253 paths: "examples/policy/smoke/**": true
254 paths: "nix/home-module.nix": true
255 requires: "selfupdate-unit": true
256 requires: "valley-go-unit": true
257 requires: "valley-self-update": true
258 }
259
260 // The rebase engine, with its own tests over real repositories. The
261 // verbs that run it are the cli class's, so its paths are there too.
262 classes: rebase: {
263 paths: "rebase/**": true
264 requires: "rebase-unit": true
265 }
266
267 // The restacker, with its unit tests and its planner end to end. It
268 // reads origin through the rebase engine and the policy through the
269 // composed-policy reader it shares with the integrator, so a change to
270 // either requires its checks too.
271 classes: restack: {
272 paths: "restack/**": true
273 paths: "composed/**": true
274 paths: "rebase/**": true
275 requires: "restack-unit": true
276 requires: "restack-e2e": true
277 }
278
279 // What a client verifies an integrator's transfer statement with: the
280 // host's publisher and the default name it publishes, the unit that
281 // runs it, the client's reading of the signers, the instance discovery
282 // it reads them through, and the snapshot that asks for them.
283 // signers-e2e drives them together over the real integrator.
284 classes: signers: {
285 paths: "integrator/signers.go": true
286 paths: "integrator/main.go": true
287 paths: "nix/valley-host.nix": true
288 paths: "status/signers.go": true
289 paths: "status/list.go": true
290 paths: "rebase/snapshot.go": true
291 requires: "signers-e2e": true
292 }
293
294 // The verification policy: this layer, the pointer to the owning
295 // valley, the schema a policy is written in, and the example policies
296 // the derivers and cue-vet read.
297 classes: policy: {
298 paths: "policy/**": true
299 paths: "schema/verification.cue": true
300 paths: "examples/policy/**": true
301 requires: "policy-deriver": true
302 requires: "derive-unit": true
303 requires: "cue-vet": true
304 requires: "own-policy": true
305 }
306
307 // The flake, the NixOS module, the packages and the check definitions,
308 // and the host declarations the module checks are evaluated over.
309 // own-policy is here because renaming or removing a flake check would
310 // leave this layer naming a check that no longer exists. A change to
311 // flake.nix or flake.lock requires these alone, so a nixpkgs bump boots no
312 // machine.
313 classes: nix: {
314 paths: "nix/**": true
315 paths: "flake.nix": true
316 paths: "flake.lock": true
317 paths: "examples/host.cue": true
318 paths: "examples/hosts/**": true
319 requires: "module-eval": true
320 requires: "valley-darwin-eval": true
321 requires: "cue-vet": true
322 requires: "own-policy": true
323 }
324
325 // The schemas, and the example events, attestations and registries they
326 // are vetted against.
327 classes: schema: {
328 paths: "schema/**": true
329 paths: "examples/events/**": true
330 paths: "examples/attestations/**": true
331 paths: "examples/identity/**": true
332 requires: "cue-vet": true
333 requires: "attest-schema": true
334 requires: "identity-schema": true
335 }
336
337 // The knowledge lint itself: its program, the node schema it holds a
338 // graph to, and the example graphs it must accept and reject. The plan
339 // graph's validator is held to the same two by knot-agree.
340 classes: "knowledge-lint": {
341 paths: "nix/knowledge-lint.*": true
342 paths: "schema/node.cue": true
343 paths: "examples/graphs/**": true
344 requires: "knowledge-lint-consumer": true
345 requires: "knowledge-lint-rejects": true
346 requires: "knot-agree": true
347 }
348
349 // The NixOS module and what its end-to-end checks run. The hook checks
350 // follow the scripts out of the hosts in nix/checks/hosts.nix, which
351 // are made of the three declarations named here; ssh-e2e and
352 // publish-e2e run the module in NixOS machines.
353 classes: "host-module": {
354 paths: "nix/valley-host.nix": true
355 paths: "nix/checks/hosts.nix": true
356 paths: "examples/hosts/protected.cue": true
357 paths: "examples/hosts/bus.cue": true
358 paths: "examples/hosts/mirrors.cue": true
359 requires: "init-e2e": true
360 requires: "mirror-e2e": true
361 requires: "bus-e2e": true
362 requires: "protect-e2e": true
363 requires: "knots-e2e": true
364 requires: "identity-e2e": true
365 requires: "ssh-e2e": true
366 requires: "publish-e2e": true
367 requires: "valley-changes": true
368 }
369
370 // A check's own files require that check: its script,
371 // nix/checks/<name>.sh, and its definition, nix/checks/<name>.nix,
372 // where it has a file of its own. One class per check, named
373 // check-<name>. prose-format is the floor's check, but its script is
374 // here. own-policy fails if a script under nix/checks/ requires no
375 // check.
376 for n in list.Concat([ownChecks, ["prose-format"]]) {
377 classes: ("check-\(n)"): {
378 paths: ("nix/checks/\(n).sh"): true
379 paths: ("nix/checks/\(n).nix"): true
380 requires: (n): true
381 }
382 }
383
384 // The other files under nix/checks/, and the checks that read each: the
385 // definitions of a subject's checks, and the helpers and rejection lists
386 // a check is given. cli.nix, which defines every check of bin/valley,
387 // is left to the nix class, as is nix/checks.nix, which wires them all.
388 let checkFiles = {
389 "attest.nix": ["attest-unit", "attest-conformance", "attest-e2e"]
390 "delta.nix": ["delta-unit"]
391 "derive.nix": ["derive-unit"]
392 "review.nix": ["review-unit"]
393 "identity.nix": ["identity-unit", "identity-e2e"]
394 "integrator.nix": ["integrator-unit", "integrator-e2e"]
395 "signers.nix": ["signers-e2e"]
396 "sigverify.nix": ["sigverify-unit", "sigverify-e2e"]
397 "schema.nix": ["cue-vet", "attest-schema", "identity-schema"]
398 "knowledge.nix": ["knowledge-lint-consumer", "knowledge-lint-rejects", "prose-format"]
399 "hooks.nix": ["valleyhook-unit", "change-unit", "mirror-e2e", "protect-e2e", "init-e2e", "bus-e2e"]
400 "host-module.nix": ["module-eval"]
401 "fail-nth.sh": ["policy-deriver", "valley-request"]
402 "review-notes-editor.sh": ["review-notes"]
403 "cue-vet-rejected.txt": ["cue-vet"]
404 "identity-rejected.txt": ["identity-schema"]
405 "knowledge-lint-rejected.txt": ["knowledge-lint-rejects"]
406 }
407 for f, ns in checkFiles {
408 classes: ("check-file-\(strings.Replace(f, ".", "-", -1))"): {
409 paths: ("nix/checks/\(f)"): true
410 requires: {for n in ns {(n): true}}
411 }
412 }
413
414 // How far an approval carries across a rebase (#Carry in
415 // schema/verification.cue). Every path not named here is same-paths.
416 //
417 // The hook, the integrator, the signature verifier and the identity
418 // compiler enforce who may do what. An approval of a change to one of
419 // them carries only while no landing has touched the same classes:
420 // same-class. The identity compiler's class is its code and the schema
421 // it holds a registry to. It requires nothing, because the identity and
422 // schema classes already require the checks of its paths.
423 classes: valleyhook: carry: "same-class": true
424 classes: integrator: carry: "same-class": true
425 classes: sigverify: carry: "same-class": true
426 classes: "identity-compiler": {
427 paths: "identity/**": true
428 paths: "schema/identity.cue": true
429 carry: "same-class": true
430 }
431
432 // The policy decides what every change requires, so an approval of a
433 // change to it carries across no landing at all: exact. That is this
434 // layer, the pointer to the owning valley, and the schema a policy is
435 // written in. The example policies are fixtures and stay same-paths. Like
436 // identity-compiler, this class requires nothing: the policy class
437 // requires the checks of its paths.
438 //
439 // This tree holds no registry, grant or secret data of its own. The
440 // registries, grants and keys under examples/ and attest/conformance/
441 // are test fixtures, and the instance's registry is in its instance
442 // repository. So nothing else here is exact.
443 classes: "policy-authority": {
444 paths: "policy/**": true
445 paths: "schema/verification.cue": true
446 carry: exact: true
447 }
448
449 // The restacker's cap is the schema's default of 64 automatic versions
450 // per change.
451}
452
453// What no class above covers falls to the floor's `unclassified` rule and
454// requires prose-format alone. That is the research artefacts under research/,
455// the GitHub mirror's workflow under .github/, and editor settings: files
456// no program here reads.