gunk-dev/the-valley

signers.nix

sourcea769d6211b91main's published tip history
4.1 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 };
40
41 # The host that restricts a worker's signer to projects, and the same host
42 # once its list has changed.
43 publisherOf = h: h.config.systemd.services.valley-signers.serviceConfig.ExecStart;
44 changedHost = hosts.restrictedHost.extendModules {
45 modules = [
46 {
47 services.valley.integrator.signerProjects = lib.mkForce {
48 "worker.valley.invalid/attestations" = [ "sealed" ];
49 };
50 }
51 ];
52 };
53in
54{
55 # The real integrator lands a change by a commit that is no fast-forward,
56 # so only its transfer statement shows the landing. The publisher the
57 # module renders (integratorHost's, which sets no signing name) writes
58 # the controller's signers file and its default name into the instance
59 # repository, and a fresh clone with neither VALLEY_KNOWN_SIGNERS nor
60 # VALLEY_INTEGRATOR_SIGNER set reads the landing as landed-recorded,
61 # through valley changes --all, valley status, and valley rebase, which
62 # drops the landed change's commits from a stack above it. Before the
63 # publication the same landing reads uncertain and every other landing
64 # reads as it does after. A flag beats a variable and a variable beats
65 # the publication; an override that does not read, or holds no key
66 # under the name, is reported. No push can replace or delete the
67 # publication. After the integrator's key is rotated, a landing signed
68 # with the new key reads uncertain until the publisher runs again, and
69 # landed-recorded after. A run that read the file before the rotation,
70 # and is still running when the host's run starts, makes that run wait
71 # for it, so the old keys are not published last. Once the registry
72 # revokes every signing key, the compiler's file with no key is
73 # published, and both merged landings read uncertain. A host that
74 # restricts signers to projects publishes its list beside the signers,
75 # a changed list is published again, a list that does not read publishes
76 # nothing, and a host that restricts nobody publishes no list.
77 signers-e2e = pkgs.runCommand "valley-signers-e2e" {
78 nativeBuildInputs = [
79 pkgs.git
80 pkgs.jq
81 pkgs.cue
82 pkgs.openssh
83 packages.attest
84 packages.identity
85 packages.integrator
86 packages.valley-script
87 packages.valley-go
88 ];
89 inherit keys;
90 initScript = host.config.systemd.services.valley-init.script;
91 publishCommand = publisherOf hosts.integratorHost;
92 restrictedPublishCommand = publisherOf hosts.restrictedHost;
93 changedPublishCommand = publisherOf changedHost;
94 passAsFile = [ "initScript" ];
95 integratorE2e = ../../integrator/e2e;
96 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
97 SCHEMA_VERIFICATION = ../../schema/verification.cue;
98 SCHEMA_EVENTS = ../../schema/events.cue;
99 } (builtins.readFile ./signers-e2e.sh);
100}