gunk-dev/the-valley

hosts.nix

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