Repository navigation
Conversation
This was referenced Nov 25, 2026
sodre
added a commit
that referenced
this pull request
Nov 25, 2026
…c reads (#63) Closes #62 ## Summary A grant worker no longer dies, and its grant is no longer fenced, when a connection frees a large response or when nine or more connections run at once. The C library's malloc used to open a file at those moments, and the worker sandbox killed the grant worker for it. glibc's malloc opens a file the first time it needs one of two values. `openat` is outside the allow-list, and ADR 0001's decision 5 makes every such call a kill: | When | File glibc opens | |---|---| | A thread's heap shrinks for the first time: a connection thread freed more than the trim threshold, 128 KiB | `/proc/sys/vm/overcommit_memory` | | A ninth thread needs a malloc arena: nine connections at once | `/sys/devices/system/cpu/online` | `confine()` now settles both before any layer goes on, so decision 5 stands with no new exception: ```diff confine() + settle_malloc() # while files can still be read + mallopt(M_ARENA_MAX, 8 × CPUs in the affinity mask) # glibc's own limit: it never counts CPUs + mallopt(M_TRIM_THRESHOLD, 128 KiB) # glibc's default, held fixed + a warm-up thread frees 1 MiB # one heap shrinks, and glibc caches the overcommit policy non-dumpable, no_new_privs, Landlock, seccomp allow-list ``` The warm-up thread ends before the first layer, since each layer binds only the calling thread. `docs/develop.md`'s section "A grant worker died of SIGSYS" now names this symptom. ### Extras for the owner - **The trim threshold is held at glibc's default.** #62's decided fix sets `M_ARENA_MAX` and frees a block on a warm-up thread; it does not set `M_TRIM_THRESHOLD`. Review round 1 found that a block of 1 MiB or more freed before confinement raises glibc's moving trim threshold above the warm-up, so the warm-up then caches nothing. It was measured: 2 MiB freed before `confine()`, then 8 MiB freed after it, killed the process (exit 159). Holding the threshold at 128 KiB closes that, and also stops glibc's moving mmap threshold for the grant worker, so a block of 128 KiB or more is always mapped on its own. Today a grant worker calls `confine()` before it allocates anything large (`main.rs`), so the gap needs future code to open. No source settles it. - [x] Widen #62 (recommended: it keeps the warm-up from failing silently, at a small cost for a TLS relay) - [ ] A new ticket - [ ] Record only - Applied: criterion added to #62 ("After a block of 2 MiB is freed before confinement, …") and its decided fix; the containment test `a_large_block_freed_before_confinement_leaves_the_warm_up_working` holds it, in f4b53ed, which changes only that test, so no review round ran on it ## Evidence | Criterion | Ticked | Shown by | |---|---|---| | A confined stand-in survives a thread that allocates and frees more than the trim threshold, and goes on serving | yes | `a_thread_that_frees_a_large_heap_leaves_the_grant_worker_serving` | | A confined stand-in survives sixteen threads allocating at once, and goes on serving | yes | `sixteen_threads_at_once_leave_the_grant_worker_serving` | | After a block of 2 MiB is freed before confinement, a confined stand-in still survives a thread that frees more than the trim threshold: the threshold is held at glibc's default | yes | `a_large_block_freed_before_confinement_leaves_the_warm_up_working` | | Both checks are in the containment test, so they run on x86-64 and arm64 and under the filter sandbox's container | yes | CI on 20ba1c4: `workspace (ubuntu-latest)` and `gateway-filter-sandbox (ubuntu-24.04)` on x86-64, 28 passed, 0 failed; `gateway-filter-sandbox (ubuntu-24.04-arm)`, 26 passed, 0 failed; each printing both tests `... ok` | | The runtime test passes under both worker sandboxes | yes | `runtime.py` with `--worker-sandbox namespaces` and `--worker-sandbox filter` | | Test | Red | Green | |---|---|---| | `a_thread_that_frees_a_large_heap_leaves_the_grant_worker_serving` | Against `main` (c612768), and again at 4ab3b5a with `settle_malloc` stubbed out: ``stand-in 0, `free-heap`: expected a reply, got Killed(31)`` | ok | | `sixteen_threads_at_once_leave_the_grant_worker_serving` | The same two ways: ``stand-in 0, `threads 16`: expected a reply, got Killed(31)`` | ok | | The trim threshold held (review) | A throwaway program, with 2 MiB freed before `confine()` and 8 MiB freed on a thread after it: exit 159 (SIGSYS) at 24ea0ea | exit 0 | | `a_large_block_freed_before_confinement_leaves_the_warm_up_working` (widening) | With `M_TRIM_THRESHOLD` left unset on purpose: ``stand-in 0, `free-heap`: expected a reply, got Killed(31)``, 26 passed, 1 failed | ok | On f4b53ed, the widening's test added, Linux arm64: `cargo test --locked -p countersign-gateway`, every suite ok, the containment test 27 passed, 0 failed; `scripts/filter-sandbox-container.sh`, exit 0 in 75 s, its containment test 27 passed, 0 failed; `cargo fmt --check` and clippy clean. Runs on 20ba1c4, Linux arm64, glibc 2.39, kernel 6.17: - `cargo test --locked -p countersign-gateway`: every suite ok. The containment test: 26 passed, 0 failed. - `cargo fmt --all -- --check` and `cargo clippy --locked -p countersign-gateway --all-targets -- -D warnings`: clean. - `python3 crates/countersign-gateway/tests/runtime.py target/debug/countersign-gateway --worker-sandbox namespaces`, and the same with `filter`: exit 0. - `scripts/filter-sandbox-container.sh`: exit 0 in 71 s. - A throwaway program that confines itself with `confine()`, as the diagnosis did, then exits 0 in each of these cases. Before the fix, 9 threads, 16 × 16 KiB freed and the 2 MiB pre-free case each died with exit 159. - 9, 16 and 32 threads allocating at once; - one thread freeing 64 × 16 KiB; - 32 threads with one CPU in the affinity mask (`taskset -c 0`); - the 2 MiB pre-free case. - The diagnosis: `strace` of the same cases unconfined names the two files. The kernel's audit line from the failed CI run, [run 45536441028](https://github.com/zeroae/countersign/actions/runs/45536441028/job/138944076394), names `syscall=257` (`openat`, x86-64) for `comm="worker"`. CI on 20ba1c4: all 28 checks passed, among them the end-to-end `curl` job on x86-64 whose failure on #61 was this bug, and the Documentation workflow's `mkdocs build --strict`. CI on f4b53ed: all 28 checks passed. The new test printed `... ok` in `workspace (ubuntu-latest)` and `gateway-filter-sandbox (ubuntu-24.04)` on x86-64, 29 passed, 0 failed, and in `gateway-filter-sandbox (ubuntu-24.04-arm)`, 27 passed, 0 failed. Not run: nothing. ## Merge Danger **Door:** two-way. A revert brings the kill back, nothing stored changes. **Blast Radius:** every grant worker's memory allocator. Nothing deploys on the merge: the `countersign-gateway` crate and the `ghcr.io/zeroae/countersign-gateway` image ship at the next version tag. No flag. After the merge, #61 is rebased onto it and its CI runs again, since the x86-64 failure there was this bug. ## Reviews <details> <summary>Correctness, Standards, Spec and Security, three rounds: 15 findings in round 1, 2 in round 2, none in round 3; the widening's commit changes only a test, so no round ran on it</summary> **Correctness, round 1** (at `medium`, on 24ea0ea against `origin/main` c612768) 1. The warm-up caches the overcommit policy only if its free shrinks the heap, and a raised trim threshold stops that without a word. Fixed: the trim threshold is held at glibc's default before the warm-up (measured; an extra for the owner, under Summary). 2. A `settle_malloc` failure is reported as the seccomp allow-list layer. Pushed back: the warm-up exists for the allow-list, and its errors carry their own words ("malloc refused option …", "the malloc warm-up thread panicked"), as `no_new_privs`' error does under the same layer. 3. `std::thread::spawn` panics when the kernel refuses a thread. Fixed: `std::thread::Builder::spawn`, whose error `confine()` returns. 4. The arena limit was not glibc's own on every glibc version. Fixed: in round 2, the CPUs in the affinity mask, which glibc 2.36 in the Gateway's image counts. 5. Answer `openat` with an error, as `clone3` is answered, rather than settle each read. Pushed back: the owner chose the warm-up on #62, which keeps ADR 0001's decision 5 with no new exception. 6. On glibc 2.35 to 2.38, the sixteen-thread test passes without the arena limit. Pushed back: CI and this host run glibc 2.39, where the test is red without the fix. 7. The regression test copied the warm-up's shape. Fixed: it frees 8 MiB in 4 KiB blocks. 8. `confine()` did not say why the warm-up thread must end before the first layer. Fixed: its comment says each layer binds only the calling thread. **Standards, round 1** 9. Possible Mysterious Name: the warm-up's errors under the allow-list layer. Pushed back, as finding 2. 10. Possible Duplicated Code: the test and the warm-up. Fixed, as finding 7. 11. Possible Primitive Obsession: the warm-up's numbers. Fixed: `TRIM_THRESHOLD` and `WARM_UP_BLOCK`. 12. A SAFETY comment also held what `mallopt` returns. Fixed: that note has its own line. 13. The 16 in the sixteen-thread test. Pushed back: the test's comment ties it to the ninth and later arenas. 14. The guide's new rule might belong in an ADR. Fixed: the paragraph names the symptom and cites ADR 0001's decision 5, with no rule of its own. **Spec, round 1** 15. The paragraph in `docs/develop.md` was not asked for. Pushed back: the guide's section on a grant worker killed by SIGSYS is where the next person looks for this symptom, and the paragraph now holds only that. **Security, round 1**: no findings. **Spec, round 2** (fix round at `low`, on 4ab3b5a against 24ea0ea; Correctness, Standards and Security found nothing) 16. Holding `M_TRIM_THRESHOLD` is not in #62's decided fix, and it stops glibc's moving thresholds. Fixed: the owner widened #62 to include it (Extras for the owner), and a containment test now holds it. 17. `available_parallelism` applies the cgroup quota, so the limit was not glibc's own. Fixed: the CPUs in the affinity mask, then the online CPUs. **Round 3** (fix round at `low`, on 20ba1c4 against 4ab3b5a): Correctness, Standards, Spec and Security found nothing. </details> ## Tracking Epic: none Spec: none Ticket: #62 A grant worker is killed when the C library's malloc opens a file Flag: none 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ser stories Spec #49's user stories 8, 11, 17, 21, 37, 38 and 42 had no test, or a test that proved less than the story. Each now has a case in the runtime test, at the real Gateway binary: - a wildcard rule reaches a host under it through the egress proxy (8); - a private rule after a proxied rule stops startup, by name (11); - the egress proxy's name is resolved again on each connection (17); - an egress proxy that never answers gives proxy_unavailable at the deadline, in its own CI step (21); - a site outside the rule's roots gets no signature through the egress proxy (37); - a name without a Gateway rule, or without a grant, never reaches the egress proxy (38); - proxy environment variables do not override egress_proxy (42). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- story 17 moves the egress proxy's name to a second, working egress proxy and back, so the test sees where each CONNECT went; - the silent egress proxy case runs under both worker sandboxes, and takes --landlock as the other passes do; - the second private rule's pattern no longer holds its id, so the error must name the rule; - one helper reads the site for the direct and wildcard routes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ad as ended Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sodre
marked this pull request as ready for review
November 25, 2026 14:36
This was referenced Nov 25, 2026
sodre
added a commit
that referenced
this pull request
Nov 25, 2026
…rator's egress proxy is in git (#66) Closes #49 ## Summary The text of the spec "Reach protected sites through an operator's egress proxy" is in the repository at `docs/specs/E2-49-reach-protected-sites-through-an-operator-s-egress-proxy.md`, as the issue held it when the spec closed. Nothing changes for anyone using the product. ```text docs/specs/ └── E2-49-reach-protected-sites-through-an-operator-s-egress-proxy.md # accepted, exported 2026-11-24 ``` Before this closing, each of the spec's 53 user stories was mapped to the test, static check or live run that proves it (the table under Evidence). On `d5b15ba`, the squash of #55, seven stories (8, 11, 17, 21, 37, 38 and 42) held but were only partly tested: a Gateway broken on purpose still passed every test. #61 added their cases, building #60, a sub-issue of this spec that is now done. Story 52's Fargate step stays out of scope, as the spec's Out of Scope says. #61's body named "the pull request that closes #49", and GitHub read that as a closing keyword: #49 closed when #61 merged. It was reopened so that this pull request closes it, as `docs/agents/issue-tracker.md` ("Closing a spec") asks. The verification also found #62: on x86-64, a grant worker was killed when glibc's malloc opened a file, which failed #61's `curl` job. #63 fixed it, and both are in Countersign 0.2.2 (`v0.2.2`). #62 has no milestone, so it never held this spec open. ## Evidence | Criterion | Ticked | Shown by | |---|---|---| | Every sub-issue of #49 is closed | yes | `export-spec.py 49` | | No issue but the spec is open in E2 | yes | `export-spec.py 49` | | The spec has no release flag | yes | The spec's Further Notes: "**Flag: none.**" | | The file's text after its header is the issue's body | yes | The comparison below | | Every user story is proven by a test, a static check or a live run | yes | The user-story table below | No test or guard is new here: the seven cases #61 added were each shown red there against a Gateway broken on purpose, and green against the real one. `python3 .claude/plugins/foresight/scripts/export-spec.py 49`, run on 59f95a9 after #61 and #65 merged: `wrote … as accepted: every sub-issue is closed and only specs are open in E2 Reach protected sites through an operator's egress proxy, so the pull request that adds this file closes #49`. The sub-issues are #50, #51, #52, #53 and #60, all closed. The text it wrote after the header is the same as the committed file's; only its export day differed, so the committed file, exported 2026-11-24, stands. A comparison of the file's text after its header with `gh issue view 49 --json body`, CRLF read as LF: 20104 bytes in each, the same. Not run: nothing. <details> <summary>The 53 user stories of #49: 39 Test, 12 Static, 10 Live run (eight stories have two verdicts), 0 Partial, 0 Gap</summary> Checked on `main` at 59f95a9, the squash of #65 (Countersign 0.2.2), which holds #55's egress proxy and #61's cases for the stories marked (#61). - **The runtime test** is `crates/countersign-gateway/tests/runtime.py`. Line numbers below are at 59f95a9. On 59f95a9, CI's *Sidecar mTLS* run [45638935969](https://github.com/zeroae/countersign/actions/runs/45638935969) passed it in all four jobs (`gateway-arm64`, `curl`, and `gateway-filter-sandbox` on x86-64 and arm64). Each job printed `sidecar/shared Gateway mTLS passed`, `sidecar/shared Gateway mTLS through the egress proxy passed` and `sidecar/shared Gateway without a usable egress proxy failed closed`, and `gateway-arm64` ran the silent egress proxy's step under both worker sandboxes. - **The Compose run** is the `compose_demo.py --squid --verify` output posted on #52, from 5d76a8b with Squid 6.14. #55's body records a pass on d84d66d too, but that run's output was not posted. - **Documents:** a Static row whose proof is a document was checked by reading that document on `main`. CI's `mkdocs build --strict` checks only its links, not its words. | # | Story (shortened) | Verdict | What proves it | Notes | |---|---|---|---|---| | 1 | Set `egress_proxy` once and every site goes through it | Test | Proxied pass. `egress.take() == through_egress` (734). Every failing rule's CONNECT is recorded by the test proxy (760–783). | One `egress_proxy` line; every rule but `direct` goes through it. | | 2 | Every destination uses the egress proxy by default | Test | Same pass. The rules `site` and `refused` … `wrong` have no `egress` field (516) and reach the proxy (734, 760–783). | | | 3 | `"egress": "direct"` on one rule; one Gateway serves both routes | Test | `res = request(user, to=direct)` returns the fingerprint, then `assert egress.take() == [], 'A direct destination went through the egress proxy'` (735–738). | #55's red run: route choice broken to always use the proxy → 502. | | 4 | No egress proxy: configuration and behaviour unchanged | Test | Direct passes `sidecar/shared Gateway mTLS passed`. Their assertions are unchanged from before #55; the diff only refactors the grant fixture. The shared pass adds `"egress": "direct"` (535–538). | | | 5 | The Gateway sends the site's name to the egress proxy | Test | `assert egress.take() == [f'CONNECT {host} HTTP/1.1'] * len(users)` (731–734), with `host = 'site.test:<port>'`. | | | 6 | No resolution on a proxied route, for a network with no external DNS | Test | `assert resolved.returncode == 2, ('The Gateway could resolve the site itself', resolved)` (571–575) runs under the Gateway's own NSS environment, and the proxied pass then succeeds. | Proves the Gateway cannot resolve `site.test` and works anyway. It does not prove the Gateway never tries a lookup, which the story does not need. | | 7 | A private site through the proxy, with a rule that has no `private_networks` | Test; Live run | Runtime: the `site` rule loses `private_networks` (512) and the site is at the host's interface address. Compose: the site is at 172.31.0.2 and the rule has no `private_networks` (#52 run, `docs/develop.md`). | Whether the runtime test's address is private depends on the host. The Compose run's address always is. | | 8 | A wildcard rule works through the egress proxy | Test (#61) | A proxied rule `*.wild.test:<port>` without `private_networks`: `reads_site(user, wild)` for each user, then `assert egress.take() == [f'CONNECT {wild} HTTP/1.1'] * len(users)` (740–742). | #61's red runs: a wildcard rule refused on a proxied route at request time (403) and at load (the Gateway exits). | | 9 | Startup refused when a proxied rule has `private_networks` | Test | `egress_configuration`: `error = refused('http://proxy.test:3128', **base)` (438). `refuses()` asserts a non-zero exit and no stdout from both `env` and `serve` (403–412). | #55's red run: `serve` started (`TimeoutExpired`). | | 10 | That error names the rule and both fixes | Test | `assert re.search(r'\bsite\b', error) and 'private_networks' in error` and `assert 'remove' in error and '"egress": "direct"' in error` (439–440). | | | 11 | Adding `egress_proxy`: every undecided private rule stops startup | Test (#61) | `egress_configuration`: `[rule, second]`, the private rule second. `refuses()` from `env` and `serve`, then `assert re.search(r'\bsecond\b', error) and 'private_networks' in error` (441–446). | #61's red run: the check limited to the first rule let `serve` start. | | 12 | An `https` egress proxy URL refused at startup | Test | `error = refused('https://proxy.test:3128')`, then `assert 'egress_proxy' in error and 'https' in error` (418–419). | | | 13 | An egress proxy URL with credentials refused at startup | Test | `assert 'egress_proxy' in error and 'credentials' in error and 'secret' not in error` for `user:secret@` and `user@` (420–422). | The error also does not echo the secret. | | 14 | An unknown `egress` value fails loading | Test | `refused(..., egress=value)` for `'proxy', 'default', 'Direct', 'none', '', None, True, ['direct']`, with and without an egress proxy (447–449). | | | 15 | `env` refuses what `serve` refuses | Test | `refuses()`: `assert results[0].stderr == results[1].stderr` across `env` and `serve` (409). Every refusal above goes through it, and so does the wildcard-with-`private_networks` rule (430–433). | | | 16 | Startup logs which destinations leave address policy to the proxy | Test | `wait_for_log(rf'Gateway egress proxy localhost:<port> carries the address policy of destinations: ' + ', '.join(['site', *failing, 'wild', 'ungranted']))`, a full match that leaves out `direct` (620–622). | | | 17 | The egress proxy's name resolved on every connection | Test (#61) | `egress_proxy` is `http://proxy.test:<port>`, resolved only through the Gateway's hosts file. The name moves to a second egress proxy on 127.0.0.2: `assert moved.take() == [f'CONNECT {host} HTTP/1.1'], 'The Gateway did not follow the egress proxy'`. Moved back: `'The Gateway did not follow the egress proxy back'` (748–758). | #61's red run: resolving once and caching fails at `The Gateway did not follow the egress proxy`. | | 18 | The egress proxy allowed on a private address | Test; Live run | The test proxy listens on 127.0.0.1, the address the Gateway's hosts file gives `proxy.test`, inside the special-use blocks, and is reached with no `private_networks` (511, 549). In Compose, Squid is on the private backend network, where Squid logs the Gateway as 192.168.32.5. | | | 19 | `denied_networks` still applied to the proxy's address | Test | Unusable pass with `denied_networks: ['127.0.0.0/8', '::1/128']` (930): `proxy_unavailable`, then `assert not egress.accepted_since(seen), 'The egress proxy saw a connection'` (682–685). | #55's red run: with the filter removed, the egress proxy saw a connection. | | 20 | A refusal by the proxy reported as `proxy_denied` | Test; Live run | `fails_through_egress(failing['refused'], 'proxy_denied')` asserts `headers.get('countersign-error') == error` (656, 760). In Compose: `TCP_DENIED/403` → `proxy_denied`. | | | 21 | An unreachable or silent proxy reported as `proxy_unavailable` | Test (#61) | Unreachable: unusable pass. Closed, not HTTP, kept open: `closed`, `garbled`, `banner`, `stub`. Silent: `runtime.py --silent-egress-proxy`, `fails_through_egress(failing['silent'], 'proxy_unavailable', timeout=130)` (675–680). It runs in `e2e.yml`'s `gateway-arm64` step "Fail a CONNECT through a silent egress proxy at the Gateway's deadline", under both worker sandboxes. | Takes the 120-second deadline. #61's red run: with the deadline mapped to `upstream_failure`, the case fails. | | 22 | The proxy's "cannot reach the site" (5xx) reported as `upstream_failure` | Test; Live run | `fails_through_egress(failing['unreachable'], 'upstream_failure')` (773). In Compose, Squid's `TCP_TUNNEL/503` with the site stopped → `upstream_failure`. | | | 23 | Each failure carries `Countersign-Request-ID` | Test | `fails_through_egress`: `assert request_id, (to, answer)`, then `wait_for_log(rf'Gateway CONNECT {request_id} {error}')` (657–661). The Compose run matches each ID to the Gateway's log line. | | | 24 | The operator guide says how to set the egress proxy | Static | `docs/operate.md`, "Reach sites through an egress proxy": the example configuration and its fields. | | | 25 | The guide says where resolution and address policy happen on each route | Static | The same section's table, with rows "Who resolves the site's name" and "Who checks the site's addresses". | | | 26 | Example Squid ACLs, blocking metadata, link-local and loopback | Static | The same section's `squid` block: `to_metadata`, `to_link_local`, `to_loopback`, each denied before any allow. | `squid -k parse` on these rules was a one-off run in #55's review, recorded in its body. The demo's `squid.conf` has the same rules, so the Compose run exercises them. | | 27 | The guide shows how to pin a private site to its prefixes | Static | The same block: `billing_prefixes` and `billing_outside`, with `http_access deny billing billing_outside`, and the paragraph on how `dst` matches. | The test with mixed answers was a one-off run in #55's review on Squid 6.14. | | 28 | The configuration reference describes `egress_proxy` and `egress` | Static | `docs/reference/config.md`: the `egress_proxy` row (Gateway fields) and the `egress` row (destination fields). | | | 29 | The troubleshooting table covers the two new error values | Static | `docs/operate.md`, troubleshooting row "CONNECT returns 502": `proxy_denied`, `proxy_unavailable`, and `upstream_failure` on a proxied route. | | | 30 | The egress proxy works in shared mode as in a sidecar | Test | `for shared in (False,True)` runs the proxied and unusable passes in both modes (922–931). CI prints `shared Gateway mTLS through the egress proxy passed`. | | | 31 | Workload client configuration unchanged on both routes | Test | One `request()` (same `--proxy`, `--proxy-cacert`, `--cacert`) reads `site.test` (proxied) and `direct.test` (direct) in one pass (623–628, 725–738). | | | 32 | A proxied failure ends with a status and an error value, never a hang, once the proxy has answered | Test | `banner`, `stub` and `lf` answer and keep the connection open. Each must give its 502 inside `connect`'s 8-second socket timeout (768–771). | #55's red run: against the old read loop, each one timed out. | | 33 | The proxy's own error page kept from the job | Test | `assert body == b'' and b'egress proxy' not in answer` (660), on every negative case. The test proxy sends `ERROR_PAGE` with each 403 and 503 (250–251, 289, 303). | | | 34 | Prompt, grant and cutoff work the same on a proxied route | Test; Live run | Grant: the site returns the approved certificate's fingerprint (727–730). Cutoff: the lease cutoff runs in the proxied pass (805–827). Prompt: in the Compose run, the Companion approval reaches the site through Squid. | The runtime test's grant authority stands in for the prompt, so only the Compose run covers the prompt itself. | | 35 | Revoking a grant cuts a proxied connection as a direct one | Test | Shared proxied pass: `broker.retired['bob'].set()`, then `assert site.cutoff.wait(1)` (831–840), before the proxied pass returns (841–843). | | | 36 | Never a fallback from the egress proxy to a direct connection | Test | `assert not site.accepted_since(seen), (to, 'The site saw a connection', answer)` in every `fails_through_egress` case (651). The unusable pass gives the Gateway a working direct route and checks that it went unused (549–550, 573). | #55's red run: a direct fallback added on purpose was caught. A silent proxy is story 21's case, which #61 added. | | 37 | Site certificate checked against the hostname and the rule's roots before any signature | Test (#61) | `for name in ('wrong', 'untrusted')`: the request fails, `egress.take()` records the allowed tunnel, and `assert failing[name] not in broker.signatures` (778–782). `untrusted`'s `roots` is another CA. | #61's red run: with trust loaded from another rule's roots, the request succeeded. | | 38 | A site still needs its destination rule at the Gateway and the Broker | Test (#61) | `refused_before_egress(unlisted)` (a grant, no rule) and `refused_before_egress(ungranted)` (a rule, no grant). Each asserts `HTTP/1.1 403`, then `'The egress proxy saw a connection'` and `'The site saw a connection'` are both false (667–673, 745–747). | #61's red runs: the rule check bypassed gives 200; a tunnel opened on a refused admission is seen by the egress proxy. | | 39 | The egress proxy carries only encrypted bytes | Test; Live run | The test proxy pumps raw bytes to a TLS site that requires a client certificate (`site_tls.verify_mode=ssl.CERT_REQUIRED`), and the grant authority asserts `body['tls'] == 'tls13'` on each signature (218). A clear-text byte after the CONNECT head would break that handshake. In Compose: Squid has no `ssl-bump`, logs `TCP_TUNNEL/200`, and the site saw the approved fingerprint. | | | 40 | Grant worker and worker sandbox unchanged | Static; Test | #55's diff touches no file under `runtime/worker.rs` or `worker_sandbox.rs`. The proxied leg is in the supervisor (`egress::tunnel` from `connect_request`). The proxied passes run under both sandboxes in CI (`gateway-filter-sandbox`). | #63 later changed `worker_sandbox.rs` for a glibc malloc read (#62), which the egress proxy did not cause: the same kill could come on a direct route. | | 41 | ADR 0003 says which checks move to the proxy and which stay | Static | `docs/adr/0003-…md`, `status: accepted`. Decisions 3 (move), 4 (stay) and 6 (the proxy's own address). | | | 42 | The Gateway ignores proxy environment variables on this leg | Test (#61) | `ignored` pass, as before. In the proxied passes, the six variables name a dead address beside `egress_proxy` (563–569), and every proxied request still succeeds. | #61's red run: `egress::tunnel` preferring `HTTPS_PROXY` fails the first proxied request with 502. | | 43 | The design record's resolution paragraph names both routes | Static | `docs/specs/2026-11-17-countersign-design.md`: "A destination takes one of two routes. On a direct route … On a route through the operator's egress proxy (ADR 0003) …". | | | 44 | The runtime test sends a request through a test-only CONNECT proxy on every pull request | Static | `.github/workflows/e2e.yml` (`on: [push, pull_request]`), step `timeout 120 python crates/countersign-gateway/tests/runtime.py …` and `scripts/filter-sandbox-container.sh`. The proxied passes always run (`main`, 922–931). | | | 45 | That test proves the site saw nothing when the proxy refused or was unreachable | Test | As story 36: line 651 for `refused`, `closed`, `garbled`, `banner`, `stub`, `lf` and `unreachable`, and both unusable passes. | | | 46 | That test proves the proxy got the site's name, not an address | Test | As stories 5 and 6 (575, 734). | | | 47 | That test runs one Gateway with a proxied and a direct destination | Test | As story 3 (735–738). | | | 48 | That test rejects a wrong-hostname certificate through an allowed tunnel | Test | `wrong` (778–782). `assert egress.take() == [f'CONNECT {failing["wrong"]} HTTP/1.1'], 'The egress proxy refused the tunnel'` proves that the tunnel was allowed. | #55's red run: with the site certified for `wrong.test`, a signature was made. | | 49 | A Compose variant with a real Squid to run before a release | Live run | `compose_demo.py --squid --verify`, the run posted on #52 (5d76a8b, Squid 6.14, exit 0). `docs/develop.md`, "Qualify the Gateway against a real Squid". | | | 50 | That variant correlates Squid's log, the site's certificate and the Workload's read from one run | Live run | #52 run: `Squid tunneled the Workload's CONNECT: … TCP_TUNNEL/200 … CONNECT site.test:9444 … HIER_DIRECT/172.31.0.2`, `Compose mTLS accepted selected SHA-256 5d01b2…` and `Job page matched the fingerprint the site received with the approval`. The checks are `Squid.logged` and `verify` in `compose_demo.py`. | The posted run is on 5d76a8b. Between it and d84d66d, `compose_demo.py` did not change on the default path. | | 51 | The glossary defines egress proxy | Static | `GLOSSARY.md`: **Egress proxy**, _Avoid_: upstream proxy, outbound proxy, Squid. | Landed with #53. | | 52 | #46's reporter has a documented, passing Compose configuration | Live run | The #52 run, plus `docs/develop.md` and `examples/demo-integrator/{compose.squid.yaml,squid.conf}`. | Repeating it on Fargate is out of scope: "Repeating the run on Fargate 1.4.0 with the filter sandbox. The reporter does that from the documented Compose configuration; Countersign's part ends at Compose for now." #52's live step (a comment on #46) is a separate matter. | | 53 | The demo walkthrough is unchanged unless the Squid variant is asked for | Static; Live run | `examples/demo-integrator/compose.yaml` is unchanged by #55, and `--squid` is an opt-in `store_true` flag. #55's body: the default `--verify` passed on 17525c6, and the default `docker compose config` was identical before and after. | After 17525c6, `compose_demo.py` changed only inside `Squid.configure`. | **Summary:** 53 stories, each proved: by test, statically, by the live run, or by a mix of these. No story is excluded whole. Only story 52's Fargate step is out of scope. Stories 8, 11, 17, 21, 37, 38 and 42 were Partial or Gaps on d5b15ba, the squash of #55; #61 added their cases, each red once against a Gateway broken on purpose. </details> ## Merge Danger **Door:** two-way. A revert removes the file, and #49 is reopened by hand. **Blast Radius:** none. The merge ships no image, release or infrastructure, and no flag. The handbook excludes `docs/specs/` (`mkdocs.yml`, `exclude_docs`). ## Reviews <details> <summary>No review ran: the file is the issue's text, checked byte for byte</summary> </details> ## Tracking Epic: E2 Reach protected sites through an operator's egress proxy Spec: #49 Reach protected sites through an operator's egress proxy Ticket: none Flag: none 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #60
Summary
Nothing changes for anyone using the product. The Gateway's runtime test now proves seven of #49's user stories that it left unproved, so every story of the egress proxy spec has a test or a check before the spec closes.
A check of #49's 53 user stories against
mainfound seven where breaking the Gateway on purpose left the runtime test green. Each now has a case at the real Gateway binary (#49's seam 1,crates/countersign-gateway/tests/runtime.py):*.wild.test:<port>reachesa.wild.test, and the proxy records that nameenvandserve, naming that ruleproxy.testmoves to a second egress proxy on 127.0.0.2 and back; each CONNECT lands where the name pointsproxy_unavailableat the Gateway's 120-second deadline, and the site sees nothingrootsis another CA: the request fails through an allowed tunnel, with no signature asked foregress_proxyThe silent case waits out the fixed deadline, so it runs behind
--silent-egress-proxy, in a step of its own in thegateway-arm64job:- name: Exercise shared and sidecar workers and lease cutoff run: timeout 120 python crates/countersign-gateway/tests/runtime.py target/debug/countersign-gateway + - name: Fail a CONNECT through a silent egress proxy at the Gateway's deadline + run: | # under both worker sandboxes at once: about two minutesThe Gateway does not change. The table of all 53 stories, with each one's verdict, goes into the Evidence of the pull request that closes #49.
Extras for the owner
alive(), onmainsince f13433d. The push-eventcurljob on f1c80b1 failed after the filter-killed grant worker was fenced as it should be:/proc/<pid>/statwas opened while a worker existed and read after it was collected, which raisesProcessLookupError(ESRCH), not theFileNotFoundErrorthe helper caught. The pull-request run of the same commit passed. The helper now reads both as ended.Evidence
private_networksreaches a host under it through the egress proxy, and the proxy records that host's name (story 8)egress_proxyset, a private rule with no route after a proxied rule stops startup, and the error names that rule (story 11)CONNECTgoes to the new address, and moved back, the one after succeeds (story 17)CONNECTand never answers gives 502proxy_unavailableand the request ID, and the site sees no connection (story 21)gateway-arm64's step "Fail a CONNECT through a silent egress proxy at the Gateway's deadline" passed in 121 s, under both worker sandboxesroots, the request fails and no signature is asked for (story 37)CONNECTto a name with no Gateway rule, and to one with no grant, are each refused with 403, and neither the egress proxy nor the site sees a connection (story 38)egress_proxyset and the proxy variables naming another address, every proxied request still goes throughegress_proxy(story 42)egress_proxycurl(x86-64),gateway-arm64andgateway-filter-sandboxon both architecturesEach break alone, the Gateway rebuilt from it, against the test at 39c0d0b (and 17 and 11 again at b995bc4):
AssertionError: ('alice', b'curl: (22) The requested URL returned error: 403\n'); refused at load:RuntimeError: Gateway exited 1.iter().take(1)):subprocess.TimeoutExpired: Command '[… 'serve', '…/egress.json']' timed out after 10 seconds, at the new caseAssertionError: The Gateway did not follow the egress proxyupstream_failure:AssertionError: ('silent.test:33833', b'HTTP/1.1 502 Bad Gateway\r\ncountersign-error: upstream_failure\r\n…')AssertionError: ('untrusted', 0, b'cfafcd6910720f1b…'), a successful readAssertionError: ('unlisted.test:41337', b'HTTP/1.1 200 OK\r\n…')AssertionError: ('ungranted.test:41185', 'The egress proxy saw a connection', b'HTTP/1.1 403 Forbidden\r\ncountersign-error: denied\r\n…')egress_proxyegress::tunnelprefersHTTPS_PROXY:AssertionError: ('alice', b'curl: (22) The requested URL returned error: 502\n')--landlockreaches the silent case (review)--landlock unavailable --silent-egress-proxyon this host, which has Landlock, fails its startup check in 5 s, as it shouldRuns on b995bc4 (
origin/mainc612768 and this branch), Linux arm64:python3 crates/countersign-gateway/tests/runtime.py target/debug/countersign-gateway: exit 0 in 27 s, printing sidecar and sharedGateway mTLS passed,Gateway mTLS through the egress proxy passed,Gateway without a usable egress proxy failed closed, andfilter-killed grant worker fenced.e2e.ymland run underbash -eas Actions runs it: both runs printedsidecar Gateway with a silent egress proxy failed closed, one under each worker sandbox, and the step exited 0 in 121 s. It exits 1 when either run fails.scripts/filter-sandbox-container.sh: exit 0 in 131 s, every step: the containment test (24 passed, 0 failed), the runtime test under the filter sandbox, both named startup failures, the filter sandbox without Landlock, and theclose_rangeunit (1 passed).Rebased onto #63 (e17331f), whose fix the x86-64
curljob on b995bc4 was waiting for. CI on f1c80b1: all 26 pull-request checks passed, among themcurlon x86-64 and the silent step ingateway-arm64. On dbdb8c9, the race fix:runtime.pyexit 0 on Linux arm64, printingfilter-killed grant worker fenced. CI on dbdb8c9: all 26 pull-request checks passed, and the push-event runs,curlamong them, passed too.Not run:
cargo testand the Compose demo, since no Rust or demo file changed.Merge Danger
Door: two-way. A revert removes the new cases and the CI step; nothing ships.
Blast Radius: CI only.
The merge ships no crate, image or deploy. The
gateway-arm64job of the end-to-end workflow takes about two minutes longer.Reviews
Correctness, Standards, Spec and Security, two rounds: 15 findings in round 1, each with its outcome, and none in round 2
Correctness, round 1 (at
medium, on 39c0d0b againstorigin/mainc612768)proxy_unavailable, the request ID and no connection at the site, not when; a Gateway that answered sooner would meet the story.--silent-egress-proxydrops--landlock. Fixed: the silent pass takeslandlockas the other passes do.untrustedcase cannot tell a roots mismatch from another failure. Pushed back: the case asserts that the egress proxy recorded the tunnel, and the rule's trust loads before the route is chosen (connect_request), so the request reached the site's certificate; with another rule's roots it succeeded (the red row).nothingthe same way, and a false pass would need another process on that port acting as a working CONNECT proxy to the site.proxy_unavailable. Fixed: the name moves to a second, working egress proxy, which must record the CONNECT while the first records none.\bsecond\balso matches the rule's patternsecond.site.test. Fixed: the pattern isextra.site.test:<port>, so only the rule's id matches.reads_siteserves the direct and wildcard routes.timeout 200leaves little room around the 120-second wait. Pushed back: the run takes 121 s, of which setup is about 1 s, and the 130-second socket timeout is per read, not added to the deadline.Standards, round 1
silentselects a whole scenario insidedo_test. Pushed back: the file selects each scenario by an argument ofdo_test(filter_kill,startup_fails,unusable), and a function of its own would repeat its setup.write_hosts' parameterproxyshadows the Gateway URLproxy. Fixed: renamedproxy_address.refused_before_egressandfails_through_egress. Pushed back: they assert different answers, a 403 against a 502 with an error value and a log line, and only the first checks the egress proxy.Spec, round 1
Security, round 1 (the path list could not be read, so every changed path was judged as a control): no findings.
Round 2 (fix round on b995bc4 against 39c0d0b; Correctness at
low): Correctness, Standards, Spec and Security found nothing.Tracking
Epic: E2 Reach protected sites through an operator's egress proxy
Spec: #49 Reach protected sites through an operator's egress proxy
Ticket: #60 Every user story of the egress proxy spec has a test that proves it
Flag: none
🤖 Generated with Claude Code