gunk-dev/the-valley

policy.cue

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