gunk-dev/the-valley

policy.cue

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