gunk-dev/the-valley

policy.cue

source822cb119f57bmain's published tip history
10.8 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 keeps a knowledge graph, so it takes the lint the docs
14 // template offers rather than declining it.
15 #docs
16
17 // The graph is archived under archive/.the-valley/, which the
18 // template's `.the-valley/**` does not reach, so the knowledge class
19 // adds the archived path. nix/checks/knowledge.nix lints that root.
20 classes: knowledge: paths: "archive/.the-valley/**": true
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 "attest-unit",
35 "attest-conformance",
36 "attest-e2e",
37 "identity-unit",
38 "identity-e2e",
39 "integrator-unit",
40 "integrator-e2e",
41 "sigverify-unit",
42 "sigverify-e2e",
43 "valley-go-unit",
44 "valley-cli",
45 "review-notes",
46 "valley-request",
47 "valley-status",
48 "valley-ready",
49 "valley-changes",
50 "valley-knot",
51 "valley-plan",
52 "valley-darwin-eval",
53 "policy-deriver",
54 "own-policy",
55 "module-eval",
56 "cue-vet",
57 "attest-schema",
58 "identity-schema",
59 "knowledge-lint-consumer",
60 "knowledge-lint-rejects",
61 "init-e2e",
62 "mirror-e2e",
63 "bus-e2e",
64 "ssh-e2e",
65 "publish-e2e",
66 ]
67 for n in ownChecks {
68 checks: (n): {
69 runner: "nix"
70 attribute: n
71 }
72 }
73
74 // The integrator's scenarios take about a minute, and ssh-e2e and
75 // publish-e2e boot NixOS machines. Every other check here takes seconds
76 // once its packages are built.
77 checks: "integrator-e2e": cost: "slow"
78 checks: "ssh-e2e": cost: "slow"
79 checks: "publish-e2e": cost: "slow"
80
81 // Each class below is one part of the tree and the checks that read it.
82 // A path in two classes requires both sets. A Go module's unit check is its
83 // package, whose checkPhase runs `go test`.
84
85 // The pre-receive hook and the git user's login shell. protect-e2e
86 // pushes to bare repositories wired with the hook a host renders,
87 // valley-ready pushes change records through that hook, and knots-e2e
88 // pushes the plan graph through it.
89 classes: valleyhook: {
90 paths: "valleyhook/**": true
91 requires: "valleyhook-unit": true
92 requires: "protect-e2e": true
93 requires: "valley-ready": true
94 requires: "knots-e2e": true
95 }
96
97 // The change record, which the hook guards, the CLI's Go verbs write and
98 // the integrator reads. Each reads a record through it, so a change to
99 // it requires their tests as well as its own.
100 classes: change: {
101 paths: "change/**": true
102 requires: "change-unit": true
103 requires: "valleyhook-unit": true
104 requires: "protect-e2e": true
105 requires: "valley-go-unit": true
106 requires: "valley-ready": true
107 requires: "valley-changes": true
108 requires: "integrator-unit": true
109 requires: "integrator-e2e": true
110 }
111
112 // The plan graph's module, which the CLI's Go verbs write the graph
113 // with and the hook validates it with. knot-agree holds its validator
114 // to the node schema and the knowledge lint, valley-knot and
115 // valley-plan drive the verbs that use it, and knots-e2e pushes
116 // through the hook.
117 classes: knot: {
118 paths: "knot/**": true
119 requires: "knot-unit": true
120 requires: "knot-agree": true
121 requires: "valley-go-unit": true
122 requires: "valley-knot": true
123 requires: "valley-plan": true
124 requires: "valleyhook-unit": true
125 requires: "knots-e2e": true
126 }
127
128 // The note envelope. The hook and attest both read notes through it, so
129 // a change to it requires their tests as well as its own.
130 classes: note: {
131 paths: "note/**": true
132 requires: "note-unit": true
133 requires: "valleyhook-unit": true
134 requires: "protect-e2e": true
135 requires: "attest-unit": true
136 requires: "attest-e2e": true
137 }
138
139 // The attestation helper, and the conformance vectors under
140 // attest/conformance/ that hold its written form fixed.
141 classes: attest: {
142 paths: "attest/**": true
143 requires: "attest-unit": true
144 requires: "attest-conformance": true
145 requires: "attest-e2e": true
146 }
147
148 // The identity registry compiler, and the registries it is driven over.
149 classes: identity: {
150 paths: "identity/**": true
151 paths: "examples/identity/**": true
152 requires: "identity-unit": true
153 requires: "identity-e2e": true
154 }
155
156 // The integrator, and the end-to-end scenarios under integrator/e2e/.
157 classes: integrator: {
158 paths: "integrator/**": true
159 requires: "integrator-unit": true
160 requires: "integrator-e2e": true
161 }
162
163 // The security-key signature verifier.
164 classes: sigverify: {
165 paths: "sigverify/**": true
166 requires: "sigverify-unit": true
167 requires: "sigverify-e2e": true
168 }
169
170 // The valley CLI: the script, its Go verbs (status/), and its
171 // completions. valley-ready drives ready, withdraw and the verbs that
172 // take a change's handle, valley-changes drives changes and pending,
173 // and valley-plan drives plan against the golden files under
174 // status/testdata/plan/.
175 classes: cli: {
176 paths: "bin/valley": true
177 paths: "status/**": true
178 paths: "completions/**": true
179 requires: "valley-go-unit": true
180 requires: "valley-cli": true
181 requires: "review-notes": true
182 requires: "valley-request": true
183 requires: "valley-status": true
184 requires: "valley-ready": true
185 requires: "valley-changes": true
186 requires: "valley-knot": true
187 requires: "valley-plan": true
188 requires: "policy-deriver": true
189 }
190
191 // The verification policy: this layer, the pointer to the owning
192 // valley, the schema a policy is written in, and the example policies
193 // the deriver and cue-vet read.
194 classes: policy: {
195 paths: "policy/**": true
196 paths: "schema/verification.cue": true
197 paths: "examples/policy/**": true
198 requires: "policy-deriver": true
199 requires: "cue-vet": true
200 requires: "own-policy": true
201 }
202
203 // The flake, the NixOS module, the packages and the check definitions,
204 // and the host declarations the module checks are evaluated over.
205 // own-policy is here because renaming or removing a flake check would
206 // leave this layer naming a check that no longer exists. A change to
207 // flake.nix or flake.lock requires these alone, so a nixpkgs bump boots no
208 // machine.
209 classes: nix: {
210 paths: "nix/**": true
211 paths: "flake.nix": true
212 paths: "flake.lock": true
213 paths: "examples/host.cue": true
214 paths: "examples/hosts/**": true
215 requires: "module-eval": true
216 requires: "valley-darwin-eval": true
217 requires: "cue-vet": true
218 requires: "own-policy": true
219 }
220
221 // The schemas, and the example events, attestations and registries they
222 // are vetted against.
223 classes: schema: {
224 paths: "schema/**": true
225 paths: "examples/events/**": true
226 paths: "examples/attestations/**": true
227 paths: "examples/identity/**": true
228 requires: "cue-vet": true
229 requires: "attest-schema": true
230 requires: "identity-schema": true
231 }
232
233 // The knowledge lint itself: its program, the node schema it holds a
234 // graph to, and the example graphs it must accept and reject. The plan
235 // graph's validator is held to the same two by knot-agree.
236 classes: "knowledge-lint": {
237 paths: "nix/knowledge-lint.*": true
238 paths: "schema/node.cue": true
239 paths: "examples/graphs/**": true
240 requires: "knowledge-lint": true
241 requires: "knowledge-lint-consumer": true
242 requires: "knowledge-lint-rejects": true
243 requires: "knot-agree": true
244 }
245
246 // The NixOS module and what its end-to-end checks run. The hook checks
247 // follow the scripts out of the hosts in nix/checks/hosts.nix, which
248 // are made of the three declarations named here; ssh-e2e and
249 // publish-e2e run the module in NixOS machines.
250 classes: "host-module": {
251 paths: "nix/valley-host.nix": true
252 paths: "nix/checks/hosts.nix": true
253 paths: "examples/hosts/protected.cue": true
254 paths: "examples/hosts/bus.cue": true
255 paths: "examples/hosts/mirrors.cue": true
256 requires: "init-e2e": true
257 requires: "mirror-e2e": true
258 requires: "bus-e2e": true
259 requires: "protect-e2e": true
260 requires: "knots-e2e": true
261 requires: "identity-e2e": true
262 requires: "ssh-e2e": true
263 requires: "publish-e2e": true
264 requires: "valley-changes": true
265 }
266
267 // A check's own files require that check: its script,
268 // nix/checks/<name>.sh, and its definition, nix/checks/<name>.nix,
269 // where it has a file of its own. One class per check, named
270 // check-<name>. prose-format is the floor's check, but its script is
271 // here. own-policy fails if a script under nix/checks/ requires no
272 // check.
273 for n in list.Concat([ownChecks, ["prose-format"]]) {
274 classes: ("check-\(n)"): {
275 paths: ("nix/checks/\(n).sh"): true
276 paths: ("nix/checks/\(n).nix"): true
277 requires: (n): true
278 }
279 }
280
281 // The other files under nix/checks/, and the checks that read each: the
282 // definitions of a subject's checks, and the helpers and rejection lists
283 // a check is given. cli.nix, which defines every check of bin/valley,
284 // is left to the nix class, as is nix/checks.nix, which wires them all.
285 let checkFiles = {
286 "attest.nix": ["attest-unit", "attest-conformance", "attest-e2e"]
287 "identity.nix": ["identity-unit", "identity-e2e"]
288 "integrator.nix": ["integrator-unit", "integrator-e2e"]
289 "sigverify.nix": ["sigverify-unit", "sigverify-e2e"]
290 "schema.nix": ["cue-vet", "attest-schema", "identity-schema"]
291 "knowledge.nix": ["knowledge-lint", "knowledge-lint-consumer", "knowledge-lint-rejects", "prose-format"]
292 "hooks.nix": ["valleyhook-unit", "change-unit", "mirror-e2e", "protect-e2e", "init-e2e", "bus-e2e"]
293 "host-module.nix": ["module-eval"]
294 "fail-nth.sh": ["policy-deriver", "valley-request"]
295 "review-notes-editor.sh": ["review-notes"]
296 "cue-vet-rejected.txt": ["cue-vet"]
297 "identity-rejected.txt": ["identity-schema"]
298 "knowledge-lint-rejected.txt": ["knowledge-lint-rejects"]
299 }
300 for f, ns in checkFiles {
301 classes: ("check-file-\(strings.Replace(f, ".", "-", -1))"): {
302 paths: ("nix/checks/\(f)"): true
303 requires: {for n in ns {(n): true}}
304 }
305 }
306}
307
308// What no class above covers falls to the floor's `unclassified` rule and
309// requires prose-format alone. That is the research artefacts under research/,
310// the GitHub mirror's workflow under .github/, and editor settings: files
311// no program here reads.