gunk-dev/the-valley

restack.nix

source1b2b54e2eea2main's published tip history
9.4 KiB
1{
2 pkgs,
3 lib,
4 packages,
5 hosts,
6 nixStandIns,
7 ...
8}:
9let
10 # Throwaway keys, made once at build time: the contributor's, which signs
11 # evidence, and the integrator's, which signs what it lands. They hold no
12 # authority anywhere. known_signers is the one verifier file the rendered
13 # hook, the integrator and the restacker all read, under the names each
14 # signs as.
15 keys =
16 pkgs.runCommand "valley-restack-e2e-keys"
17 {
18 nativeBuildInputs = [
19 pkgs.openssh
20 packages.attest
21 ];
22 }
23 ''
24 mkdir $out
25 for who in contributor integrator; do
26 ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$out/$who"
27 done
28 attest key --key "$out/contributor" --name contributor.valley.invalid/attestations > "$out/known_signers"
29 attest key --key "$out/integrator" --name integrator.valley.invalid/attestations >> "$out/known_signers"
30 '';
31
32 # The protected host, with its hook checking evidence against those keys
33 # rather than a file under /var/lib that no sandbox holds. Its grants are
34 # the protected host's: requester holds request and restack, and
35 # restacker holds restack alone.
36 host = hosts.protectedHost.extendModules {
37 modules = [
38 { services.valley.integrator.knownSignersFile = lib.mkForce "${keys}/known_signers"; }
39 ];
40 };
41 initScript = host.config.systemd.services.valley-init.script;
42
43 # The transport the end-to-end tests reach origin through: a stand-in for
44 # ssh that serves pushes and fetches with the real receive-pack and
45 # upload-pack, and holds or cuts one where a test chooses
46 # (restack/e2e/transport). Go, standard library only.
47 transport = pkgs.buildGoModule {
48 pname = "valley-restack-transport";
49 version = "0";
50 src = ../../restack/e2e/transport;
51 vendorHash = null;
52 postInstall = ''
53 mv $out/bin/transport $out/bin/valley-restack-transport
54 '';
55 };
56in
57{
58 # The restacker's own tests (restack/), in its unit build: how a
59 # request relates to a family, by every version head a change has had,
60 # which outcomes are current and which release a family, the arithmetic
61 # of each capacity limit, and how the policy's cap is counted, one larger
62 # than any int included. A report that holds more than the format allows
63 # falls back within every bound, and two reports are the same by what
64 # they say, whatever operation wrote them. Against real git: every write
65 # is built and kept in the journal before any push, with origin
66 # untouched; recovery decides each write against origin as a test makes
67 # the pushes, author movement, withdrawal, unreadying, a deleted record,
68 # a moved or rewritten main and a request each stop what they must; a
69 # lost, foreign or malformed journal is never decided, nor one that
70 # records accepted writes the family does not have; and once
71 # --report-only decides a journal of pending writes and pushes none of
72 # them. A family of 65 changes whose top version was not added keeps a
73 # partial replacement for each change, listing only that change's own
74 # layer. A conflict on more than 100 paths keeps them all in the journal,
75 # and a write pass that reports it writes the full observation to the
76 # state-directory file named by the report, which outlives the journal.
77 # No inherited git variable, nor the user's attributes file, reaches a
78 # pass, and a process whose stderr nobody reads still ends. Its
79 # scratch repository commits as its flags say with no identity in the
80 # environment, and with an author and a committer the environment
81 # injects as git configuration, a pass locks its state directory, the
82 # directory belongs to one repository, target and principal, and a cue
83 # or an ssh that never returns is killed at the deadline. Given the
84 # fixture host's rendered hook, the restack append is pushed through it
85 # as the restacker principal: the hook takes the active title and
86 # refuses a forged one, and takes a report from the restacker and not
87 # from the change's owner. Through the same hook, write passes run as
88 # once runs them: after a landing, a two-owner stack is restacked once,
89 # each layer onto the new layer below it, while a conflict beside it
90 # moves nothing, is reported, and is skipped on the next pass; a request
91 # holds its family until its outcome is a current stale; an interrupted
92 # journal finishes with one version per change; an owner's push to a
93 # restacked branch stops that version and produces a partial replacement
94 # report; a refused partial report stays in the journal until pushed, is
95 # pushed once when its reply is lost, and is still pushed after the
96 # author rewrites or deletes every branch the family moved; a report
97 # that origin keeps refusing holds only its own family in the journal,
98 # while a family restacked beside it is retired and restacked again
99 # after the next landing; two ready changes that name the same branch
100 # both wait while a change beside them is restacked; a request filed
101 # between phases pauses the versions and keeps the family open until
102 # released, while an unrelated change readied beside it is restacked;
103 # the project's cap holds a change at its limit; and run converges on a
104 # change readied after the landing and exits when stopped.
105 restack-unit = packages.restack-unwrapped.unit.overrideAttrs {
106 inherit initScript;
107 passAsFile = [ "initScript" ];
108 preCheck = ''
109 VALLEY_RESTACK_TEST_HOOK="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)"
110 test -x "$VALLEY_RESTACK_TEST_HOOK"
111 export VALLEY_RESTACK_TEST_HOOK
112 '';
113 };
114
115 # valley-restacker once --report-only over a bare repository wired with
116 # the fixture host's rendered hook, every change readied by its owner
117 # through the repository's own valley. Ready changes of two owners are
118 # planned; a linear stack is one family, and so are two stacks on a
119 # shared lower layer. A draft, a withdrawn change, a lone plain branch, a
120 # change landed by fast-forward and an uncertain landing are left alone,
121 # and a family with a plain branch or a draft in it is held. A change
122 # with two versions uploaded by the restacker principal is held by the
123 # project's cap of 2. A request by name with no outcome holds; a current
124 # stale and a current reject release, the reject noted; an outcome about
125 # another head, tip or evidence, and one that does not read, hold.
126 # Requests by exact head and by range hold, the range's head fetched by
127 # the planner, and a request whose head is no commit holds every family.
128 # A cap larger than any int composes and is no practical cap, so the
129 # change the cap of 2 held is planned to restack. Its writes are built
130 # as a complete restack, and a held family's as a blocked report. A
131 # request at an older version's head, and one on top of it, each hold
132 # that change's family whatever their names. With git variables that
133 # point git at a decoy inherited, the pass plans and builds the same and
134 # leaves the decoy untouched, and a pass whose stderr nobody reads still
135 # ends. Every ref on origin is compared before and after each pass.
136 # Outcomes are injected on the server side, since no push may write one.
137 #
138 # Then the fixtures the publishing slice's tests stand on, each proved
139 # by a small test. The restacker principal pushes through the transport
140 # and cannot file a request, which requester can. A barrier holds a push
141 # before origin sees it and releases it, and one held there loses its
142 # lease to a push made while it waits; a barrier holds a push origin has
143 # taken; a dropped answer leaves origin holding a push its client
144 # reports as failed. A second pass on a state directory fails while a
145 # barrier holds the first, and a pass for another principal is refused
146 # it. A pass whose output nobody reads ends at its --timeout, and the
147 # next pass takes the lock. In a repository served with the integrator's evidence fixtures
148 # (integrator/e2e: the nix stand-in and a policy of pure checks), the
149 # real integrator lands one change and rejects another whose signed
150 # evidence lies about its kind. The planner, reading the shared verifier
151 # keys, sees the landed change submitted, which it reads as uncertain
152 # without them or while a signer projects file restricts the integrator
153 # name, and releases the rejected change's family on the real outcome,
154 # noting the reject. A signer projects file that does not read stops
155 # the pass.
156 #
157 # Finally, write passes run over the SSH transport as the restacker
158 # principal after the real landing: a change readied on the seed and the
159 # rejected change are each restacked once onto main's tip under their
160 # owners, with complete reports, while the rejected change's request
161 # still points at its old head. The reply to the first record push is
162 # dropped after origin accepts it, and the next read sees the version on
163 # origin so it is added only once. A second write pass pushes nothing.
164 restack-e2e = pkgs.runCommand "valley-restack-e2e" {
165 nativeBuildInputs = [
166 pkgs.git
167 pkgs.jq
168 pkgs.cue
169 pkgs.openssh
170 packages.attest
171 packages.integrator
172 packages.valley-script
173 packages.valley-restacker
174 transport
175 ];
176 inherit initScript keys;
177 passAsFile = [ "initScript" ];
178 smokePolicy = ../../examples/policy/smoke;
179 integratorE2e = nixStandIns;
180 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
181 SCHEMA_VERIFICATION = ../../schema/verification.cue;
182 SCHEMA_EVENTS = ../../schema/events.cue;
183 } (builtins.readFile ./restack-e2e.sh);
184}