gunk-dev/the-valley

hosts.nix

sourcedd85a8e116a8main's published tip history
19.1 KiB
1# The hosts the module checks are about: eval-only instantiations of the
2# NixOS module, one per declaration worth holding it to. Evaluating one
3# catches option-surface and cue-export regressions without building or
4# booting anything, and the hook checks read the scripts these render.
5{
6 pkgs,
7 lib,
8 self,
9 # Whether the hosts run stand-ins for this flake's programs rather than
10 # the programs themselves.
11 stubbed ? false,
12}:
13let
14 # The stand-ins: the integrator, the identity compiler, valleyhook and
15 # the restacker, each a script with the program's name that fails if
16 # anything runs it.
17 # A host rendered over them renders the same units, hooks and scripts,
18 # with the stand-ins' store paths where the programs' would be. None of
19 # them changes when a program does, so a check that reads only what the
20 # module renders changes only when the module or the check does. A check
21 # that runs a program takes the hosts that run the real one.
22 stub =
23 name:
24 pkgs.writeShellScriptBin name ''
25 echo "${name}: a stand-in the module checks render hosts over, which runs nothing" >&2
26 exit 1
27 '';
28 stubs = lib.genAttrs [ "integrator" "identity" "valleyhook" ] stub // {
29 restacker = stub "valley-restacker";
30 };
31
32 # Each check host shares the machine baseline and supplies its own
33 # declaration (and, where the declaration asks for backup, the secret
34 # paths).
35 #
36 # Each host is also handed the package set the checks already use,
37 # rather than importing nixpkgs again for itself. It is the same nixpkgs
38 # with the same configuration, so every host renders the same
39 # derivations. module-eval evaluates every host here, and importing
40 # nixpkgs once per host was half of its evaluation time.
41 mkHost =
42 module:
43 lib.nixosSystem {
44 inherit pkgs;
45 modules = [
46 self.nixosModules.default
47 {
48 fileSystems."/" = {
49 device = "/dev/disk/by-label/nixos";
50 fsType = "ext4";
51 };
52 boot.loader.grub.enable = false;
53 system.stateVersion = "25.11";
54 services.valley = {
55 enable = true;
56 authorizedKeys = [
57 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck0 valley-check"
58 ];
59 };
60 }
61 (lib.mkIf stubbed { services.valley.packages = stubs; })
62 module
63 ];
64 };
65
66 # The same controllers as restrictedHost's with the check worker on and
67 # the build slice on at its defaults, writing neither the worker's
68 # projects nor its signer's.
69 workerBase = {
70 services.valley = {
71 config = ../../examples/hosts/protected.cue;
72 buildSlice.enable = true;
73 integrator = {
74 enable = true;
75 signingKeyFile = "/run/agenix/valley-integrator-key";
76 knownSignersFile = "/var/lib/valley-instance/known_signers";
77 instanceProject = "sealed";
78 };
79 worker = {
80 enable = true;
81 signerName = "worker.valley.invalid/attestations";
82 };
83 };
84 };
85
86 # The check worker for two of the projects the controllers serve, its
87 # signer restricted to exactly those two. It is bound here so the hosts
88 # the module must refuse can be made from it.
89 workerHost = mkHost {
90 imports = [ workerBase ];
91 services.valley = {
92 integrator.signerProjects."worker.valley.invalid/attestations" = [
93 "sealed"
94 "guarded"
95 ];
96 worker.projects = [
97 "guarded"
98 "sealed"
99 ];
100 };
101 };
102in
103{
104 # The example declaration enables backup, so this host supplies
105 # the four secret paths (eval-only placeholders).
106 host = mkHost {
107 services.valley = {
108 config = ../../examples/host.cue;
109 backup = {
110 repositoryFile = "/run/agenix/valley-restic-repo";
111 passwordFile = "/run/agenix/valley-restic-password";
112 sshKeyFile = "/run/agenix/valley-git-ssh-key";
113 knownHostsFile = "/var/lib/valley-backup/known_hosts";
114 };
115 };
116 };
117
118 # A declaration with no optional field set at all — no backup, no
119 # protection — must keep evaluating exactly as it did before those
120 # fields existed: zero restic machinery, no hook.
121 noBackupHost = mkHost {
122 services.valley.config = ../../examples/hosts/no-backup.cue;
123 };
124
125 # The example declaration with the secret paths left unset: the
126 # module must refuse with assertions naming the missing options.
127 noSecretsHost = mkHost {
128 services.valley.config = ../../examples/host.cue;
129 };
130
131 # Bus enabled, minimal declaration. The bus-e2e check drives this
132 # host's rendered hooks and stream-init against a real server.
133 busHost = mkHost {
134 services.valley = {
135 config = ../../examples/hosts/bus.cue;
136 bus.enable = true;
137 };
138 };
139
140 # Two mirror URLs the sandbox can serve: git resolves a relative
141 # URL against the pushing repo's directory, so the mirror-e2e
142 # check drives the rendered script with no substitution at all —
143 # one reachable sibling repo, one that does not exist.
144 mirrorHost = mkHost {
145 services.valley.config = ../../examples/hosts/mirrors.cue;
146 # Client environment the push boundary does not read stays acceptable.
147 services.openssh.settings.AcceptEnv = "LANG LC_*";
148 };
149
150 # The protection declaration, plus the machine half it needs: keys
151 # bound to the principal names it uses, and the approve and restack
152 # grants held by hand. requester holds both grants, so the hook checks
153 # read a principal whose approve grant the restack grant leaves as it
154 # is. The approve grant is declared under both its names: requester is
155 # named under both, and approver under approve alone. The baseline key
156 # above is anonymous and stays in the list, so this host also renders
157 # the two forms of key side by side.
158 protectedHost = mkHost {
159 services.valley = {
160 config = ../../examples/hosts/protected.cue;
161 authorizedKeys = [
162 {
163 principal = "integrator";
164 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck1 integrator";
165 }
166 {
167 principal = "contributor";
168 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
169 }
170 {
171 principal = "requester";
172 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck3 requester";
173 }
174 {
175 principal = "restacker";
176 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck4 restacker";
177 }
178 {
179 principal = "approver";
180 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck5 approver";
181 }
182 ];
183 grants.request = [ "requester" ];
184 grants.approve = [
185 "approver"
186 "requester"
187 ];
188 grants.restack = [
189 "restacker"
190 "requester"
191 ];
192 # The keys attestations pushed here are checked against: the ones a
193 # controller would accept evidence from, though this host runs none.
194 integrator.knownSignersFile = "/var/lib/valley-instance/known_signers";
195 # released composes a hook of its own after the push policy: it
196 # refuses branches under frozen/, which the policy would accept.
197 extraPreReceive.released = pkgs.writeShellScript "valley-check-released-pre-receive" ''
198 while read -r _ _ ref; do
199 case "$ref" in
200 refs/heads/frozen/*)
201 echo "released: $ref is frozen" >&2
202 exit 1
203 ;;
204 esac
205 done
206 '';
207 };
208 };
209
210 # The same protection declaration with the controllers switched on. The
211 # integrator serves exactly what that declaration protects, so this host
212 # renders two controllers and no third; the paths are eval-only
213 # placeholders, like the backup host's.
214 integratorHost = mkHost {
215 services.valley = {
216 config = ../../examples/hosts/protected.cue;
217 integrator = {
218 enable = true;
219 signingKeyFile = "/run/agenix/valley-integrator-key";
220 knownSignersFile = "/var/lib/valley-instance/known_signers";
221 # The floor comes from "sealed", which declares protection, as the
222 # instance repository has to. Every other controller here reads the
223 # floor out of a repository that is not the one it serves, which is
224 # the cross-repository read the unit has to grant.
225 instanceProject = "sealed";
226 };
227 };
228 };
229
230 # The same controllers with a check worker's signer restricted to two of
231 # the projects they serve, and a retired signer restricted to none.
232 restrictedHost = mkHost {
233 services.valley = {
234 config = ../../examples/hosts/protected.cue;
235 integrator = {
236 enable = true;
237 signingKeyFile = "/run/agenix/valley-integrator-key";
238 knownSignersFile = "/var/lib/valley-instance/known_signers";
239 instanceProject = "sealed";
240 signerProjects = {
241 "worker.valley.invalid/attestations" = [
242 "guarded"
243 "sealed"
244 ];
245 "retired.valley.invalid/attestations" = [ ];
246 };
247 };
248 };
249 };
250
251 inherit workerHost;
252
253 # The check worker with neither list written: it builds for every project
254 # the controllers serve, and its signer counts in exactly those.
255 defaultWorkerHost = mkHost workerBase;
256
257 # The check worker narrowed to one project, its signer's list unwritten:
258 # the signer counts in that one project alone.
259 narrowedWorkerHost = mkHost {
260 imports = [ workerBase ];
261 services.valley.worker.projects = [ "guarded" ];
262 };
263
264 # Both lists written, the signer's narrower than the worker's. A module
265 # entry merged into the host's, rather than replaced by it, would make
266 # the two lists match.
267 mismatchedWorkerHost = mkHost {
268 imports = [ workerBase ];
269 services.valley = {
270 integrator.signerProjects."worker.valley.invalid/attestations" = [ "sealed" ];
271 worker.projects = [
272 "guarded"
273 "sealed"
274 ];
275 };
276 };
277
278 # The restacker on for one of the projects the controllers serve, with
279 # the floor read from the instance repository.
280 restackerHost = mkHost {
281 services.valley = {
282 config = ../../examples/hosts/protected.cue;
283 integrator = {
284 enable = true;
285 signingKeyFile = "/run/agenix/valley-integrator-key";
286 knownSignersFile = "/var/lib/valley-instance/known_signers";
287 instanceProject = "sealed";
288 };
289 restacker = {
290 enable = true;
291 projects = [ "guarded" ];
292 sshKeyFile = "/run/agenix/valley-restacker-key";
293 };
294 };
295 };
296
297 # The restacker with no list of projects: it serves every project the
298 # host integrates.
299 defaultRestackerHost = mkHost {
300 services.valley = {
301 config = ../../examples/hosts/protected.cue;
302 integrator = {
303 enable = true;
304 signingKeyFile = "/run/agenix/valley-integrator-key";
305 knownSignersFile = "/var/lib/valley-instance/known_signers";
306 instanceProject = "sealed";
307 };
308 restacker = {
309 enable = true;
310 sshKeyFile = "/run/agenix/valley-restacker-key";
311 };
312 };
313 };
314
315 # The restacker for a project this host does not serve.
316 unservedRestackerHost = mkHost {
317 services.valley = {
318 config = ../../examples/hosts/protected.cue;
319 integrator.instanceProject = "sealed";
320 restacker = {
321 enable = true;
322 projects = [ "nowhere" ];
323 sshKeyFile = "/run/agenix/valley-restacker-key";
324 };
325 };
326 };
327
328 # The restacker with no key to push with.
329 keylessRestackerHost = mkHost {
330 services.valley = {
331 config = ../../examples/hosts/protected.cue;
332 integrator.instanceProject = "sealed";
333 restacker = {
334 enable = true;
335 projects = [ "guarded" ];
336 };
337 };
338 };
339
340 # The build slice alone, at caps of its own: every build of the daemon
341 # capped, and no worker.
342 buildSliceHost = mkHost {
343 services.valley = {
344 config = ../../examples/hosts/protected.cue;
345 buildSlice = {
346 enable = true;
347 cpuQuota = "200%";
348 memoryMax = "4G";
349 };
350 };
351 };
352
353 # The registry machinery switched on, over the same declaration. The
354 # signers file is not supplied: the compiler renders it, and a consumer
355 # that also named one would be asking which of the two won. The
356 # integrator's signing name is set here too, because a host that compiles
357 # a registry is a host whose registry publishes the integrator's key under
358 # a name, and the controller has to sign under that same name.
359 identityHost = mkHost {
360 services.valley = {
361 config = ../../examples/hosts/protected.cue;
362 identity.enable = true;
363 integrator = {
364 enable = true;
365 signingKeyFile = "/run/agenix/valley-integrator-key";
366 signingName = "integrator";
367 instanceProject = "sealed";
368 };
369 };
370 };
371
372 # The same host with the instance repository among the served projects —
373 # the shape a group's own instance takes, where the repository carrying
374 # the floor is itself integrated. The controller serving it reads the
375 # floor from the repository it is already serving.
376 integratorSelfHost = mkHost {
377 services.valley = {
378 config = ../../examples/hosts/protected.cue;
379 integrator = {
380 enable = true;
381 signingKeyFile = "/run/agenix/valley-integrator-key";
382 knownSignersFile = "/var/lib/valley-instance/known_signers";
383 instanceProject = "guarded";
384 };
385 };
386 };
387
388 # Hosts the module must refuse. Each is one way for the push policy to be
389 # quietly wrong, and each must fail an assertion naming what is wrong.
390 #
391 # The instance repository unprotected: the floor and the registry would
392 # be read from a main any key could push.
393 unprotectedInstanceHost = mkHost {
394 services.valley = {
395 config = ../../examples/hosts/protected.cue;
396 integrator = {
397 enable = true;
398 signingKeyFile = "/run/agenix/valley-integrator-key";
399 knownSignersFile = "/var/lib/valley-instance/known_signers";
400 instanceProject = "open";
401 };
402 };
403 };
404
405 # sshd accepting the principal variable from the client.
406 acceptEnvHost = mkHost {
407 services.valley.config = ../../examples/hosts/protected.cue;
408 services.openssh.settings.AcceptEnv = "LANG LC_* VALLEY_*";
409 };
410
411 # The same, in the git user's own Match block, with the keyword in another
412 # case: sshd reads keywords in any case.
413 matchAcceptEnvHost = mkHost {
414 services.valley.config = ../../examples/hosts/protected.cue;
415 services.openssh.extraConfig = lib.mkAfter ''
416 Match User git
417 ACCEPTENV GIT_CONFIG_*
418 Match All
419 '';
420 };
421
422 # The principal, single-quoted: sshd strips the quotes and admits it.
423 quotedAcceptEnvHost = mkHost {
424 services.valley.config = ../../examples/hosts/protected.cue;
425 services.openssh.extraConfig = lib.mkAfter "AcceptEnv LANG 'VALLEY_PRINCIPAL'";
426 };
427
428 # The principal, separated from the pattern before it by a tab.
429 tabAcceptEnvHost = mkHost {
430 services.valley.config = ../../examples/hosts/protected.cue;
431 services.openssh.settings.AcceptEnv = "LANG\tVALLEY_PRINCIPAL";
432 };
433
434 # A pattern that names neither variable outright and still admits one.
435 wildcardAcceptEnvHost = mkHost {
436 services.valley.config = ../../examples/hosts/protected.cue;
437 services.openssh.settings.AcceptEnv = "LANG G?T_*";
438 };
439
440 # sshd setting the principal itself, over every key.
441 setEnvHost = mkHost {
442 services.valley.config = ../../examples/hosts/protected.cue;
443 services.openssh.extraConfig = lib.mkAfter "SetEnv VALLEY_PRINCIPAL=operator";
444 };
445
446 # sshd honouring every variable a key's entry or ~/.ssh/environment sets.
447 permitUserEnvironmentHost = mkHost {
448 services.valley.config = ../../examples/hosts/protected.cue;
449 services.openssh.settings.PermitUserEnvironment = lib.mkForce "yes";
450 };
451
452 # Two projects written as one: rendered one signer per line, the worker
453 # would read back as restricted to guarded and sealed, two projects the
454 # declaration never listed for it.
455 spacedSignerProjectsHost = mkHost {
456 services.valley = {
457 config = ../../examples/hosts/protected.cue;
458 integrator = {
459 enable = true;
460 signingKeyFile = "/run/agenix/valley-integrator-key";
461 knownSignersFile = "/var/lib/valley-instance/known_signers";
462 instanceProject = "sealed";
463 signerProjects."worker.valley.invalid/attestations" = [ "guarded sealed" ];
464 };
465 };
466 };
467
468 # The same two projects joined by a no-break space, U+00A0, which Nix's
469 # [:space:] does not match and Go's unicode.IsSpace does. Nix strings
470 # have no escape for it, so it is decoded from JSON.
471 unicodeSpacedSignerProjectsHost = mkHost {
472 services.valley = {
473 config = ../../examples/hosts/protected.cue;
474 integrator = {
475 enable = true;
476 signingKeyFile = "/run/agenix/valley-integrator-key";
477 knownSignersFile = "/var/lib/valley-instance/known_signers";
478 instanceProject = "sealed";
479 signerProjects."worker.valley.invalid/attestations" = [
480 "guarded${builtins.fromJSON ''"\u00a0"''}sealed"
481 ];
482 };
483 };
484 };
485
486 # The check worker with its signer restricted to no project list at all:
487 # every controller holding its key would count its evidence everywhere.
488 unrestrictedWorkerHost = workerHost.extendModules {
489 modules = [ { services.valley.integrator.signerProjects = lib.mkForce { }; } ];
490 };
491
492 # The check worker given build capacity of its own: three checks at
493 # once, each building two derivations at once on two cores.
494 capacityWorkerHost = workerHost.extendModules {
495 modules = [
496 {
497 services.valley.worker = {
498 buildSlots = 3;
499 maxJobs = 2;
500 cores = 2;
501 };
502 }
503 ];
504 };
505
506 # The check worker on a host whose builds are not capped: turning it on
507 # must not be what caps every build of the daemon.
508 noSliceWorkerHost = workerHost.extendModules {
509 modules = [ { services.valley.buildSlice.enable = lib.mkForce false; } ];
510 };
511
512 # The worker's signer restricted to a project the worker does not build:
513 # its key would be trusted where it does no work.
514 widerWorkerHost = workerHost.extendModules {
515 modules = [
516 {
517 services.valley.integrator.signerProjects = lib.mkForce {
518 "worker.valley.invalid/attestations" = [
519 "guarded"
520 "released"
521 "sealed"
522 ];
523 };
524 }
525 ];
526 };
527
528 # The worker signing under the controllers' own name.
529 integratorNamedWorkerHost = workerHost.extendModules {
530 modules = [
531 {
532 services.valley.integrator.signingName = "integrator";
533 services.valley.integrator.signerProjects = lib.mkForce {
534 integrator = [
535 "guarded"
536 "sealed"
537 ];
538 };
539 services.valley.worker.signerName = lib.mkForce "integrator";
540 }
541 ];
542 };
543
544 # One key declared untagged and tagged: which principal it pushes as
545 # would depend on which line sshd reads first.
546 conflictingKeysHost = mkHost {
547 services.valley = {
548 config = ../../examples/hosts/protected.cue;
549 authorizedKeys = [
550 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor"
551 {
552 principal = "contributor";
553 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
554 }
555 ];
556 };
557 };
558}