gunk-dev/the-valley

signers.nix

source695d65eb4898main's published tip history
3.0 KiB
1# The signers a client verifies an integrator's transfer statement with:
2# published by the host into its instance repository, and read by a fresh
3# client with nothing configured.
4{
5 pkgs,
6 lib,
7 packages,
8 hosts,
9 ...
10}:
11let
12 # Throwaway keys, made once at build time: the contributor's, which signs
13 # evidence, and two of the integrator's, the second for after a rotation.
14 # They hold no authority anywhere. The hook checks pushed evidence against
15 # the contributor's key alone, since the integrator writes locally. The
16 # integrator's lines are written when the test runs, under the name the
17 # integrator defaults to on the machine it runs on.
18 keys =
19 pkgs.runCommand "valley-signers-e2e-keys"
20 {
21 nativeBuildInputs = [
22 pkgs.openssh
23 packages.attest
24 ];
25 }
26 ''
27 mkdir $out
28 for who in contributor integrator rotated; do
29 ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$out/$who"
30 done
31 attest key --key "$out/contributor" --name contributor.valley.invalid/attestations > "$out/hook_signers"
32 '';
33
34 # The protected host's rendered hook, checking evidence against that key.
35 host = hosts.protectedHost.extendModules {
36 modules = [
37 { services.valley.integrator.knownSignersFile = lib.mkForce "${keys}/hook_signers"; }
38 ];
39 };
40in
41{
42 # The real integrator lands a change by a commit that is no fast-forward,
43 # so only its transfer statement shows the landing. The publisher the
44 # module renders (integratorHost's, which sets no signing name) writes
45 # the controller's signers file and its default name into the instance
46 # repository, and a fresh clone with neither VALLEY_KNOWN_SIGNERS nor
47 # VALLEY_INTEGRATOR_SIGNER set reads the landing as landed-recorded,
48 # through valley changes --all, valley status, and valley rebase, which
49 # drops the landed change's commits from a stack above it. Before the
50 # publication the same landing reads uncertain and every other landing
51 # reads as it does after. A flag beats a variable and a variable beats
52 # the publication; an override that does not read, or holds no key
53 # under the name, is reported. No push can replace or delete the
54 # publication. After the integrator's key is rotated, a landing signed
55 # with the new key reads uncertain until the publisher runs again, and
56 # landed-recorded after.
57 signers-e2e = pkgs.runCommand "valley-signers-e2e" {
58 nativeBuildInputs = [
59 pkgs.git
60 pkgs.jq
61 pkgs.cue
62 pkgs.openssh
63 packages.attest
64 packages.integrator
65 packages.valley-script
66 packages.valley-go
67 ];
68 inherit keys;
69 initScript = host.config.systemd.services.valley-init.script;
70 publishCommand = hosts.integratorHost.config.systemd.services.valley-signers.serviceConfig.ExecStart;
71 passAsFile = [ "initScript" ];
72 integratorE2e = ../../integrator/e2e;
73 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
74 SCHEMA_VERIFICATION = ../../schema/verification.cue;
75 SCHEMA_EVENTS = ../../schema/events.cue;
76 } (builtins.readFile ./signers-e2e.sh);
77}