gunk-dev/the-valley

policy.cue

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