gunk-dev/the-valley

restack.nix

sourcee612ba14a52bmain's published tip history
8.5 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; and
70 # once --report-only decides a journal of pending writes and pushes none
71 # of them. A conflict on more than 100 paths keeps them all in the
72 # journal. No inherited git variable, nor the user's attributes file,
73 # reaches a pass, and a process whose stderr nobody reads still ends. Its
74 # scratch repository commits as its flags say with no identity in the
75 # environment, and with an author and a committer the environment
76 # injects as git configuration, a pass locks its state directory, the
77 # directory belongs to one repository, target and principal, and a cue
78 # or an ssh that never returns is killed at the deadline. Given the
79 # fixture host's rendered hook, the restack append is pushed through it
80 # as the restacker principal: the hook takes the active title and
81 # refuses a forged one, and takes a report from the restacker and not
82 # from the change's owner. Through the same hook, write passes run as
83 # once runs them: after a landing, a two-owner stack is restacked once,
84 # each layer on the new one below it, while a conflict beside it moves
85 # nothing, is reported, and is not tried again; a request holds its
86 # family until its outcome is a current stale; a journal left after
87 # any of its steps is finished with one version per change; an owner's
88 # push to a restacked branch stops that version, reported partial; a
89 # request between the phases pauses the versions and keeps the journal
90 # open until it is released; the project's cap holds; and run converges
91 # on a change readied after the landing, and ends when stopped.
92 restack-unit = packages.restack-unwrapped.unit.overrideAttrs {
93 inherit initScript;
94 passAsFile = [ "initScript" ];
95 preCheck = ''
96 VALLEY_RESTACK_TEST_HOOK="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)"
97 test -x "$VALLEY_RESTACK_TEST_HOOK"
98 export VALLEY_RESTACK_TEST_HOOK
99 '';
100 };
101
102 # valley-restacker once --report-only over a bare repository wired with
103 # the fixture host's rendered hook, every change readied by its owner
104 # through the repository's own valley. Ready changes of two owners are
105 # planned; a linear stack is one family, and so are two stacks on a
106 # shared lower layer. A draft, a withdrawn change, a lone plain branch, a
107 # change landed by fast-forward and an uncertain landing are left alone,
108 # and a family with a plain branch or a draft in it is held. A change
109 # with two versions uploaded by the restacker principal is held by the
110 # project's cap of 2. A request by name with no outcome holds; a current
111 # stale and a current reject release, the reject noted; an outcome about
112 # another head, tip or evidence, and one that does not read, hold.
113 # Requests by exact head and by range hold, the range's head fetched by
114 # the planner, and a request whose head is no commit holds every family.
115 # A cap larger than any int composes and is no practical cap, so the
116 # change the cap of 2 held is planned to restack. Its writes are built
117 # as a complete restack, and a held family's as a blocked report. A
118 # request at an older version's head, and one on top of it, each hold
119 # that change's family whatever their names. With git variables that
120 # point git at a decoy inherited, the pass plans and builds the same and
121 # leaves the decoy untouched, and a pass whose stderr nobody reads still
122 # ends. Every ref on origin is compared before and after each pass.
123 # Outcomes are injected on the server side, since no push may write one.
124 #
125 # Then the fixtures the publishing slice's tests stand on, each proved
126 # by a small test. The restacker principal pushes through the transport
127 # and cannot file a request, which requester can. A barrier holds a push
128 # before origin sees it and releases it, and one held there loses its
129 # lease to a push made while it waits; a barrier holds a push origin has
130 # taken; a dropped answer leaves origin holding a push its client
131 # reports as failed. A second pass on a state directory fails while a
132 # barrier holds the first, and a pass for another principal is refused
133 # it. A pass whose output nobody reads ends at its --timeout, and the
134 # next pass takes the lock. In a repository served with the integrator's evidence fixtures
135 # (integrator/e2e: the nix stand-in and a policy of pure checks), the
136 # real integrator lands one change and rejects another whose signed
137 # evidence lies about its kind. The planner, reading the shared verifier
138 # keys, sees the landed change submitted, which it reads as uncertain
139 # without them or while a signer projects file restricts the integrator
140 # name, and releases the rejected change's family on the real outcome,
141 # noting the reject. A signer projects file that does not read stops
142 # the pass.
143 #
144 # Then write passes through the transport, as the restacker principal,
145 # after the real landing: a change bob readied on the seed and the
146 # rejected change are each restacked once, onto main's tip, under their
147 # owners, with reports that say complete, and the rejected change's
148 # request still names its old head. The answer to the first record push
149 # is dropped, so origin takes it and the pass hears nothing; the pass's
150 # next read finds the version, and it is added once. A second pass
151 # pushes nothing.
152 restack-e2e = pkgs.runCommand "valley-restack-e2e" {
153 nativeBuildInputs = [
154 pkgs.git
155 pkgs.jq
156 pkgs.cue
157 pkgs.openssh
158 packages.attest
159 packages.integrator
160 packages.valley-script
161 packages.valley-restacker
162 transport
163 ];
164 inherit initScript keys;
165 passAsFile = [ "initScript" ];
166 smokePolicy = ../../examples/policy/smoke;
167 integratorE2e = nixStandIns;
168 SCHEMA_ATTESTATION = ../../schema/attestation.cue;
169 SCHEMA_VERIFICATION = ../../schema/verification.cue;
170 SCHEMA_EVENTS = ../../schema/events.cue;
171 } (builtins.readFile ./restack-e2e.sh);
172}