gunk-dev/the-valley

policy.cue

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