gunk-dev/the-valley

restack.nix

source5c91b2faf25bmain's published tip history
6.0 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, and with an author and a committer the environment
63 # injects as git configuration, a pass locks its state directory, the
64 # directory belongs to
65 # one repository, target and principal, and a cue or an ssh that never
66 # returns is killed at the deadline. Given the fixture host's rendered
67 # hook, the restack append is pushed through it as the restacker
68 # principal: the hook takes the active title and refuses a forged one,
69 # and takes a report from the restacker and not from the change's owner.
70 restack-unit = packages.restack-unwrapped.overrideAttrs {
71 inherit initScript;
72 passAsFile = [ "initScript" ];
73 preCheck = ''
74 VALLEY_RESTACK_TEST_HOOK="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)"
75 test -x "$VALLEY_RESTACK_TEST_HOOK"
76 export VALLEY_RESTACK_TEST_HOOK
77 '';
78 };
79
80 # valley-restacker once --report-only over a bare repository wired with
81 # the fixture host's rendered hook, every change readied by its owner
82 # through the repository's own valley. Ready changes of two owners are
83 # planned; a linear stack is one family, and so are two stacks on a
84 # shared lower layer. A draft, a withdrawn change, a lone plain branch, a
85 # change landed by fast-forward and an uncertain landing are left alone,
86 # and a family with a plain branch or a draft in it is held. A change
87 # with two versions uploaded by the restacker principal is held by the
88 # project's cap of 2. A request by name with no outcome holds; a current
89 # stale and a current reject release, the reject noted; an outcome about
90 # another head, tip or evidence, and one that does not read, hold.
91 # Requests by exact head and by range hold, the range's head fetched by
92 # the planner, and a request whose head is no commit holds every family.
93 # A cap larger than any int composes and is no practical cap, so the
94 # change the cap of 2 held is planned to restack. Every ref on origin is
95 # compared before and after each pass. Outcomes are injected on the
96 # server side, since no push may write one.
97 #
98 # Then the fixtures the publishing slice's tests stand on, each proved
99 # by a small test. The restacker principal pushes through the transport
100 # and cannot file a request, which requester can. A barrier holds a push
101 # before origin sees it and releases it, and one held there loses its
102 # lease to a push made while it waits; a barrier holds a push origin has
103 # taken; a dropped answer leaves origin holding a push its client
104 # reports as failed. A second pass on a state directory fails while a
105 # barrier holds the first, and a pass for another principal is refused
106 # it. A pass whose output nobody reads ends at its --timeout, and the
107 # next pass takes the lock. In a repository served with the integrator's evidence fixtures
108 # (integrator/e2e: the nix stand-in and a policy of pure checks), the
109 # real integrator lands one change and rejects another whose signed
110 # evidence lies about its kind. The planner, reading the shared verifier
111 # keys, sees the landed change submitted, which it reads as uncertain
112 # without them, and releases the rejected change's family on the real
113 # outcome, noting the reject.
114 restack-e2e = pkgs.runCommand "valley-restack-e2e" {
115 nativeBuildInputs = [
116 pkgs.git
117 pkgs.jq
118 pkgs.cue
119 pkgs.openssh
120 packages.attest
121 packages.integrator
122 packages.valley-script
123 packages.valley-restacker
124 transport
125 ];
126 inherit initScript keys;
127 passAsFile = [ "initScript" ];
128 smokePolicy = ../../examples/policy/smoke;
129 integratorE2e = ../../integrator/e2e;
130 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
131 SCHEMA_VERIFICATION = ../../schema/verification.cue;
132 SCHEMA_EVENTS = ../../schema/events.cue;
133 } (builtins.readFile ./restack-e2e.sh);
134}