gunk-dev/the-valley

restack.nix

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