Repository navigation
ci(test): run sozu-command-lib's tests, which no workflow named - #1540
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 25, 2026 20:13
.github/workflows/ci.yml tested exactly sozu-lib, sozu, sozu-e2e and sozu-sim, and there is no `cargo test --workspace` anywhere in the workflows, so command/'s 170 #[test] functions across 13 files never ran. sozu-command-lib appeared in no workflow except a licence line in release.yml. They pass. `cargo test -p sozu-command-lib --locked` is green on aaf2a6a: 169 unit tests, 4 integration tests, 2 doctests. The 3 "ignored" are illustrative proto doc blocks, not skipped tests. So this was never a quarantine anyone chose — the package was simply never added, and nothing reported its absence. A test that never runs is indistinguishable from a test that always passes. The same gap has been closed twice before, each time for just the crate the fix at hand was about: sozu#1301/#1313/#1314's command-server unit tests, then the #[ignore]d process-level e2e tests. ci.yml's own comments record both rounds — "were never exercised by CI", "before it existed they never ran anywhere". The command lib was in scope neither time, so it survived both. What was unguarded: the configuration parser and validator, the protobuf request/response types, Channel, the logging macros and the state model that sozu-lib and sozu are both built on, plus command/tests/state_compat_v1_1_1.rs — a forward-compat regression pinning the SaveState/LoadState JSON contract that proxy-manager and other tools pinned to sozu-command-lib = "1.1.1" still write. A regression in any of them reached CI only if some other package's test happened to exercise it sideways. Two choices, both measured rather than assumed. Gated to the single msrv-full cell instead of running per crypto provider: command/src/ contains ZERO cfg(feature). Its only features (unstable, logs-debug, logs-trace) are empty markers and it has no crypto-provider feature at all, so nothing in it varies by matrix cell and the four crypto cells would re-run one identical result four times. msrv-full already hosts the other workspace-wide steps (format check, documentation build) under the same guard. Carrying no matrix.flags: they are not merely redundant but rejected. `cargo test -p sozu-command-lib --no-default-features --features crypto-ring,opentelemetry,splice,simd` fails with "the package 'sozu-command-lib' does not contain these features". --locked and --verbose match the neighbouring test steps so a dependency drift fails here exactly as it fails there. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
ci/test-sozu-command-lib
branch
from
September 25, 2026 20:42
cc3bc9a to
d10a2c7
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 25, 2026
) ## The bypass The per-`(cluster, source-IP)` limiter has no concept of a subnet. Someone on an IPv6 `/64` — the standard residential allocation — bypasses it **entirely** by taking a fresh address for every connection: the per-address counter never reaches 2. Reported by @jpds in #1270 from reading the release notes and the limiter code. ## The shape: two independent limiters Per @FlorentinDUBOIS in the issue: > I think we need both as the current rate limit is for handling rate limit by > ip as an api gateway, and the subnet aware will be there for ddos purposes. So this adds a **second, independent counter** rather than changing the first. `cluster_ip_at_limit`, `track_cluster_ip`, `effective_max_connections_per_ip` and both per-IP maps are untouched — same fields, same semantics, same bodies. What did change around them: the two call sites now go through a combined gate, and `untrack_all_cluster_ip` also drains the subnet slots (it is the single release point all three protocols already call on close, and a second entry point would be one more thing each could forget). Both gates are consulted on every admission and **both must admit**, which is what makes "10 per IP **and** 100 per /64" expressible: ```toml max_connections_per_ip = 10 # existing, untouched max_connections_per_subnet = 100 # new subnet_ipv4_prefix = 24 subnet_ipv6_prefix = 56 ``` The conjunction lives in exactly one place, `SessionManager::cluster_connection_at_limit`, so the H1+H2 mux and raw TCP cannot drift on what "admitted" means. ## The defaults leave current behaviour intact `max_connections_per_subnet` defaults to `0` (disabled) and the prefixes default to `/32` and `/128`, which mask nothing. An upgrade is inert until an operator opts in. `/24` and `/56` are **documented recommendations**, not defaults — matching what the reporter did in the equivalent Caddy module (default left at single IPs, those prefixes highly recommended in the docs). They are written up in `doc/configure.md` and `doc/rate-limit-design.md` §7.1.1. Stronger than inert: while the cap is `0` the subnet bookkeeping is **not written at all**, so a deployment that never enables the feature allocates nothing for it. `an_unset_subnet_cap_leaves_the_admission_path_untouched` asserts both maps stay empty. This is a **deliberate divergence from the per-IP twin**, which tracks unconditionally — flagging it explicitly as the point where you may want to decide otherwise. The cost is that enabling the cap at runtime does not retroactively count sessions already in flight; the counter converges as they close. ## New configuration surface Global TOML keys (`command/src/config.rs`): | Key | Type | Default | |---|---|---| | `max_connections_per_subnet` | integer, 0 = unlimited | `0` | | `subnet_ipv4_prefix` | integer 0-32 | `32` | | `subnet_ipv6_prefix` | integer 0-128 | `128` | Plus a per-cluster `max_connections_per_subnet` override with the same `None` inherits / `Some(0)` explicit-unlimited / `Some(n)` overrides semantics as its per-IP twin. Out-of-range prefixes are **rejected** at config-load time (`ConfigError::InvalidSubnetPrefix`), never silently clamped. ### Additions to `command.proto`, named explicitly | Message / field | Tag | |---|---| | `Request.set_max_connections_per_subnet` (uint64) | 60 | | `Request.query_max_connections_per_subnet` | 61 | | `message QueryMaxConnectionsPerSubnet {}` | — | | `message MaxConnectionsPerSubnetLimit { limit, ipv4_prefix, ipv6_prefix }` | — | | `ResponseContent.max_connections_per_subnet_limit` | 18 | | `Cluster.max_connections_per_subnet` (optional uint64) | 17 | | `ServerConfig.max_connections_per_subnet` | 26 | | `ServerConfig.subnet_ipv4_prefix` | 27 | | `ServerConfig.subnet_ipv6_prefix` | 28 | `command/src/proto/command.rs` is generated and was not edited. ### CLI New `sozu subnet-connection-limit {set|remove|show}`, mirroring `sozu connection-limit`. `show` reports the two prefixes alongside the limit: they are boot-time only, so that reply is the only runtime surface that can tell an operator what the live cap is a cap *on*. Like its twin the setter is non-sticky — workers reset to the TOML value on restart. The prefixes have no runtime setter on purpose: the mask is part of the counter key, so patching it live would re-key every counter in flight. ## Masking `Ipv4Addr` / `Ipv6Addr` have no standard masking method and no dependency was added. Both shift-overflowing bounds are branched explicitly — `u128::MAX << 128` panics under `debug_assertions` and wraps silently in release, so a full-width prefix must never reach the shift; a zero prefix is branched from the other end. **IPv4-mapped IPv6 sources are canonicalised first.** A dual-stack `[::]` listener reports an IPv4 client as `::ffff:a.b.c.d`; masking that with an IPv6 prefix would collapse the entire IPv4 internet into one `::/56` bucket, so it is converted to IPv4 and charged to `subnet_ipv4_prefix`. The per-IP counter is deliberately left un-canonicalised — part of what keeps its behaviour untouched. ## To SEE THIS RED Delete the `|| self.cluster_subnet_at_limit(...)` disjunct from `SessionManager::cluster_connection_at_limit` in `lib/src/server.rs`, leaving every other piece — config keys, proto fields, masking, tracking — in place: ``` cargo test -p sozu-lib --locked --no-default-features \ --features crypto-ring,opentelemetry,splice,simd subnet ``` ``` test ...::a_subnet_cap_refuses_a_fresh_address_from_an_already_counted_subnet ... FAILED panicked at lib/src/protocol/mux/router.rs: a fresh address from an already-counted /24 must be refused — an Admitted verdict here is the #1270 bypass: a new address per connection defeats the cap ``` The test drives the real `plan_connect` → `consult_ip_gate` → `plan_connect_resume` sequence for four **distinct** addresses in one `/24`, under a per-IP cap of 10 that no single address comes near — so only the subnet counter can refuse the fourth. A fifth address in a *different* `/24` is asserted admitted, so the refusal is the subnet key and not a blanket cap on new addresses. Restoring the disjunct returns it to green; the cycle was run twice. ## Tests added - `a_subnet_cap_refuses_a_fresh_address_from_an_already_counted_subnet` — the regression above. - `an_unset_subnet_cap_leaves_the_admission_path_untouched` — the default changes nothing, and allocates nothing. - `a_cluster_override_dropping_to_zero_after_a_track_is_a_no_op` — a cluster override can drop to `Some(0)` after a session was tracked under a positive limit (`AddCluster` is an upsert and clears no counters; only the *global* `SetMaxConnectionsPerSubnet(0)` drains). An earlier revision asserted that could not happen and panicked on it. - `masking_handles_both_shift_overflowing_prefix_bounds` — prefixes 0, full width, and over-wide. - `masking_groups_addresses_at_the_recommended_prefixes` — /24 and /56, including the issue's own `/64`-holder scenario. - `an_ipv4_mapped_source_is_charged_to_the_ipv4_prefix` — including the negative case where two mapped `/24`s must not collide. - `subnet_connection_limit_keys_round_trip_from_toml` and `an_out_of_range_subnet_prefix_is_rejected_not_clamped` — the config plumbing and its validation. ## Known limitation A subnet refusal currently surfaces as `BackendConnectionError::TooManyConnectionsPerIp` and increments the shared `connections.rejected_per_cluster_ip` counter, so an operator cannot tell the two caps apart in metrics. Kept shared to hold this changeset to the feature; a distinct error variant and counter are a reasonable follow-up. ## Validation All run locally at the tip of this branch, rebased onto `main` at `42ed1111` (after #1537 and #1540 landed); CI is the verdict. The rebase over #1537 conflicted only on line citations, in `doc/testing.md` and `lib/src/protocol/mux/LIFECYCLE.md` (13 hunks). Each was resolved by locating the text the citation named at the merge base inside the merged tree, never by arithmetic; the resulting diff on those two files is citations only — every removed line has an identical added counterpart once the digits are stripped, so none of #1537's prose was altered. | Command | Result | |---|---| | `cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd` | pass | | `cargo +nightly fmt --all -- --check` | pass | | `cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings` | pass | | `cargo test -p sozu-lib …` | 1147 passed, 0 failed | | `cargo test -p sozu …` | pass | | `cargo test -p sozu-command-lib --locked --no-default-features` | 171 passed, 0 failed | | `cargo test -p sozu-e2e … -- --skip tests::fuzz_tests::` | 449 passed, 0 failed | | `RUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --locked` | pass | | `RUSTFLAGS="--cfg tokio_unstable" cargo clippy -p sozu-sim --all-targets --locked -- -D warnings` | pass | | `check_doc_citations.py --self-test / --root . / --base / --audit --root .` | all pass | | `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked` | pass | > **Note on the two config tests — resolved since this PR was opened.** > `subnet_connection_limit_keys_round_trip_from_toml` and > `an_out_of_range_subnet_prefix_is_rejected_not_clamped` live in > `command/src/config.rs`. When this PR was first pushed, CI ran `cargo test` for > `sozu-lib`, `sozu`, `sozu-e2e` and `sozu-sim` but **never** for > `sozu-command-lib`, and there was no workspace-wide `cargo test` anywhere — so > these two would have landed without ever running. That gap was reported as > [#1539](#1539), and > [#1540](#1540) landed the step that shut it; > it is now in `main`. > This branch is rebased on top of it, so CI does exercise both tests. Docs updated in the same changeset: `doc/configure.md`, `doc/rate-limit-design.md` (§3.1, §3.2, §3.3, §3.7, §3.8, §7.1.1), `bin/config.toml`, `CHANGELOG.md`. Line citations displaced by the insertions were renumbered and each renumbered bound verified against the text it named at the base. > **On the renumbering, for `check_doc_citations.py`'s own record.** The first > automated pass produced **three wrong ranges** on lines whose text is ambiguous > (a bare `}`), two of them inverted. The checker caught two. The third — > `lib/src/server.rs:1060-1068`, which should have been `1056-1064` — **passed > silently, because a citation this changeset re-anchored is exempt from the > base comparison and is never checked at all** (the run reports this honestly: > "39 re-anchored spans were exempt from the comparison"). It was only found by > auditing all 29 renumbered bounds content-against-content, resolving each one > through the text it named at the base. Another agent hit the same mechanism on > a different changeset today, so this is an independent confirmation that the > re-anchoring exemption is a real hole, not a theoretical one: the rule cannot > guard precisely the citations a changeset touches, which are the ones most > likely to be wrong. Closes #1270 Signed-off-by: Florentin Dubois <[email protected]>
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.
What was not running
.github/workflows/ci.ymltests exactly four packages —-p sozu-lib,-p sozu,-p sozu-e2e,-p sozu-sim— andsimulation-sweep.ymladds two more-p sozu-siminvocations. There is no
cargo test --workspaceanywhere in the workflows, andsozu-command-libis named in none of them except a licence line inrelease.yml.So
command/'s 170#[test]functions across 13 files have never run in CI.They pass. On
aaf2a6aa:The 3
ignoredare illustrativeprotodoc blocks, not skipped tests.This was never a quarantine anyone chose — the package was simply never added, and
nothing reported its absence. A test that never runs is indistinguishable from a test
that always passes.
It has been closed twice before, package by package
ci.yml's own comments record both rounds:Each fix added the one package it was about.
sozu-command-libwas in scope neithertime, so it survived both.
What was unguarded
command/holds the configuration parser and validator, the protobuf request/responsetypes,
Channel, the logging macros, and the state model thatsozu-libandsozuareboth built on. A regression in any of it reached CI only if some other package's test
happened to exercise it sideways.
It also holds
command/tests/state_compat_v1_1_1.rs, which is not an internal unittest at all: it pins the
SaveState/LoadStateJSON contract thatproxy-managerandother tools pinned to
sozu-command-lib = "1.1.1"still write. Its own header describesthe failure it guards — a new
repeated/mapfield without#[serde(default)]makesparse_several_requestsleave the payload unconsumed andload_statereport"Error consuming load state message". That is a cross-project compatibility guaranteethat has been unenforced.
The two decisions, measured rather than assumed
Where: one cell, not the crypto matrix
command/src/contains zerocfg(feature):Its only features are
unstable,logs-debugandlogs-trace, all declared as emptymarkers (
command/Cargo.toml), and it has no crypto-provider feature at all. Nothingin the package varies by matrix cell, so the four crypto cells would re-run one identical
result four times for a single verdict.
The step is therefore gated
if: matrix.cell == 'msrv-full'— the guardci.ymlalreadyuses for its other workspace-wide steps (
Format check,Build documentation). That cellis non-experimental and pins the 1.93.1 MSRV, so the step also confirms
command/buildsat the declared minimum. It reuses the cell's existing toolchain, cache and baked-in
protoc, so it adds no job, no runner and no new setup.Flags: none, because they are rejected
Not a judgement call — the flags do not apply:
Passing
${{ matrix.flags }}would fail the step outright on six of the nine cells. So thecommand is
cargo test -p sozu-command-lib --locked --verbose:--lockedand--verbosematch the neighbouring test steps, so a dependency drift fails here exactly as it fails
there.
Result
Green on the current tree — the step verified locally with the exact command it runs:
Had it been red, that failure would have been the point of the issue and is reported, not
skipped. It is not.
The changeset touches no Rust file, no manifest and no lockfile —
ci.ymlandCHANGELOG.mdonly — so it cannot change what the other steps compile. The fourcheck_doc_citations.pyrules (--self-test,--root .,--base,--audit --root .)all pass.
Note for review order
The
CHANGELOG.mdentry is appended at the end of the### ✨ Addedsection ratherthan the top, deliberately: #1538 adds its entry at the top of the same section, and
keeping the two hunks ~240 lines apart lets both merge without a textual conflict. No
other file overlaps between the two branches.
Closes #1539
Signed-off-by: Florentin Dubois [email protected]