Skip to content

Add mutual TLS client certificate authentication on HTTPS listeners - #1300

Merged
FlorentinDUBOIS merged 19 commits into
sozu-proxy:mainfrom
Shine-neko:feat/mtls-client-auth
Oct 9, 2026
Merged

FlorentinDUBOIS merged 19 commits into
sozu-proxy:mainfrom
Shine-neko:feat/mtls-client-auth

Conversation

@Shine-neko

@Shine-neko Shine-neko commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1299.

What

Adds mutual TLS (client certificate authentication) to HTTPS listeners. Until now lib/src/https.rs hardcoded .with_no_client_auth(), so verifying a client certificate was impossible.

Configuration

A per-listener client_auth mode drives the rustls WebPkiClientVerifier:

[[listeners]]
protocol = "https"
address = "0.0.0.0:443"
client_auth = "required"                     # none (default) | optional | required
client_ca_certificates = ["/etc/sozu/ca.pem"]
client_ca_crls = ["/etc/sozu/crl.pem"]       # optional
  • none: current behavior, no CertificateRequest is sent
  • optional: requests a certificate, admits clients presenting none; a presented certificate must still validate
  • required: aborts the handshake unless the client presents a certificate chaining to a trusted CA

CA and CRL files are read at config-load. sozu reload refreshes them on a running listener in place: when the policy it reads differs from the running one, it sends an UpdateHttpsListenerConfig whose client_auth_policy replaces mode, CAs and CRLs together, and the workers rebuild the verifier for new handshakes.

Wire compatibility

  • HttpsListenerConfig fields 51-53, UpdateHttpsListenerConfig field 45 (ClientAuthPolicy), new ClientAuthMode enum whose zero value is CLIENT_AUTH_NONE. Absent fields decode to today's behavior; the repeated fields carry #[serde(default)], so older state files load.
  • A listener with client auth goes to workers as AddHttpsListenerWithClientAuth (Request 63) and a policy patch as UpdateHttpsListenerWithClientAuth (Request 64). A worker that predates this change cannot decode them, so it fails the request instead of building the listener without client auth or keeping its old CRLs. The main process rewrites every fan-out to these verbs (RequestType::into_canonical).

Fail-closed behavior

Rejected rather than silently degraded, by the main process before commit (and again by each worker when it builds the listener):

  • an unknown client_auth value, or a non-none mode with no trusted CA
  • an unreadable CA or CRL file, or an entry that parses to no certificate / CRL
  • CA or CRL files with no client_auth key (an explicit none is allowed, with a warning)
  • an mTLS field on a non-HTTPS listener
  • a CRL already past its nextUpdate
  • two CRLs of one CA covering the same certificates (rustls only reads the first); partitions with distinct IssuingDistributionPoints are accepted

Revocation is checked over the whole chain, unknown status is denied, and CRL expiry is enforced at handshake (enforce_revocation_expiration).

Limitations (documented in doc/configure.md)

  • The client identity is not forwarded to backends, so optional provides no access control by itself and required admits any trusted certificate to every frontend of the listener.
  • Rolling back to a version that predates this change stops reading a saved state at the first AddHttpsListenerWithClientAuth record; the doc gives the procedure.

Tests

  • lib/src/https.rs: verifier construction, revocation verdicts against real CRL fixtures (lib/assets/mtls/, regenerated by generate.sh) asserting the exact rustls error, CRL set checks, in-place policy patch.
  • command/src/: config-load inlining and rejections, verb selection, old-worker decoding of both new verbs, state patch and reload refresh.
  • bin/src/command/: fan-out verb, reload refresh through load_static_config, load_state with a record larger than 200 kB.
  • e2e/src/tests/tls_tests.rs: test_mtls_* handshakes for each mode, each CRL case, and a policy patch sequence on a running listener.

cargo clippy --all-targets --locked -- -D warnings, cargo +nightly fmt --all -- --check and the doc citation check pass.

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-review (5 lenses + Codex cross-check)

Reviewed 1518d93e across /review, /review-code, /security-review, /guidelines, /simplify, plus an independent OpenAI Codex pass. 9 raw findings → 4 after dedupe → 4/4 survived adversarial refutation, 0 dropped.

What checked out clean

The security core of this feature is correct and fails closed — verified against the vendored rustls 0.23.42 source, not from memory:

  • client_cert_verifier rejects unknown/garbage client_auth enum values via ClientAuthMode::try_from rather than silently degrading to NONE.
  • A non-NONE mode with an empty CA bundle is rejected; a CA/CRL PEM entry parsing to zero objects is rejected rather than silently dropped (the before/after .len() check is sound — RootCertStore::add does not dedupe).
  • CRL expiration is unconditionally enforced (enforce_revocation_expiration()), and WebPkiClientVerifier's default UnknownStatusPolicy::Deny is left intact.
  • allow_unauthenticated() (OPTIONAL) matches its rustls contract: a presented certificate is still fully chain-validated — no silent bypass.
  • try_new/create_rustls_context return Result, so a listener that fails to build its verifier is never activated — no fallback to an unauthenticated listener.
  • UpdateHttpsListenerConfig carries no mTLS fields, so a running listener's policy cannot be downgraded by a runtime patch; the ALPN-change rebuild path reuses the existing config.
  • Protobuf/serde back-compat is sound: field numbers 48–50 don't collide, Option<i32> defaults to None without #[serde(default)], and the repeated fields correctly do carry it.

Codex additionally scripted a live TLS handshake exercising OPTIONAL/REQUIRED with and without a client certificate and confirmed correct accept/reject behavior; its verdict was "no actionable defect attributable to this commit". cargo check --workspace --all-features, cargo clippy -p sozu-lib -p sozu-command-lib -- -D warnings, and the 12 new unit tests all pass. No correctness or security defect was found.

What's left (4 inline comments)

Severity Finding
🟡 medium doc/configure.md not updated for the three new TOML keys (CONTRIBUTING.md "docs are code")
🔵 low HttpsListenerConfig's hand-written Debug impl omits the new mTLS fields
🔵 low New helper orphans to_http's doc comment
🔵 low No end-to-end handshake test, despite the existing tcp_sni_tests.rs mTLS pattern

Nothing here is a defect in the shipped logic — the blocking item is the documentation rule. Details inline.

Grounded at head 1518d93eba16072d6da2e53b3f6decc198abde97.

Comment thread command/src/config.rs Resolved
Comment thread command/build.rs Resolved
Comment thread command/src/config.rs Resolved
Comment thread lib/src/https.rs Resolved
@FlorentinDUBOIS FlorentinDUBOIS self-assigned this Jul 27, 2026
@Shine-neko
Shine-neko force-pushed the feat/mtls-client-auth branch from 1518d93 to 2c3c092 Compare July 28, 2026 15:26
@Shine-neko

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough pass, especially for grounding the rustls behaviour against the vendored source rather than from memory. All four findings are addressed.

Heads-up on history: the branch was force-pushed, so 1518d93e is now 2c3c092f and your four inline comments are likely marked outdated. The delta against your reviewed commit is exactly the five files below, nothing else.

🟡 medium — undocumented TOML keys

Added a #### mTLS — client certificate authentication section to doc/configure.md, under Options specific to HTTPS listeners and mirroring the HSTS treatment: a commented TOML block, a mode table (CertificateRequest sent / behaviour with and without a client certificate), a validation matrix covering every fail-closed path, and notes on scope.

The matrix distinguishes the two rejection stages, which the description in this PR conflated: reading the CA/CRL files and rejecting mTLS keys on a non-HTTPS listener happen at config-load in the master, while PEM parsing and verifier construction happen worker-side.

Also updated, as you flagged: doc/upgrade/1.x-to-2.0.md:400 now reads shipped via #1300 instead of follow-up release. I deliberately left the version out rather than guessing a tag.

One thing I did not carry over from your comment: the UnknownStatusPolicy::Deny row. You verified it against the vendored rustls sources; I did not, and https.rs has no explicit mention of it, so I left the claim out of the docs rather than restate something I hadn't checked. Happy to add it if you confirm.

🔵 low — Debug impl

command/src/proto/mod.rs now emits client_auth, client_ca_certificates_count/_len and client_ca_crls_count/_len, following the cipher_list / groups_list treatment in the same impl.

🔵 low — orphaned doc comment

/// build an HTTP listener with config timeouts... moved back directly above pub fn to_http; reject_client_auth_fields keeps only its own block.

🔵 low — no end-to-end handshake test

Added three tests in e2e/src/tests/tls_tests.rs, driving real rustls::ClientConnection handshakes against a live HTTPS listener:

Test Asserts
test_mtls_required_rejects_client_without_cert no response and requests_received == 0
test_mtls_required_accepts_trusted_client_cert HTTP/1.1 200 + backend reached
test_mtls_optional_accepts_client_without_cert HTTP/1.1 200 + backend reached

The reject test asserts an untouched backend, not just an absent response: absence alone would also pass if Sōzu admitted the session and answered a 4xx, which is not what required means.

They reuse the e2e/assets/tcp_sni/ CA and client identity (mtls-client-cert.pem chains to ca-cert.pem and carries the TLS Web Client Authentication EKU). Since HttpsListenerConfig carries inlined PEM rather than paths, the tests mutate the generated config in place, same approach as the existing disable_http11 test.

Mutation-checked against exactly the bypass you described: flipping allow_unauthenticated() from the OPTIONAL arm to the REQUIRED one makes required_rejects and optional_accepts both fail, while every unit test in lib/src/https.rs still passes. That pair is what pins the mode boundary.

Verification

cargo clippy --all-targets -- -D warnings and cargo +nightly fmt --check clean; tls_tests 12/12; the 8 verifier unit tests and the sozu-command-lib suite green. CI is green on 2c3c092f except Docker build and push to Docker Hub, which fails identically on 1518d93e (fork credentials, unrelated to this change).

The master-side validation limitation from the PR description is unchanged and still looks like a separate issue to me.

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Thx, I will take another look tomorrow

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated cross-review (review / review-code / Rust guidelines / security-review + Codex, adversarially verified). Three findings are inline and were submitted as one batched review.

Comment thread command/src/command.proto Resolved
Comment thread doc/configure.md Resolved
Comment thread command/src/command.proto Resolved
@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Hi @Shine-neko — this branch is now 60 commits behind main and its last CI run is from 2026-08-27. Could you rebase it on current main? A fresh run would help move the review along.

Two jobs are red on that August run, and they have different causes — only one of them is yours to fix:

cargo audit — a rebase clears this. It is failing on dependencies, not on your changes:

Crate:    h2          Version: 0.4.15
Title:    h2 unbounded empty DATA frames
ID:       RUSTSEC-2026-0258      Solution: Upgrade to >=0.4.16

Crate:    chacha20    Version: 0.10.1      Warning: yanked

main already carries h2 0.4.19 and chacha20 0.10.2, so both findings disappear on rebase with no action needed from you.

Docker build and push to Docker Hub — please ignore this one. It fails with Secret source: None and ##[error]Username and password required at the docker/login-action step: the registry secrets are not exposed to pull requests from forks. Nothing in this PR causes it and nothing you can do will make it green. It is not a signal about your work.

One other reason a rerun is worth it: lib/src/https.rs is one of the files you touch and it has moved in three commits since your branch point. GitHub currently reports no merge conflicts, so the rebase should be uneventful — CHANGELOG.md is the likely friction point, as it has been touched by 35 commits in the meantime.

Thanks for the contribution, and sorry it has been sitting.

@Shine-neko

Copy link
Copy Markdown
Contributor Author

Rebased on main, the three comments are addressed in 51584c83, 9bd2465e and 49b7306f.

@Shine-neko
Shine-neko force-pushed the feat/mtls-client-auth branch from 51584c8 to 6947899 Compare October 2, 2026 19:14
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
Fixes #1800

## Summary

A backend that accepts no connection (blackholed: SYN dropped, accept queue full) hit `connect_timeout` and the request was answered `504`. The timeout path marked the connection `Disconnecting`, so the dead-backend branch of `Mux::ready_inner`, the only place a connect failure is counted, never saw it. The backend's retry policy was never armed and the load balancer kept picking it.

- **Connect timeout counts as a connect failure.** `Mux::timeout_inner` now flags a still-`Connecting` connection's readiness `ERROR`, the way the kernel flags a refused dial. `Server::timeout` then runs the `ready` pass that only it can trigger (new `ProxySession::needs_ready_pass`, default `false`). That pass reuses the existing dead-backend branch: it counts the failure (`failures`, `retry_policy`, `backend.connections.error`, `backend.down`), closes the connection, and re-links the request through `EndStreamAction::Reconnect`. The request sent no byte, so it is safe to resend. A response timeout on an established connection still answers `504`.
- **A WRITABLE event no longer marks a connecting socket connected.** `SO_ERROR` (`take_error`) is read first, then `getpeername(2)`. An error is a connect failure. `ENOTCONN` means the WRITABLE was raised by Sōzu itself, not by the kernel, so the connection waits for the kernel's completion edge. This fixes a separate defect you can observe on its own: on `main`, a dial from an `http2 = true` cluster to a blackholed backend was marked connected and then hung until `back_timeout`.
- **A synchronous `connect(2)` failure is retried** instead of being answered `503` at once.
- **Each retry skips the backends that already failed for this request** (`Stream::tried_backends`), for every load-balancing policy. The exclusion narrows the candidate set (`BackendList::select_with_key_excluding`). If every selectable backend was already tried, selection falls back to the plain behaviour, fail-open included, so the request retries one of them instead of being refused. A sticky cookie that names a tried backend is not followed.
- **The retry budget is configurable.** `max_connection_attempts` counts every attempt, the first included. It replaces the hard-coded `CONN_RETRIES = 3`, and **the default is now 5**. It can be set:
  - globally: TOML and `ServerConfig` field 29;
  - per cluster: `Cluster` field 23, TOML, `sozu cluster add --max-connection-attempts`, and `sozu cluster connection-attempts set|unset` (query, then re-send with the field changed, like `cluster h2`). A cluster table column shows the value;
  - at runtime on every worker: `sozu connection-attempts set` (`Request.set_max_connection_attempts`, field 62). Like `connection-limit set`, this is not saved.

  Allowed range is `1..=255`. It is validated at config load, on `AddCluster` (main and worker), and on the runtime set. A cluster value wins over the global one, for both HTTP and TCP clusters.

- **Failover is bounded by `front_timeout`.** The frontend's nominal timeout is set only on a request's first link, not on every re-link. The deadline armed then therefore bounds the whole failover, so a request can no longer run for `max_connection_attempts × connect_timeout`. When the deadline expires during failover, the request gets the frontend timeout's existing answer: `504`, with access-log message `client_timeout_during_response`. `doc/configure.md` recommends keeping `connect_timeout` well below `front_timeout / max_connection_attempts`, and explains how back-off grows.
- **Socket error logged.** The socket error read by `take_error()` is logged at `debug!`, the same level as the synchronous-refusal path.

**Status change for alerting:** when every attempted backend is unreachable (connect timeout or refused), the answer is now `503`. A connect timeout used to answer `504`. Requests that arrive during a back-off window can also fail fast with `503`. Operators alerting on `504` rates should watch `503`, `backend.connections.error` and `backend.connect.retries_exhausted` instead. With the default budget at 5, an idempotent request on a stale keep-alive connection can be replayed to up to 4 backends (`n - 1`), against 2 before.

**Coordination:** `Request` field 62 is also used by the open PR #1300. That PR already needs renumbering, so this one keeps 62.

**Library API break:** `sozu_lib::server::CONN_RETRIES` is removed, and new fields are added to `Cluster`, `ServerConfig`, `RequestType`, `FileConfig`, `FileClusterConfig`, `HttpClusterConfig`, `TcpClusterConfig`, `Stream` and `SessionManager`. Upgrade the main process, the workers and the CLI together before setting a per-cluster budget: an older CLI that patches clusters by read-modify-write drops the field.

Docs: `doc/configure.md` (new "Backend connection failover" section, global key, metrics, shard and replay budget text), `doc/configure_cli.md`, `doc/health_checks.md`, `doc/lifetime_of_a_session.md`, `doc/rate-limit-design.md`, `lib/src/protocol/mux/LIFECYCLE.md` §7.3, `bin/config.toml`, and `CHANGELOG.md`.

## Existing tests touched

Two existing tests now call `mark_connected(h1)` in their fixtures: `a_backend_timeout_leaves_no_linked_stream_behind_on_the_close_path` and `a_completed_backend_response_timeout_unlinks_through_end_stream_alone`. Both describe a backend that has already sent response bytes, but their fixture left it `Connecting`. With this change, a `Connecting` connection is treated as a connect timeout. No assertion changed, and neither test encodes the old `504`; they cover the response-timeout arms. An alternative would be to narrow the timeout branch to `Connecting && no linked stream has back.consumed`. I kept the fixture fix instead, because that extra condition cannot be reached in production.

## Tests

New: `e2e/src/tests/backend_failover_tests.rs`, plus `connect_outcome_tests`, `exclusion_tests`, `a_connect_timeout_flags_the_dial_dead_instead_of_answering_504`, the `max_connection_attempts` config tests, and the state validation test.

What each test proves:
- The connect-timeout e2e tests use 3 healthy and 3 blackholed backends with `connect_timeout = 1`. The blackhole is a backlog-0 listener with a full accept queue; `test_blackholed_listener_times_out` checks that it really times out. Every request must answer 200, and the cluster-level `backend.connections.error` must be greater than 0. That counter shows the timeouts are now counted against the backend, which arms its retry policy. It does not measure a drop in how often dead backends are picked.
- The refused-backend e2e tests use a refused/healthy alternation that drives the first request onto three refused backends in a row. The budget raise is what fixes them. The tried set itself is covered by `exclusion_tests`.

## CI fix: leaked mock backend threads

CI on `9bd8bfa6` and `379b4a4e` failed `tests::h2_tests::test_h2_rapid_reset_triggers_goaway` in every cell ("received 0 frames"). The cause was in this PR's test module, not in production code.

**Cause:** `Backends` in `e2e/src/tests/backend_failover_tests.rs` dropped its `AsyncBackend` handles without stopping them. That backend's thread (`e2e/src/mock/async_backend.rs`, the spawn loop) only exits on a stop message, so every dropped handle left a thread spinning for the rest of the test process. That was about two dozen threads, all started before `h2_tests` in name order. On a small CI runner they starved the rapid-reset worker: CI logged its 999 resets over 12 s, in batches of about 17 every 110 ms. Main's CI run took 0.16 s for the same resets, with identical per-stream timings.

**Fix:** `impl Drop for Backends` now stops those backends. The rapid-reset test is unchanged.

**Evidence:** I ran `taskset -c 0 cargo test -p sozu-e2e --locked -- backend_failover tests::h2_tests::test_h2_rapid_reset_triggers_goaway --test-threads=4 --nocapture` before and after the fix.
- Before: about 24 threads were busy during the rapid-reset test (`ps -L`), and the 999 resets took 1.57 s instead of 0.1 s.
- After: no busy leftover threads, and the 999 resets took 0.32 s.
- The full e2e suite dropped from 3098 s to 1963 s.

## CI fix: worker events read as answers

At `dff0285e`, `test_connect_timeout_fails_over_h2` failed in the crypto-openssl cell even though every request got its 200. The test's metrics query read a worker event (`content_type: Some("event")`) in place of its answer. The failover tests make backends fail on purpose, and a backend whose retry policy gives up on it is reported `BACKEND_DOWN` on the same command channel. Reads in these tests now skip events (`read_answer`).

That event's arrival depends on randomized back-off, so I did not reproduce the race locally. After the fix, both connect-timeout tests passed 20 runs out of 20 under `taskset -c 0`, and 20 out of 20 on 2 CPUs loaded with 6 busy processes.

Validation at head `6c7dd668`, after merging origin/main `320e86d6` (#1805; conflicts in `command/src/config.rs` and `doc/health_checks.md` resolved keeping both features):

Verified: `cargo +nightly fmt --all -- --check` -> exit 0
Verified: `cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings` -> exit 0
Verified: `cargo test -p sozu-lib --lib --all-features` -> `test result: ok. 1586 passed; 0 failed`
Verified: `cargo test -p sozu-command-lib -p sozu --all-features --locked` -> exit 0, all `test result: ok` (227 command-lib unit tests)
Verified: `cargo test -p sozu-e2e --features opentelemetry,splice,simd -- --test-threads=4` -> `test result: ok. 621 passed; 0 failed`
Verified: `RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -p sozu-command-lib -p sozu` -> exit 0
(An earlier run at `f8d4c18e` had one timing failure under load: `test_h1_chunked_encoding_edge_cases`. That test passed 3 times out of 3 in isolation, and the full `h1_security_tests` module passed with `--test-threads=4`.)
Verified: `python3 .github/scripts/check_doc_citations.py --root . --base origin/main` -> exit 0

Red without the fix:
- New e2e tests on `main` (`dc25d2ff`):
  - `test_connect_timeout_fails_over_h1`/`_h2`: `[200, 504, 200, 504, …]` (12×200, 12×504) and `backend.connections.error: 0`.
  - `test_refused_backends_never_exhaust_attempts_h1`/`_h2`: first request `503`.
  - `test_h2_backend_connect_failure_fails_over_h1`/`_h2`: `[200, 0, 200, 200, 0, …]`, where `0` is no answer within 10 s.
- `test_failover_is_bounded_by_front_timeout_h1`/`_h2` (6 blackholed backends, budget 20, `connect_timeout` 1 s, `front_timeout` 3 s):
  - in a scratch copy of this branch with the per-attempt re-arm restored: no answer within 10 s on both frontends;
  - with the fix: `[504]` after about 3.09 s on both.
- `try_connect_timeout_fails_over` now asserts `backend.connections.error >= 3`, one failure per blackholed backend. Round robin hits each of the six backends in the first six requests, so this is deterministic.
- Budget and unit tests, in scratch copies of this branch with one part of the fix reverted at a time:
  - default set back to 3: `test_default_connection_attempt_budget_is_five` fails (`503`), and so does the config default test;
  - cluster override ignored: `…overrides_global` fails (`503`), and so do the runtime cluster update and the default test's per-cluster `four`;
  - runtime setter disabled: `…changes_at_runtime` fails (`200` where `503` is expected);
  - exclusion, fallback or sticky filter removed: the matching `exclusion_tests` fail;
  - `ENOTCONN` treated as connected: `a_dial_nobody_answers_is_pending` and the H2-backend e2e tests fail;
  - `Connecting` early return removed: `a_connect_timeout_flags_the_dial_dead_instead_of_answering_504` fails;
  - validation removed: the config and state range tests fail.



Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Heads-up on protobuf field numbers: Request field 62 is now taken on main by set_max_connection_attempts = 62 (#1806, merged as e959838). This PR also uses 62 for add_https_listener_with_client_auth, so it needs to move to the next free number, 63, before it can merge. The HttpsListenerConfig fields 51–53 (client_auth, client_ca_certificates, client_ca_crls) are still free on main (it stops at 50, h2_stream_refusal_percent).

@Santoshkumarpuppala

Copy link
Copy Markdown

None of the tests at 6947899 load a real CRL, so the revocation wiring at lib/src/https.rs:1849-1855 and the Revocation table in doc/configure.md:489-500 are untested. The only CRL-bearing unit test (https.rs:4771) passes "not a crl" and errors before :1849. There is no BEGIN X509 CRL anywhere in the tree, against 36 files with BEGIN CERTIFICATE. Read, not run: deleting .enforce_revocation_expiration() at :1854 would leave every test green.

The logic reads correct to me. Since ca-key.pem isn't checked in, fixtures need a throwaway CA (with cRLSign if it has a KeyUsage extension), or rcgen as a new dev-dependency. Two details matter, because the reject assertion at e2e/src/tests/tls_tests.rs:2704 can't tell rejection reasons apart:

  1. The revoked CRL needs a far-future nextUpdate. webpki checks expiry before the serial lookup (src/crl/mod.rs:155-166), so once it lapses the revoked test becomes a second expired-CRL test.
  2. The expired CRL must be signed by the client cert's issuer, or it fails as UnknownRevocationStatus and dropping :1854 still passes.

@FlorentinDUBOIS, want this in #1300 or separately? Happy to send the throwaway CA plus revoked and expired CRLs as a commit against the branch.

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

I think it will be great to have the full lifecycle with revocation, I do not really mind about having a large diff, as long as there are tests for lifecycle of each features and also we do not reduce quality of others. Also, could you update the documentation as well?

@Shine-neko
Shine-neko force-pushed the feat/mtls-client-auth branch from 6947899 to aeafd91 Compare October 4, 2026 10:16
@Shine-neko

Copy link
Copy Markdown
Contributor Author

@FlorentinDUBOIS rebased on main, the verb is now 63.

@Santoshkumarpuppala thanks for the detailed pointers, no need to send the fixtures. The branch now has a throwaway CA with current, revoking, expired and foreign-issuer CRLs (lib/assets/mtls/generate.sh), verifier tests asserting the exact rustls error, and e2e handshake tests. Writing them showed that rustls only reads the first CRL of a given issuer, so two CRLs from the same CA are now refused. Docs updated accordingly.

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

I am launching a code review :D

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update; the protobuf number collision is fixed (Request = 63).

This review combines two passes on head 58a4cfc:

  • a code review, which traced each issue in the code;
  • a guidelines check, which built and tested the PR head and its merge with current main.

The build is clean:

  • clippy -D warnings on the crypto-ring, aws-lc-rs, openssl and fips cells;
  • rustdoc, fmt and doc citations;
  • tests: lib 1650, bin 316, command 270, e2e TLS 31 (all 7 test_mtls_*);
  • the merge with main is conflict-free and builds and tests green.

Mutating enforce_revocation_expiration, reject_crls_sharing_an_issuer, allow_unauthenticated and into_canonical each turns a test red.

Inline comments, most important first:

  1. CRL/CA refresh is impossible through a reload, and CRL expiry is enforced.
  2. CA/CRL paths without client_auth are silently ignored.
  3. Partitioned CRLs are refused, and an expired CRL is accepted at load.
  4. Rollback and state-size effects of embedding PEMs.
  5. Client identity isn't forwarded to backends.
    The rest are doc and nit items.

Two items have no line in the diff:

  • Commit 3e3b8cb9f (feat(https): add mutual TLS...) has no Signed-off-by, and none of the 9 commits is GPG-signed. The repo convention is signed-off and GPG-signed commits (-s -S).
  • bin/config.toml has no example for client_auth, client_ca_certificates and client_ca_crls.

Comment thread lib/src/https.rs Resolved
Comment thread command/src/config.rs Resolved
Comment thread lib/src/https.rs Resolved
Comment thread lib/src/https.rs Resolved
Comment thread lib/src/https.rs Resolved
Comment thread doc/configure.md Resolved
Comment thread doc/configure.md Resolved
Comment thread command/src/proto/display.rs Resolved
Comment thread CHANGELOG.md Resolved
Comment thread lib/src/https.rs Resolved
@Shine-neko
Shine-neko force-pushed the feat/mtls-client-auth branch 2 times, most recently from 3eb523b to 41ce5f8 Compare October 6, 2026 07:49

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 41ce5f8. Thanks, the previous round is addressed.

  • Resolved:
    • Reload now refreshes the CA bundle and CRLs (client_auth_refresh plus the client_auth_policy patch on Request 64).
    • CA or CRL files without client_auth are rejected.
    • Partitioned CRLs are accepted and an already-expired CRL is refused.
    • The doc comment is back on client_cert_verifier.
    • The always-true debug_asserts are removed.
    • Main-process validation is documented.
    • The rollback procedure and the load_state buffer size are handled.
    • The display.rs citation path is fixed.
    • The CHANGELOG blank line and proto numbers are added.
    • bin/config.toml has the new keys.
    • The client identity limitation is documented.
  • Partly addressed: to_owned, with one production .to_string() left; the validation matrix still places one check in the worker. Both are inline.
  • Commits: all 15 now carry Signed-off-by. None is GPG-signed.

Two CI jobs are red at this head, each with a one-line cause, explained inline:

  • msrv-full: a misplaced doc block in command/src/state.rs triggers rustdoc's private intra-doc link error.
  • Doc citations: two proto field names in the CHANGELOG are read as test names.

Both fixes pass locally.

Also inline: a stale "not patchable" paragraph in the listener mutability section, a few doc nits, and a question on the CRL expiry check running on every worker-side build.

Checked locally at 41ce5f8 with --no-default-features --features crypto-ring:

  • sozu-lib (1626 tests) and sozu-command-lib (265 tests) pass.
  • The three new bin tests pass: reload CRL refresh, 200 kB state record, and fan-out verb.
  • The 7 test_mtls_* e2e tests pass.
  • The branch is 7 commits behind main, and git merge-tree against current main is clean.
  • Request 63/64, HttpsListenerConfig 51-53 and UpdateHttpsListenerConfig 45 are still free on main.

Comment thread command/src/state.rs Resolved
Comment thread CHANGELOG.md Resolved
Comment thread doc/configure.md Resolved
Comment thread doc/configure.md Resolved
Comment thread doc/configure.md Resolved
Comment thread command/src/command.proto Resolved
Comment thread lib/src/https.rs Resolved
Comment thread command/src/proto/display.rs Resolved

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at c07b797. Thanks, all 8 points from the previous round are addressed:

  • The update_https_listener doc block sits on its fn again, and msrv-full is green.
  • The CHANGELOG cites the variant names and names ConfigError::ClientAuthModeMissing. Doc citations is green.
  • In doc/configure.md, the stale "not patchable" paragraph is rewritten, the duplicate bullets are merged, and the trust-set row says main process.
  • The proto comment is fixed.
  • The CRL expiry refusal now runs only in the main process, on authored requests. Workers and state replays still build the listener, so a later reload can patch it. The new bin test and the updated e2e cover this.
  • to_owned is used in display.rs.

CI: 36/36 checks green at this head. Both new commits carry Signed-off-by, but neither is GPG-signed, like the previous 15. git merge-tree --write-tree origin/main is clean, and the branch is 8 commits behind main.

Unchanged behaviour without mTLS keys. I found no change to the TLS path or the wire for a deployment that sets no client_auth / client_ca_* key. What I checked:

  • Wire: I ran one probe binary from the same TOML at main (95094cd) and at this head. The protobuf bytes match for every config message (AddHttpsListener included), for the InitialState a new worker or upgrade receives, and for an ALPN UpdateHttpsListener patch. Optional/repeated fields left unset are not encoded, and the audit SHA hashes those same bytes. Non-mTLS requests keep their verbs, both from RequestType::add_https_listener and after into_canonical in scatter_on. So any mix of old and new main, worker or CLI decodes them as before.
  • Config: ListenerBuilder is deny_unknown_fields, so no existing file can contain the new keys. The two new errors and the warning fire only when one of those keys is present.
  • Handshake: client_cert_verifier returns None before any allocation, so the builder takes with_no_client_auth() at the same place. ALPN, tickets, resolver and session settings are untouched. The only extra cost is one Arc clone per listener build, and nothing per handshake.
  • Reload: in the head probe, client_auth_refresh returns None for the non-mTLS listener, and ConfigState::diff of the same config is empty. So load_static_config emits nothing new. validate_client_crls_current and validate_client_auth_policy return Ok early on empty input.
  • Metrics and access logs: the diff adds no metric macro and does not touch lib/src/protocol. The info! lines that print {:?} of listeners print fd lists (Listeners), not HttpsListenerConfig.
  • Tests at head (--no-default-features --features crypto-ring, -j4): sozu-lib 1626 and sozu-command-lib 265 pass, as do the sozu bin tests (166 per target). e2e: test_mtls/tls_/https gives 60 passed, 9 of them mTLS and 51 non-mTLS TLS/HTTPS. upgrade/listener_update gives 31 passed.

Three observable differences remain, all minor:

  1. sozu listener list now shows three extra rows for every HTTPS listener (inline).
  2. Boot and sozu state load allocate a larger parse buffer (inline).
  3. save_state JSON gains "client_auth":null,"client_ca_certificates":[],"client_ca_crls":[] on each HTTPS listener record ("client_auth_policy":null on a patch). Every new proto field does the same. The merge-base binary parses all 7 head-written records, so a rollback still reads the state file. No action needed.

Comment thread command/src/proto/display.rs Resolved
Comment thread bin/src/command/requests.rs Resolved
@Shine-neko
Shine-neko force-pushed the feat/mtls-client-auth branch from 92c0484 to 16a4cae Compare October 6, 2026 14:00
…h no client_auth mode

Signed-off-by: Mlanawo MBECHEZI <[email protected]>
…ion, add an mTLS config example

Signed-off-by: Mlanawo MBECHEZI <[email protected]>
…client auth key is set

Signed-off-by: Mlanawo MBECHEZI <[email protected]>

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All review threads addressed, CI green at a661a58. Without client_auth configured the listener keeps the historical with_no_client_auth path and the historical AddHttpsListener/UpdateHttpsListener verbs. Thanks!

@FlorentinDUBOIS
FlorentinDUBOIS merged commit eeffdc2 into sozu-proxy:main Oct 9, 2026
36 checks passed
@Shine-neko
Shine-neko deleted the feat/mtls-client-auth branch October 10, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mutual TLS (client certificate authentication) on HTTPS listeners

3 participants