gunk-dev/the-valley

hosts.nix

source8d0e7f14a4f9main's published tip history
10.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 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 registry machinery switched on, over the same declaration. The
167 # signers file is not supplied: the compiler renders it, and a consumer
168 # that also named one would be asking which of the two won. The
169 # integrator's signing name is set here too, because a host that compiles
170 # a registry is a host whose registry publishes the integrator's key under
171 # a name, and the controller has to sign under that same name.
172 identityHost = mkHost {
173 services.valley = {
174 config = ../../examples/hosts/protected.cue;
175 identity.enable = true;
176 integrator = {
177 enable = true;
178 signingKeyFile = "/run/agenix/valley-integrator-key";
179 signingName = "integrator";
180 instanceProject = "sealed";
181 };
182 };
183 };
184
185 # The same host with the instance repository among the served projects —
186 # the shape a group's own instance takes, where the repository carrying
187 # the floor is itself integrated. The controller serving it reads the
188 # floor from the repository it is already serving.
189 integratorSelfHost = mkHost {
190 services.valley = {
191 config = ../../examples/hosts/protected.cue;
192 integrator = {
193 enable = true;
194 signingKeyFile = "/run/agenix/valley-integrator-key";
195 knownSignersFile = "/var/lib/valley-instance/known_signers";
196 instanceProject = "guarded";
197 };
198 };
199 };
200
201 # Hosts the module must refuse. Each is one way for the push policy to be
202 # quietly wrong, and each must fail an assertion naming what is wrong.
203 #
204 # The instance repository unprotected: the floor and the registry would
205 # be read from a main any key could push.
206 unprotectedInstanceHost = mkHost {
207 services.valley = {
208 config = ../../examples/hosts/protected.cue;
209 integrator = {
210 enable = true;
211 signingKeyFile = "/run/agenix/valley-integrator-key";
212 knownSignersFile = "/var/lib/valley-instance/known_signers";
213 instanceProject = "open";
214 };
215 };
216 };
217
218 # sshd accepting the principal variable from the client.
219 acceptEnvHost = mkHost {
220 services.valley.config = ../../examples/hosts/protected.cue;
221 services.openssh.settings.AcceptEnv = "LANG LC_* VALLEY_*";
222 };
223
224 # The same, in the git user's own Match block, with the keyword in another
225 # case: sshd reads keywords in any case.
226 matchAcceptEnvHost = mkHost {
227 services.valley.config = ../../examples/hosts/protected.cue;
228 services.openssh.extraConfig = lib.mkAfter ''
229 Match User git
230 ACCEPTENV GIT_CONFIG_*
231 Match All
232 '';
233 };
234
235 # The principal, single-quoted: sshd strips the quotes and admits it.
236 quotedAcceptEnvHost = mkHost {
237 services.valley.config = ../../examples/hosts/protected.cue;
238 services.openssh.extraConfig = lib.mkAfter "AcceptEnv LANG 'VALLEY_PRINCIPAL'";
239 };
240
241 # The principal, separated from the pattern before it by a tab.
242 tabAcceptEnvHost = mkHost {
243 services.valley.config = ../../examples/hosts/protected.cue;
244 services.openssh.settings.AcceptEnv = "LANG\tVALLEY_PRINCIPAL";
245 };
246
247 # A pattern that names neither variable outright and still admits one.
248 wildcardAcceptEnvHost = mkHost {
249 services.valley.config = ../../examples/hosts/protected.cue;
250 services.openssh.settings.AcceptEnv = "LANG G?T_*";
251 };
252
253 # sshd setting the principal itself, over every key.
254 setEnvHost = mkHost {
255 services.valley.config = ../../examples/hosts/protected.cue;
256 services.openssh.extraConfig = lib.mkAfter "SetEnv VALLEY_PRINCIPAL=patrick";
257 };
258
259 # sshd honouring every variable a key's entry or ~/.ssh/environment sets.
260 permitUserEnvironmentHost = mkHost {
261 services.valley.config = ../../examples/hosts/protected.cue;
262 services.openssh.settings.PermitUserEnvironment = lib.mkForce "yes";
263 };
264
265 # One key declared untagged and tagged: which principal it pushes as
266 # would depend on which line sshd reads first.
267 conflictingKeysHost = mkHost {
268 services.valley = {
269 config = ../../examples/hosts/protected.cue;
270 authorizedKeys = [
271 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor"
272 {
273 principal = "contributor";
274 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
275 }
276 ];
277 };
278 };
279}