gunk-dev/the-valley

hosts.nix

source61364523a8d7main's published tip history
9.7 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 request and restack
88 # grants held by hand. requester holds both grants, so the hook checks
89 # read a principal whose request grant the restack grant leaves as it
90 # is. The baseline key above is anonymous and stays in the list, so this
91 # host also renders the two forms of key side by side.
92 protectedHost = mkHost {
93 services.valley = {
94 config = ../../examples/hosts/protected.cue;
95 authorizedKeys = [
96 {
97 principal = "integrator";
98 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck1 integrator";
99 }
100 {
101 principal = "contributor";
102 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
103 }
104 {
105 principal = "requester";
106 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck3 requester";
107 }
108 {
109 principal = "restacker";
110 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck4 restacker";
111 }
112 ];
113 grants.request = [ "requester" ];
114 grants.restack = [
115 "restacker"
116 "requester"
117 ];
118 # The keys attestations pushed here are checked against: the ones a
119 # controller would accept evidence from, though this host runs none.
120 integrator.knownSignersFile = "/var/lib/valley-instance/known_signers";
121 # released composes a hook of its own after the push policy: it
122 # refuses branches under frozen/, which the policy would accept.
123 extraPreReceive.released = pkgs.writeShellScript "valley-check-released-pre-receive" ''
124 while read -r _ _ ref; do
125 case "$ref" in
126 refs/heads/frozen/*)
127 echo "released: $ref is frozen" >&2
128 exit 1
129 ;;
130 esac
131 done
132 '';
133 };
134 };
135
136 # The same protection declaration with the controllers switched on. The
137 # integrator serves exactly what that declaration protects, so this host
138 # renders two controllers and no third; the paths are eval-only
139 # placeholders, like the backup host's.
140 integratorHost = mkHost {
141 services.valley = {
142 config = ../../examples/hosts/protected.cue;
143 integrator = {
144 enable = true;
145 signingKeyFile = "/run/agenix/valley-integrator-key";
146 knownSignersFile = "/var/lib/valley-instance/known_signers";
147 # The floor comes from "sealed", which declares protection, as the
148 # instance repository has to. Every other controller here reads the
149 # floor out of a repository that is not the one it serves, which is
150 # the cross-repository read the unit has to grant.
151 instanceProject = "sealed";
152 };
153 };
154 };
155
156 # The registry machinery switched on, over the same declaration. The
157 # signers file is not supplied: the compiler renders it, and a consumer
158 # that also named one would be asking which of the two won. The
159 # integrator's signing name is set here too, because a host that compiles
160 # a registry is a host whose registry publishes the integrator's key under
161 # a name, and the controller has to sign under that same name.
162 identityHost = mkHost {
163 services.valley = {
164 config = ../../examples/hosts/protected.cue;
165 identity.enable = true;
166 integrator = {
167 enable = true;
168 signingKeyFile = "/run/agenix/valley-integrator-key";
169 signingName = "integrator";
170 instanceProject = "sealed";
171 };
172 };
173 };
174
175 # The same host with the instance repository among the served projects —
176 # the shape a group's own instance takes, where the repository carrying
177 # the floor is itself integrated. The controller serving it reads the
178 # floor from the repository it is already serving.
179 integratorSelfHost = mkHost {
180 services.valley = {
181 config = ../../examples/hosts/protected.cue;
182 integrator = {
183 enable = true;
184 signingKeyFile = "/run/agenix/valley-integrator-key";
185 knownSignersFile = "/var/lib/valley-instance/known_signers";
186 instanceProject = "guarded";
187 };
188 };
189 };
190
191 # Hosts the module must refuse. Each is one way for the push policy to be
192 # quietly wrong, and each must fail an assertion naming what is wrong.
193 #
194 # The instance repository unprotected: the floor and the registry would
195 # be read from a main any key could push.
196 unprotectedInstanceHost = mkHost {
197 services.valley = {
198 config = ../../examples/hosts/protected.cue;
199 integrator = {
200 enable = true;
201 signingKeyFile = "/run/agenix/valley-integrator-key";
202 knownSignersFile = "/var/lib/valley-instance/known_signers";
203 instanceProject = "open";
204 };
205 };
206 };
207
208 # sshd accepting the principal variable from the client.
209 acceptEnvHost = mkHost {
210 services.valley.config = ../../examples/hosts/protected.cue;
211 services.openssh.settings.AcceptEnv = "LANG LC_* VALLEY_*";
212 };
213
214 # The same, in the git user's own Match block, with the keyword in another
215 # case: sshd reads keywords in any case.
216 matchAcceptEnvHost = mkHost {
217 services.valley.config = ../../examples/hosts/protected.cue;
218 services.openssh.extraConfig = lib.mkAfter ''
219 Match User git
220 ACCEPTENV GIT_CONFIG_*
221 Match All
222 '';
223 };
224
225 # The principal, single-quoted: sshd strips the quotes and admits it.
226 quotedAcceptEnvHost = mkHost {
227 services.valley.config = ../../examples/hosts/protected.cue;
228 services.openssh.extraConfig = lib.mkAfter "AcceptEnv LANG 'VALLEY_PRINCIPAL'";
229 };
230
231 # The principal, separated from the pattern before it by a tab.
232 tabAcceptEnvHost = mkHost {
233 services.valley.config = ../../examples/hosts/protected.cue;
234 services.openssh.settings.AcceptEnv = "LANG\tVALLEY_PRINCIPAL";
235 };
236
237 # A pattern that names neither variable outright and still admits one.
238 wildcardAcceptEnvHost = mkHost {
239 services.valley.config = ../../examples/hosts/protected.cue;
240 services.openssh.settings.AcceptEnv = "LANG G?T_*";
241 };
242
243 # sshd setting the principal itself, over every key.
244 setEnvHost = mkHost {
245 services.valley.config = ../../examples/hosts/protected.cue;
246 services.openssh.extraConfig = lib.mkAfter "SetEnv VALLEY_PRINCIPAL=patrick";
247 };
248
249 # sshd honouring every variable a key's entry or ~/.ssh/environment sets.
250 permitUserEnvironmentHost = mkHost {
251 services.valley.config = ../../examples/hosts/protected.cue;
252 services.openssh.settings.PermitUserEnvironment = lib.mkForce "yes";
253 };
254
255 # One key declared untagged and tagged: which principal it pushes as
256 # would depend on which line sshd reads first.
257 conflictingKeysHost = mkHost {
258 services.valley = {
259 config = ../../examples/hosts/protected.cue;
260 authorizedKeys = [
261 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor"
262 {
263 principal = "contributor";
264 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
265 }
266 ];
267 };
268 };
269}