| 1 | { |
| 2 | pkgs, |
| 3 | lib, |
| 4 | packages, |
| 5 | hosts, |
| 6 | nixStandIns, |
| 7 | ... |
| 8 | }: |
| 9 | let |
| 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 | }; |
| 56 | in |
| 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. |
| 83 | restack-unit = packages.restack-unwrapped.unit.overrideAttrs { |
| 84 | inherit initScript; |
| 85 | passAsFile = [ "initScript" ]; |
| 86 | preCheck = '' |
| 87 | VALLEY_RESTACK_TEST_HOOK="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)" |
| 88 | test -x "$VALLEY_RESTACK_TEST_HOOK" |
| 89 | export VALLEY_RESTACK_TEST_HOOK |
| 90 | ''; |
| 91 | }; |
| 92 | |
| 93 | # valley-restacker once --report-only over a bare repository wired with |
| 94 | # the fixture host's rendered hook, every change readied by its owner |
| 95 | # through the repository's own valley. Ready changes of two owners are |
| 96 | # planned; a linear stack is one family, and so are two stacks on a |
| 97 | # shared lower layer. A draft, a withdrawn change, a lone plain branch, a |
| 98 | # change landed by fast-forward and an uncertain landing are left alone, |
| 99 | # and a family with a plain branch or a draft in it is held. A change |
| 100 | # with two versions uploaded by the restacker principal is held by the |
| 101 | # project's cap of 2. A request by name with no outcome holds; a current |
| 102 | # stale and a current reject release, the reject noted; an outcome about |
| 103 | # another head, tip or evidence, and one that does not read, hold. |
| 104 | # Requests by exact head and by range hold, the range's head fetched by |
| 105 | # the planner, and a request whose head is no commit holds every family. |
| 106 | # A cap larger than any int composes and is no practical cap, so the |
| 107 | # change the cap of 2 held is planned to restack. Its writes are built |
| 108 | # as a complete restack, and a held family's as a blocked report. A |
| 109 | # request at an older version's head, and one on top of it, each hold |
| 110 | # that change's family whatever their names. With git variables that |
| 111 | # point git at a decoy inherited, the pass plans and builds the same and |
| 112 | # leaves the decoy untouched, and a pass whose stderr nobody reads still |
| 113 | # ends. Every ref on origin is compared before and after each pass. |
| 114 | # Outcomes are injected on the server side, since no push may write one. |
| 115 | # |
| 116 | # Then the fixtures the publishing slice's tests stand on, each proved |
| 117 | # by a small test. The restacker principal pushes through the transport |
| 118 | # and cannot file a request, which requester can. A barrier holds a push |
| 119 | # before origin sees it and releases it, and one held there loses its |
| 120 | # lease to a push made while it waits; a barrier holds a push origin has |
| 121 | # taken; a dropped answer leaves origin holding a push its client |
| 122 | # reports as failed. A second pass on a state directory fails while a |
| 123 | # barrier holds the first, and a pass for another principal is refused |
| 124 | # it. A pass whose output nobody reads ends at its --timeout, and the |
| 125 | # next pass takes the lock. In a repository served with the integrator's evidence fixtures |
| 126 | # (integrator/e2e: the nix stand-in and a policy of pure checks), the |
| 127 | # real integrator lands one change and rejects another whose signed |
| 128 | # evidence lies about its kind. The planner, reading the shared verifier |
| 129 | # keys, sees the landed change submitted, which it reads as uncertain |
| 130 | # without them or while a signer projects file restricts the integrator |
| 131 | # name, and releases the rejected change's family on the real outcome, |
| 132 | # noting the reject. A signer projects file that does not read stops |
| 133 | # the pass. |
| 134 | restack-e2e = pkgs.runCommand "valley-restack-e2e" { |
| 135 | nativeBuildInputs = [ |
| 136 | pkgs.git |
| 137 | pkgs.jq |
| 138 | pkgs.cue |
| 139 | pkgs.openssh |
| 140 | packages.attest |
| 141 | packages.integrator |
| 142 | packages.valley-script |
| 143 | packages.valley-restacker |
| 144 | transport |
| 145 | ]; |
| 146 | inherit initScript keys; |
| 147 | passAsFile = [ "initScript" ]; |
| 148 | smokePolicy = ../../examples/policy/smoke; |
| 149 | integratorE2e = nixStandIns; |
| 150 | SCHEMA_ATTESTATION = ../../schema/attestation.cue; |
| 151 | SCHEMA_VERIFICATION = ../../schema/verification.cue; |
| 152 | SCHEMA_EVENTS = ../../schema/events.cue; |
| 153 | } (builtins.readFile ./restack-e2e.sh); |
| 154 | } |