gunk-dev/the-valley

hosts.nix

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