gunk-dev/the-valley

policy.cue

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