gunk-dev/the-valley

hosts.nix

sourceed2ea70fe6b2main's published tip history
12.3 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}:
10let
11 # Each check host shares the machine baseline and supplies its own
12 # declaration (and, where the declaration asks for backup, the secret
13 # paths).
14 #
15 # Each host is also handed the package set the checks already use,
16 # rather than importing nixpkgs again for itself. It is the same nixpkgs
17 # with the same configuration, so every host renders the same
18 # derivations. module-eval evaluates every host here, and importing
19 # nixpkgs once per host was half of its evaluation time.
20 mkHost =
21 module:
22 lib.nixosSystem {
23 inherit pkgs;
24 modules = [
25 self.nixosModules.default
26 {
27 fileSystems."/" = {
28 device = "/dev/disk/by-label/nixos";
29 fsType = "ext4";
30 };
31 boot.loader.grub.enable = false;
32 system.stateVersion = "25.11";
33 services.valley = {
34 enable = true;
35 authorizedKeys = [
36 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck0 valley-check"
37 ];
38 };
39 }
40 module
41 ];
42 };
43in
44{
45 # The example declaration enables backup, so this host supplies
46 # the four secret paths (eval-only placeholders).
47 host = mkHost {
48 services.valley = {
49 config = ../../examples/host.cue;
50 backup = {
51 repositoryFile = "/run/agenix/valley-restic-repo";
52 passwordFile = "/run/agenix/valley-restic-password";
53 sshKeyFile = "/run/agenix/valley-git-ssh-key";
54 knownHostsFile = "/var/lib/valley-backup/known_hosts";
55 };
56 };
57 };
58
59 # A declaration with no optional field set at all — no backup, no
60 # protection — must keep evaluating exactly as it did before those
61 # fields existed: zero restic machinery, no hook.
62 noBackupHost = mkHost {
63 services.valley.config = ../../examples/hosts/no-backup.cue;
64 };
65
66 # The example declaration with the secret paths left unset: the
67 # module must refuse with assertions naming the missing options.
68 noSecretsHost = mkHost {
69 services.valley.config = ../../examples/host.cue;
70 };
71
72 # Bus enabled, minimal declaration. The bus-e2e check drives this
73 # host's rendered hooks and stream-init against a real server.
74 busHost = mkHost {
75 services.valley = {
76 config = ../../examples/hosts/bus.cue;
77 bus.enable = true;
78 };
79 };
80
81 # Two mirror URLs the sandbox can serve: git resolves a relative
82 # URL against the pushing repo's directory, so the mirror-e2e
83 # check drives the rendered script with no substitution at all —
84 # one reachable sibling repo, one that does not exist.
85 mirrorHost = mkHost {
86 services.valley.config = ../../examples/hosts/mirrors.cue;
87 # Client environment the push boundary does not read stays acceptable.
88 services.openssh.settings.AcceptEnv = "LANG LC_*";
89 };
90
91 # The protection declaration, plus the machine half it needs: keys
92 # bound to the principal names it uses, and the approve and restack
93 # grants held by hand. requester holds both grants, so the hook checks
94 # read a principal whose approve grant the restack grant leaves as it
95 # is. The approve grant is declared under both its names: requester is
96 # named under both, and approver under approve alone. The baseline key
97 # above is anonymous and stays in the list, so this host also renders
98 # the two forms of key side by side.
99 protectedHost = mkHost {
100 services.valley = {
101 config = ../../examples/hosts/protected.cue;
102 authorizedKeys = [
103 {
104 principal = "integrator";
105 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck1 integrator";
106 }
107 {
108 principal = "contributor";
109 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
110 }
111 {
112 principal = "requester";
113 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck3 requester";
114 }
115 {
116 principal = "restacker";
117 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck4 restacker";
118 }
119 {
120 principal = "approver";
121 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck5 approver";
122 }
123 ];
124 grants.request = [ "requester" ];
125 grants.approve = [
126 "approver"
127 "requester"
128 ];
129 grants.restack = [
130 "restacker"
131 "requester"
132 ];
133 # The keys attestations pushed here are checked against: the ones a
134 # controller would accept evidence from, though this host runs none.
135 integrator.knownSignersFile = "/var/lib/valley-instance/known_signers";
136 # released composes a hook of its own after the push policy: it
137 # refuses branches under frozen/, which the policy would accept.
138 extraPreReceive.released = pkgs.writeShellScript "valley-check-released-pre-receive" ''
139 while read -r _ _ ref; do
140 case "$ref" in
141 refs/heads/frozen/*)
142 echo "released: $ref is frozen" >&2
143 exit 1
144 ;;
145 esac
146 done
147 '';
148 };
149 };
150
151 # The same protection declaration with the controllers switched on. The
152 # integrator serves exactly what that declaration protects, so this host
153 # renders two controllers and no third; the paths are eval-only
154 # placeholders, like the backup host's.
155 integratorHost = mkHost {
156 services.valley = {
157 config = ../../examples/hosts/protected.cue;
158 integrator = {
159 enable = true;
160 signingKeyFile = "/run/agenix/valley-integrator-key";
161 knownSignersFile = "/var/lib/valley-instance/known_signers";
162 # The floor comes from "sealed", which declares protection, as the
163 # instance repository has to. Every other controller here reads the
164 # floor out of a repository that is not the one it serves, which is
165 # the cross-repository read the unit has to grant.
166 instanceProject = "sealed";
167 };
168 };
169 };
170
171 # The same controllers with a check worker's signer restricted to two of
172 # the projects they serve, and a retired signer restricted to none.
173 restrictedHost = mkHost {
174 services.valley = {
175 config = ../../examples/hosts/protected.cue;
176 integrator = {
177 enable = true;
178 signingKeyFile = "/run/agenix/valley-integrator-key";
179 knownSignersFile = "/var/lib/valley-instance/known_signers";
180 instanceProject = "sealed";
181 signerProjects = {
182 "worker.valley.invalid/attestations" = [
183 "guarded"
184 "sealed"
185 ];
186 "retired.valley.invalid/attestations" = [ ];
187 };
188 };
189 };
190 };
191
192 # The registry machinery switched on, over the same declaration. The
193 # signers file is not supplied: the compiler renders it, and a consumer
194 # that also named one would be asking which of the two won. The
195 # integrator's signing name is set here too, because a host that compiles
196 # a registry is a host whose registry publishes the integrator's key under
197 # a name, and the controller has to sign under that same name.
198 identityHost = mkHost {
199 services.valley = {
200 config = ../../examples/hosts/protected.cue;
201 identity.enable = true;
202 integrator = {
203 enable = true;
204 signingKeyFile = "/run/agenix/valley-integrator-key";
205 signingName = "integrator";
206 instanceProject = "sealed";
207 };
208 };
209 };
210
211 # The same host with the instance repository among the served projects —
212 # the shape a group's own instance takes, where the repository carrying
213 # the floor is itself integrated. The controller serving it reads the
214 # floor from the repository it is already serving.
215 integratorSelfHost = mkHost {
216 services.valley = {
217 config = ../../examples/hosts/protected.cue;
218 integrator = {
219 enable = true;
220 signingKeyFile = "/run/agenix/valley-integrator-key";
221 knownSignersFile = "/var/lib/valley-instance/known_signers";
222 instanceProject = "guarded";
223 };
224 };
225 };
226
227 # Hosts the module must refuse. Each is one way for the push policy to be
228 # quietly wrong, and each must fail an assertion naming what is wrong.
229 #
230 # The instance repository unprotected: the floor and the registry would
231 # be read from a main any key could push.
232 unprotectedInstanceHost = 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 = "open";
240 };
241 };
242 };
243
244 # sshd accepting the principal variable from the client.
245 acceptEnvHost = mkHost {
246 services.valley.config = ../../examples/hosts/protected.cue;
247 services.openssh.settings.AcceptEnv = "LANG LC_* VALLEY_*";
248 };
249
250 # The same, in the git user's own Match block, with the keyword in another
251 # case: sshd reads keywords in any case.
252 matchAcceptEnvHost = mkHost {
253 services.valley.config = ../../examples/hosts/protected.cue;
254 services.openssh.extraConfig = lib.mkAfter ''
255 Match User git
256 ACCEPTENV GIT_CONFIG_*
257 Match All
258 '';
259 };
260
261 # The principal, single-quoted: sshd strips the quotes and admits it.
262 quotedAcceptEnvHost = mkHost {
263 services.valley.config = ../../examples/hosts/protected.cue;
264 services.openssh.extraConfig = lib.mkAfter "AcceptEnv LANG 'VALLEY_PRINCIPAL'";
265 };
266
267 # The principal, separated from the pattern before it by a tab.
268 tabAcceptEnvHost = mkHost {
269 services.valley.config = ../../examples/hosts/protected.cue;
270 services.openssh.settings.AcceptEnv = "LANG\tVALLEY_PRINCIPAL";
271 };
272
273 # A pattern that names neither variable outright and still admits one.
274 wildcardAcceptEnvHost = mkHost {
275 services.valley.config = ../../examples/hosts/protected.cue;
276 services.openssh.settings.AcceptEnv = "LANG G?T_*";
277 };
278
279 # sshd setting the principal itself, over every key.
280 setEnvHost = mkHost {
281 services.valley.config = ../../examples/hosts/protected.cue;
282 services.openssh.extraConfig = lib.mkAfter "SetEnv VALLEY_PRINCIPAL=patrick";
283 };
284
285 # sshd honouring every variable a key's entry or ~/.ssh/environment sets.
286 permitUserEnvironmentHost = mkHost {
287 services.valley.config = ../../examples/hosts/protected.cue;
288 services.openssh.settings.PermitUserEnvironment = lib.mkForce "yes";
289 };
290
291 # Two projects written as one: rendered one signer per line, the worker
292 # would read back as restricted to guarded and sealed, two projects the
293 # declaration never listed for it.
294 spacedSignerProjectsHost = mkHost {
295 services.valley = {
296 config = ../../examples/hosts/protected.cue;
297 integrator = {
298 enable = true;
299 signingKeyFile = "/run/agenix/valley-integrator-key";
300 knownSignersFile = "/var/lib/valley-instance/known_signers";
301 instanceProject = "sealed";
302 signerProjects."worker.valley.invalid/attestations" = [ "guarded sealed" ];
303 };
304 };
305 };
306
307 # The same two projects joined by a no-break space, U+00A0, which Nix's
308 # [:space:] does not match and Go's unicode.IsSpace does. Nix strings
309 # have no escape for it, so it is decoded from JSON.
310 unicodeSpacedSignerProjectsHost = mkHost {
311 services.valley = {
312 config = ../../examples/hosts/protected.cue;
313 integrator = {
314 enable = true;
315 signingKeyFile = "/run/agenix/valley-integrator-key";
316 knownSignersFile = "/var/lib/valley-instance/known_signers";
317 instanceProject = "sealed";
318 signerProjects."worker.valley.invalid/attestations" = [
319 "guarded${builtins.fromJSON ''"\u00a0"''}sealed"
320 ];
321 };
322 };
323 };
324
325 # One key declared untagged and tagged: which principal it pushes as
326 # would depend on which line sshd reads first.
327 conflictingKeysHost = mkHost {
328 services.valley = {
329 config = ../../examples/hosts/protected.cue;
330 authorizedKeys = [
331 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor"
332 {
333 principal = "contributor";
334 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
335 }
336 ];
337 };
338 };
339}