gunk-dev/the-valley

signers.nix

source58e68be0d151main's published tip history
4.3 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 nixStandIns,
10 ...
11}:
12let
13 # Throwaway keys, made once at build time: the contributor's, which signs
14 # evidence, and two of the integrator's, the second for after a rotation.
15 # They hold no authority anywhere. The hook checks pushed evidence against
16 # the contributor's key alone, since the integrator writes locally. The
17 # integrator's lines are written when the test runs, under the name the
18 # integrator defaults to on the machine it runs on.
19 keys =
20 pkgs.runCommand "valley-signers-e2e-keys"
21 {
22 nativeBuildInputs = [
23 pkgs.openssh
24 packages.attest
25 ];
26 }
27 ''
28 mkdir $out
29 for who in contributor integrator rotated; do
30 ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$out/$who"
31 done
32 attest key --key "$out/contributor" --name contributor.valley.invalid/attestations > "$out/hook_signers"
33 '';
34
35 # The protected host's rendered hook, checking evidence against that key.
36 host = hosts.protectedHost.extendModules {
37 modules = [
38 { services.valley.integrator.knownSignersFile = lib.mkForce "${keys}/hook_signers"; }
39 ];
40 };
41
42 # The host that restricts a worker's signer to projects, and the same host
43 # once its list has changed.
44 publisherOf = h: h.config.systemd.services.valley-signers.serviceConfig.ExecStart;
45 changedHost = hosts.restrictedHost.extendModules {
46 modules = [
47 {
48 services.valley.integrator.signerProjects = lib.mkForce {
49 "worker.valley.invalid/attestations" = [ "sealed" ];
50 };
51 }
52 ];
53 };
54in
55{
56 # The real integrator lands a change by a commit that is no fast-forward,
57 # so only its transfer statement shows the landing. The publisher the
58 # module renders (integratorHost's, which sets no signing name) writes
59 # the controller's signers file and its default name into the instance
60 # repository, and a fresh clone with neither VALLEY_KNOWN_SIGNERS nor
61 # VALLEY_INTEGRATOR_SIGNER set reads the landing as landed-recorded,
62 # through valley changes --all, valley status, and valley rebase, which
63 # drops the landed change's commits from a stack above it. Before the
64 # publication the same landing reads uncertain and every other landing
65 # reads as it does after. A flag beats a variable and a variable beats
66 # the publication; an override that does not read, or holds no key
67 # under the name, is reported. No push can replace or delete the
68 # publication. The publisher refuses a signer projects list that
69 # restricts the name it publishes; a client given one anyway, one that
70 # does not read, or an entry that is not a file, verifies no transfer
71 # statement, and one naming only a worker changes nothing. After the integrator's key is rotated, a landing signed
72 # with the new key reads uncertain until the publisher runs again, and
73 # landed-recorded after. A run that read the file before the rotation,
74 # and is still running when the host's run starts, makes that run wait
75 # for it, so the old keys are not published last. Once the registry
76 # revokes every signing key, the compiler's file with no key is
77 # published, and both merged landings read uncertain. A host that
78 # restricts signers to projects publishes its list beside the signers,
79 # a changed list is published again, a list that does not read publishes
80 # nothing, and a host that restricts nobody publishes no list.
81 signers-e2e = pkgs.runCommand "valley-signers-e2e" {
82 nativeBuildInputs = [
83 pkgs.git
84 pkgs.jq
85 pkgs.cue
86 pkgs.openssh
87 packages.attest
88 packages.identity
89 packages.integrator
90 packages.valley-unstamped
91 ];
92 inherit keys;
93 initScript = host.config.systemd.services.valley-init.script;
94 publishCommand = publisherOf hosts.integratorHost;
95 restrictedPublishCommand = publisherOf hosts.restrictedHost;
96 changedPublishCommand = publisherOf changedHost;
97 passAsFile = [ "initScript" ];
98 integratorE2e = nixStandIns;
99 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
100 SCHEMA_VERIFICATION = ../../schema/verification.cue;
101 SCHEMA_EVENTS = ../../schema/events.cue;
102 } (builtins.readFile ./signers-e2e.sh);
103}