gunk-dev/the-valley

restack.nix

source5f0229dc1066main's published tip history
5.8 KiB
1{
2 pkgs,
3 lib,
4 packages,
5 hosts,
6 ...
7}:
8let
9 # Throwaway keys, made once at build time: the contributor's, which signs
10 # evidence, and the integrator's, which signs what it lands. They hold no
11 # authority anywhere. known_signers is the one verifier file the rendered
12 # hook, the integrator and the restacker all read, under the names each
13 # signs as.
14 keys =
15 pkgs.runCommand "valley-restack-e2e-keys"
16 {
17 nativeBuildInputs = [
18 pkgs.openssh
19 packages.attest
20 ];
21 }
22 ''
23 mkdir $out
24 for who in contributor integrator; do
25 ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$out/$who"
26 done
27 attest key --key "$out/contributor" --name contributor.valley.invalid/attestations > "$out/known_signers"
28 attest key --key "$out/integrator" --name integrator.valley.invalid/attestations >> "$out/known_signers"
29 '';
30
31 # The protected host, with its hook checking evidence against those keys
32 # rather than a file under /var/lib that no sandbox holds. Its grants are
33 # the protected host's: requester holds request and restack, and
34 # restacker holds restack alone.
35 host = hosts.protectedHost.extendModules {
36 modules = [
37 { services.valley.integrator.knownSignersFile = lib.mkForce "${keys}/known_signers"; }
38 ];
39 };
40 initScript = host.config.systemd.services.valley-init.script;
41
42 # The transport the end-to-end tests reach origin through: a stand-in for
43 # ssh that serves pushes and fetches with the real receive-pack and
44 # upload-pack, and holds or cuts one where a test chooses
45 # (restack/e2e/transport). Go, standard library only.
46 transport = pkgs.buildGoModule {
47 pname = "valley-restack-transport";
48 version = "0";
49 src = ../../restack/e2e/transport;
50 vendorHash = null;
51 postInstall = ''
52 mv $out/bin/transport $out/bin/valley-restack-transport
53 '';
54 };
55in
56{
57 # The restacker's own tests (restack/), run in its checkPhase: how a
58 # request relates to a family, which outcomes are current and which
59 # release a family, the arithmetic of each capacity limit, and how the
60 # policy's cap is counted, one larger than any int included. Its scratch
61 # repository commits as its flags say with no identity in the
62 # environment, a pass locks its state directory, the directory belongs to
63 # one repository, target and principal, and a cue or an ssh that never
64 # returns is killed at the deadline. Given the fixture host's rendered
65 # hook, the restack append is pushed through it as the restacker
66 # principal: the hook takes the active title and refuses a forged one,
67 # and takes a report from the restacker and not from the change's owner.
68 restack-unit = packages.restack-unwrapped.overrideAttrs {
69 inherit initScript;
70 passAsFile = [ "initScript" ];
71 preCheck = ''
72 VALLEY_RESTACK_TEST_HOOK="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)"
73 test -x "$VALLEY_RESTACK_TEST_HOOK"
74 export VALLEY_RESTACK_TEST_HOOK
75 '';
76 };
77
78 # valley-restacker once --report-only over a bare repository wired with
79 # the fixture host's rendered hook, every change readied by its owner
80 # through the repository's own valley. Ready changes of two owners are
81 # planned; a linear stack is one family, and so are two stacks on a
82 # shared lower layer. A draft, a withdrawn change, a lone plain branch, a
83 # change landed by fast-forward and an uncertain landing are left alone,
84 # and a family with a plain branch or a draft in it is held. A change
85 # with two versions uploaded by the restacker principal is held by the
86 # project's cap of 2. A request by name with no outcome holds; a current
87 # stale and a current reject release, the reject noted; an outcome about
88 # another head, tip or evidence, and one that does not read, hold.
89 # Requests by exact head and by range hold, the range's head fetched by
90 # the planner, and a request whose head is no commit holds every family.
91 # A cap larger than any int composes and is no practical cap, so the
92 # change the cap of 2 held is planned to restack. Every ref on origin is
93 # compared before and after each pass. Outcomes are injected on the
94 # server side, since no push may write one.
95 #
96 # Then the fixtures the publishing slice's tests stand on, each proved
97 # by a small test. The restacker principal pushes through the transport
98 # and cannot file a request, which requester can. A barrier holds a push
99 # before origin sees it and releases it, and one held there loses its
100 # lease to a push made while it waits; a barrier holds a push origin has
101 # taken; a dropped answer leaves origin holding a push its client
102 # reports as failed. A second pass on a state directory fails while a
103 # barrier holds the first, and a pass for another principal is refused
104 # it. In a repository served with the integrator's evidence fixtures
105 # (integrator/e2e: the nix stand-in and a policy of pure checks), the
106 # real integrator lands one change and rejects another whose signed
107 # evidence lies about its kind. The planner, reading the shared verifier
108 # keys, sees the landed change submitted, which it reads as uncertain
109 # without them, and releases the rejected change's family on the real
110 # outcome, noting the reject.
111 restack-e2e = pkgs.runCommand "valley-restack-e2e" {
112 nativeBuildInputs = [
113 pkgs.git
114 pkgs.jq
115 pkgs.cue
116 pkgs.openssh
117 packages.attest
118 packages.integrator
119 packages.valley-script
120 packages.valley-restacker
121 transport
122 ];
123 inherit initScript keys;
124 passAsFile = [ "initScript" ];
125 smokePolicy = ../../examples/policy/smoke;
126 integratorE2e = ../../integrator/e2e;
127 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
128 SCHEMA_VERIFICATION = ../../schema/verification.cue;
129 SCHEMA_EVENTS = ../../schema/events.cue;
130 } (builtins.readFile ./restack-e2e.sh);
131}