Repository navigation
T34 — Refuse proxied requests exactly as direct connections, and close HTTP/2 at the proxy - #1737
Conversation
A request through the hostname proxy is now put to the same verdict a direct connection between the same two boxes meets, before the proxy dials anything: the caller's compiled egress rules first (NET-070), then the target's declared ingress ports (NET-069), on host-address and own-address targets alike (NET-071). One function, net::switch::proxied_request_verdict, decides it through the relay's own helpers - the pure egress verdict over a synthesized TCP frame, the route's port gate, the relay's drop-line vocabulary - and server::start_host_proxies hands the router that function, so the routing core stays pure over the registry's facts. The registry now carries the facts that verdict reads: a route carries the target's declared request ports (the external ports its ingress publishes, on every host form), and a lease-to-session map joins a proxied request's peer address onto the caller's recorded name and compiled egress rules. The session actor records callers at hostname registration; the attach path joins the lease when the box reports it. The proxy closes a connection that opens with the HTTP/2 prior-knowledge preface at once - it routes HTTP/1.1 requests and CONNECT tunnels only (NET-135) - and strips an Upgrade: h2c offer, its HTTP2-Settings header and their Connection tokens before the head is replayed upstream, so a request offering h2c is routed as the HTTP/1.1 request it is. Every refusal logs one warn line in the relay drop line's shape, with the caller, the target, the port and the rule.
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
Babysitter review against T34's plan block (covers NET-069, NET-070, NET-071, NET-135; five layers, exactly the five files touched). Round 1 is in flight on minimal-review's Agree with the open finding, and rate it MEDIUM, MEDIUM, LOW
NIT: Verified: preface close is a zero-byte TCP close with HTTP/1.1 unaffected; h2c stripped with websocket passthrough and mixed-offer cases proven on the wire; head bounded at 8 KiB with a 30 s timeout and no panicking slice; CONNECT applies the verdict at connect; duplicate Host takes the first and replays the head to that socket, no extra reach; refusal log line carries direction, remote, proto, port, rule, host, session, caller, status. |
`declared_request_ports` read an absent ingress declaration as `None`, the value a route carries only for a host-address box, whose direct connections no surface gates. On a native host that made the box's published-loopback route ungated, so a proxied request to any port was dialed at `127.0.0.1:<port>` while the same request to the same box on a VM host was refused — the parity NET-071 binds, broken on one host form. `sessions::validate_policy` accepts an `own_ip` record with no ingress, and the own-IP default-block posture is what the relay's gate gives it, so that is what the proxy must give it too. The set is now a plain set: an own-address box is always gated and a declaration of none is the empty one, so `register_own_ip` and `own_route` take `BTreeSet<u16>` and the compiler holds every future call site to it. The NET-071 property now generates the absent declaration too (and derives the applied map the attach path reports from the declaration, so a box with no section reports an empty one), and a regression test pins both registry paths on both host forms to the deny-all verdict.
…xied-requests-exactly-as-direct-connec
|
Round 1 of 10 on the runtime's review findings, pushed as
Verify Review threads the coder judged:
A request through the proxy to a port the target box did not declare, or from a caller whose rules deny the target, is refused with the same refusal a direct connection gets on host-address and own-address targets alike — including an own-address box that declares no ingress at all, on a native host as well as a VM host, where the proxy previously dialed the port — and an HTTP/2 preface is closed at once. Notes from the agent: Round 1: the one review finding (declared_request_ports collapsing an absent ingress declaration to None, the host-address 'ungated' value, so an OwnIp box with no ingress was forwarded on a native host while a VM host refused it) was valid and is fixed: declared_request_ports returns a plain BTreeSet that is empty for an absent declaration, register_own_ip/own_route take a plain set so the compiler holds future call sites to 'an own-address box is always gated', and the Route/own_route/upstream doc comments now tie None to host-address only. The NET-071 property now generates the absent declaration for own-address modes and derives the applied map from the declaration (the first failing case it found was the test's own model of that map, now corrected to match the attach path's ingress.map_or_else derivation). One deterministic regression test, own_ip_target_with_no_ingress_is_deny_all_on_every_host_form, pins both registry paths on both host forms. server.rs needed no change this round. proptest's failure-seed file created during iteration was removed; no proptest-regressions files are tracked in this repo, so nothing out of scope was left behind. |
|
/revise Round 1 closed the no-ingress own-address gap (verdict valid on
Resolve both threads when done. Nothing else is open; CI is green on |
`tcp_frame_summary` wrote the destination port at `ip[20..22]`, the L4 source-port slot, while `egress::summarize` reads the destination port from `ip[ihl + 2..ihl + 4]` (`ip[22..24]` for IHL 5), so every summary it built carried `dst_port == 0` and the proxy's egress verdict never saw the port the request named. Latent today — the verdict consults the port only for the UDP resolver carve-out, which a TCP frame cannot match — but a port-shaped rule or carve-out the verdict ever grows would silently ignore the connection's port, and the doc comment's claim that the port sits "at the offsets summarize extracts them from" was not true. The mirror-image helper `tcp_frame_to` in the proxy tests had the same mis-offset, so `proxy_parity_across_network_modes` compared two equally-wrong summaries and passed despite it: the NET-071 parity claim was not exercised at the port level. Both now write the port where `summarize` reads it, and a new unit assertion holds `tcp_frame_summary(dst, p).destination_port() == p` for non-zero `p` so the offset cannot drift again.
|
Round 2 of 10 on a /revise note, pushed as
Verify Review threads the coder judged:
A proxied request to a port the target did not declare, or from a caller whose egress rules deny the target, still gets exactly the refusal a direct connection gets on host-address and own-address targets alike — and this round the synthesized frame behind that verdict names the connection's destination port at the offset egress::summarize reads it from, so the NET-071 parity is now actually exercised at the port level (asserted directly, and compared against a test frame that carries the port too), with an HTTP/2 preface still closed at once. Notes from the agent: Both findings were judged against the branch head. Thread 2 (the dst_port mis-offset) held and is fixed in c46dd64: the production offset in switch.rs, the mirror-image test helper tcp_frame_to in proxy.rs, and a new unit assertion that fails on the old offset — so proxy_parity_across_network_modes now compares two frames that both name the port instead of two that both lost it. Thread 1 (no-ingress own-address) is already fixed on this branch by 4be614e, so it needed no change this round; see its verdict note for the two tests that pin it. Beyond the test: lines I ran |
…xied-requests-exactly-as-direct-connec Resolve it by keeping the shared derivation the branch introduced and the lease main's NET-084 added to it: compiled_egress takes the box's lease, the registry's caller facts hold the declaration uncompiled and build the rules at the join — with the lease that names the caller — and the synthesized frame a proxied request is put to carries the caller's own lease as its source, so the verdict's source check reads it as the box's own frame and the declared dimensions decide, on both surfaces.
The diff-scoped strict clippy gate arrived with this merge, so the branch's own lines meet it for the first time and the PR lanes would have gone red on them. - The provably-bounded slices and indexes (constant offsets into the fixed-size synthesized frame, cuts at an index or length a search already bounded) carry #[expect] with the reason the bound holds. - The parity property's match named the host-address arm it had already excluded with unreachable!; it is now the meaningful None it always was — a host-address target has no gate to compare with — so the excluded case is stated where it is decided instead of asserted away. - The recording backend's discarded answer is named as intentional.
|
Round 3 of 10 on a conflict with the base branch, pushed as Resolved conflicts in:
Verify A request through the hostname proxy to a port the target box did not declare, or from a caller whose egress rules deny the target, is refused with the same rule name, direction and reason a direct connection's drop carries — on host-address and own-address targets alike, before the proxy dials anything — and an HTTP/2 preface is closed at once, which the branch's five verify lines hold green on top of main's lease-checked egress verdict. Notes from the agent: Round 3 was a conflict round: main's NET-084 (T40, reject relay frames whose source is not the box's lease) changed EgressRules::from_policy to take the lease and made egress::verdict check the frame's source against it first. The conflict marker in SessionGate::for_session was the visible tip of that; the rest of the resolution was required to keep the branch's parity true under the new verdict. How it landed, in the five layer files: (1) compiled_egress takes the lease as a third parameter and for_session passes it, so the branch's shared derivation and main's lease dimension are one compile path; (2) the hostname registry now records a caller as its uncompiled declaration (CallerFacts holds the SessionPolicy and the SwitchSubnet, not prebuilt rules) and builds the EgressRules at the join in caller_at, with the lease that names the caller — the lease arrives from the attach path (provider.rs → report_own_address) after the session actor registers the caller at spawn, so it cannot be compiled at registration; the join is the only place both facts exist, and compiling there means the rules and the lease can never disagree; (3) direct_connection_verdict synthesizes its frame with the rules' own lease as the IPv4 source, so the verdict's new lease check reads the frame as the box's own and the declared dimensions decide — without this every proxied request from a box would have been refused as a foreign source, which is also why the deferred compile matters: session.rs records the caller before the …[truncated] |
norrietaylor
left a comment
There was a problem hiding this comment.
Gates met: T34's five test lines exit 0 on 1323644 and the agent-verify gate passed; the five files touched are the task's layers; CI green on the head; minimal-review concluded (neutral) and CodeRabbit approved on the head; the port-offset fix and its assertion (tcp_frame_summary_names_the_destination_port) are on the branch; the remaining caller-identity thread is T43's work and is resolved with that pointer; no open threads, not a draft, no needs-human.
`just fix` is the innermost loop, and the gate failed there. Three agent rounds on the NET walk then rewrote lines their task never named to clear it (#1737 round 3, #1730 round 5, #1727 round 4), two of them in conflict rounds whose only directive was the merge. A command that fails in the edit loop outranks a sentence in AGENTS.md telling you to leave the hit alone, so the sentence this branch added needs the recipe to agree with it. CLIPPY_STRICT_REPORT_ONLY=1 prints the diagnostics and exits 0. `fix` sets it; `clippy-strict` and `ci` do not, so "before opening a PR" stays the round that owns the judgement. Only hits are demoted — a build or tooling failure still exits non-zero, which is what the cargo check above the filter is for.
…l ref The base was `git merge-base main HEAD`, and a branch that merges `origin/main` leaves the local ref where it was — agent sandboxes and worktrees never check main out at all. The merge-base against a ref that stale predates the main commits the branch merged in, so every line of those commits reads as a line this branch changed, and the gate reports diagnostics on other people's code under a heading saying they are yours. Three agent rounds fixing lines their task never named is what that looks like from the outside (#1737, #1730, #1727). Measured on this branch: a local `main` ten commits behind turned a change touching no Rust at all into 14 changed Rust files across `minimald`, `sessions` and `switch`. With `origin/main` it is nought, and the gate says "no Rust changes" as it should. The remote ref is the safe one by construction: it cannot be behind anything the branch merged, because merging it required fetching it, and a fetch only moves it forward. Stale means the base is older than the newest main, never older than this branch's first commit. The local ref stays as the fallback for a clone without a remote.
…d take it out of just fix (#1749) * docs(agents): say the strict clippy gate is local and bounded by the directive Three agent rounds since #1724 landed rewrote lines beyond their task to satisfy `just clippy-strict`, two of them in conflict rounds whose only directive was the merge, and two coders wrote that the PR lanes would have gone red otherwise. They would not: the gate is local, no CI lane runs it. Say so where AGENTS.md names the gate, and say what a revise or conflict round does with its hits: report them in `notes`, not fix them. * chore(lint): report the strict gate in just fix, enforce it in just ci `just fix` is the innermost loop, and the gate failed there. Three agent rounds on the NET walk then rewrote lines their task never named to clear it (#1737 round 3, #1730 round 5, #1727 round 4), two of them in conflict rounds whose only directive was the merge. A command that fails in the edit loop outranks a sentence in AGENTS.md telling you to leave the hit alone, so the sentence this branch added needs the recipe to agree with it. CLIPPY_STRICT_REPORT_ONLY=1 prints the diagnostics and exits 0. `fix` sets it; `clippy-strict` and `ci` do not, so "before opening a PR" stays the round that owns the judgement. Only hits are demoted — a build or tooling failure still exits non-zero, which is what the cargo check above the filter is for. * fix(lint): demote only the filter's hits, and never inherit report-only Two false-success paths in the report-only mode added a commit ago, both of them the thing this gate exists to avoid: exiting 0 without having checked. The filter's exit was read as "hits" whatever it was, so no python3 on PATH or a crash inside it made `just fix` pass having reported nothing. It now exits a distinct 2 for hits and only that is demoted; 1 from an unhandled exception, 127 from a missing interpreter, and the cargo failure above the filter all still leave non-zero. CLIPPY_STRICT_REPORT_ONLY was read from the ambient environment, so one export in a shell profile would have turned the gate off in `just clippy-strict` and therefore in `just ci`, silently. The enforcing recipe clears it. * fix(lint): take the strict gate's base from origin/main, not the local ref The base was `git merge-base main HEAD`, and a branch that merges `origin/main` leaves the local ref where it was — agent sandboxes and worktrees never check main out at all. The merge-base against a ref that stale predates the main commits the branch merged in, so every line of those commits reads as a line this branch changed, and the gate reports diagnostics on other people's code under a heading saying they are yours. Three agent rounds fixing lines their task never named is what that looks like from the outside (#1737, #1730, #1727). Measured on this branch: a local `main` ten commits behind turned a change touching no Rust at all into 14 changed Rust files across `minimald`, `sessions` and `switch`. With `origin/main` it is nought, and the gate says "no Rust changes" as it should. The remote ref is the safe one by construction: it cannot be behind anything the branch merged, because merging it required fetching it, and a fetch only moves it forward. Stale means the base is older than the newest main, never older than this branch's first commit. The local ref stays as the fallback for a clone without a remote. * fix(lint): report-only never fails, whatever stopped the gate `just fix` is the autofix loop: safe to run any number of times and never stopping on the strict gate. Report-only demoted hits but still exited 101 on a build failure and 127 with no python3, so the loop failed on the gate it was told only to report. Under report-only every failure is now printed with its exit code and demoted; enforcing (`just ci`) keeps every one fatal, so a gate that did not run still cannot pass there. Driven through cargo and python3 shims: hit 2/0, cargo 101/0, no python3 127/0 (enforcing/report-only), and report-only twice gives the same output. * chore(lint): take the strict gate out of just fix `just fix` is the edit loop, and everything it prints is something to fix, so a strict hit printed beside fmt and clippy --fix reads as work whatever a doc sentence says. Report-only kept the hits in that loop and only removed the failure. Remove the gate from the recipe instead: it runs in `just clippy-strict` and `just ci`, the round that owns the judgement, and nowhere else. With no caller, the report-only mode and the recipe that cleared it go too; the script's exit codes are 0 clean, 2 hits, anything else a failure to run, none read as clean. AGENTS.md's tight-loop bullet says the loop prints only what to fix.
T34 — Refuse proxied requests exactly as direct connections, and close HTTP/2 at the proxy
slice: S8
kind: task
covers: NET-069, NET-070, NET-071, NET-135
size: L
est: 400 code, 300 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: the bundle's daemon log tail shows each proxy refusal with the same rule name a direct refusal carries
observability: one warn log line per proxy refusal with the caller, the target, the port and the rule, in the shape of the relay's drop line
layers:
- daemon:
- crates/minimald/src/net/proxy.rs: closes on the HTTP/2 preface, strips the h2c upgrade and its headers, and checks the target's declared ports and the caller's egress before connecting
- crates/minimald/src/net/dns.rs: a registration carries the target's declared ingress ports and the lease-to-session map that names the caller
- crates/minimald/src/session.rs: register_hostname passes the ports
- crates/minimald/src/server.rs: start_host_proxies hands the proxy the verdict it shares with the relay
- crates/minimald/src/net/switch.rs: exposes the declared-port logic so both surfaces reach the same verdict
test: cargo nextest run -p minimald proxy_undeclared_port_refused_like_direct
test: cargo nextest run -p minimald proxy_caller_egress_denied
test: cargo nextest run -p minimald proxy_parity_across_network_modes
test: cargo nextest run -p minimald hostname_proxy_closes_h2_preface
test: cargo nextest run -p minimald hostname_proxy_strips_h2c_upgrade
produces: none
consumes:
- crates/sessions/src/core/egress.rs
proof: A request through the proxy to a port the target box did not declare, or from a caller whose rules deny the target, is refused with the same refusal a direct connection gets on host-address and own-address targets alike, and an HTTP/2 preface is closed at once.
depends on:
- blocked by #1611
- blocked by #1629
- blocked by #1623
Proof
A request through the hostname proxy is now put, before the proxy dials anything, to the same verdict a direct connection between the same two boxes meets: a request to a port the target box did not declare, or from a caller whose egress rules deny the target, is refused with 403 Forbidden and one warn line carrying the same rule name a direct refusal logs, on host-address and own-address targets alike (property-tested across every network mode, egress rule set and requested port); and a connection that opens with the HTTP/2 prior-knowledge preface is closed at once with no response bytes, while a request offering Upgrade: h2c is routed as the HTTP/1.1 request it is, with the offer, its HTTP2-Settings header and their Connection tokens stripped before the head reaches the upstream.
Notes from the agent: One verdict function decides both surfaces: net::switch::proxied_request_verdict composes the relay's own helpers (the pure sessions egress verdict over a synthesized TCP frame for the caller's half, the route's port gate and the relay's NO_INGRESS_MAPPING_RULE for the target's half); server::start_host_proxies hands the router that function, so the routing core stays pure over the registry's facts and there is exactly one admit-or-drop derivation in the tree. Semantics worth knowing: a proxied request names the target's external port while the relay's gate admits the mapping's internal one, so the parity the tests hold is 'the proxy forwards only to a box-side port the same declaration admits (translating through the map on a VM host, the published external port on the native published-loopback model) and refuses every port the declaration does not publish' — SessionGate::admits_direct_tcp exposes the gate's half for that assertion; direct box-to-box enforcement at the target's own address is NET-073, a separate task. register_host_net kept its two-argument signature because a host-address box declares no ingress at all (Record::validate_policy reje…[truncated]
Tests
cargo nextest run -p minimald proxy_undeclared_port_refused_like_directcargo nextest run -p minimald proxy_caller_egress_deniedcargo nextest run -p minimald proxy_parity_across_network_modescargo nextest run -p minimald hostname_proxy_closes_h2_prefacecargo nextest run -p minimald hostname_proxy_strips_h2c_upgradeVerify
min task run agent-verifypassed ([tasks.verify]).Closes #1639