Repository navigation
feat(auth): add basic HTTP authentication - #1210
Closed
FlorentinDUBOIS wants to merge 3 commits into
Closed
FlorentinDUBOIS wants to merge 3 commits into
FlorentinDUBOIS wants to merge 3 commits into
Conversation
Add basic HTTP authentication with SHA256 password hashes: - Extract and verify Authorization header in editor.rs - SHA256 hash comparison against per-cluster authorized_hashes - WWW-Authenticate challenge response (401) with configurable realm - New proto fields: authorized_hashes, www_authenticate on Cluster - Route required_auth through Frontend -> RouteResult -> auth check - E2e test covering: no-auth 401, wrong-credentials 401, correct 200 Signed-off-by: Florentin Dubois <[email protected]>
Vec::contains uses PartialEq with early exit, which leaks timing information about the hash value. Replace with subtle::ConstantTimeEq to prevent timing side-channel attacks on basic auth credentials. Signed-off-by: Florentin Dubois <[email protected]>
The sozu-lib crate depends on subtle (workspace dependency) for constant-time credential comparison, but Cargo.lock was missing the subtle entry in sozu-lib's dependency list. This caused `cargo vendor --locked` to fail in the Docker build CI job. Signed-off-by: Florentin Dubois <[email protected]>
llenotre
approved these changes
Mar 23, 2026
5 tasks done
FlorentinDUBOIS
added a commit
that referenced
this pull request
Apr 28, 2026
…chema Lay the wire schema for the bundled feature work that brings PR #1206..#1210 onto current main. Wave 1 of a multi-wave implementation; subsequent waves land the runtime engine, mux integration, auth helper, e2e tests, and docs. Cluster gains four fields: per-cluster `answers` (status code → template body) at field 9, `https_redirect_port` at 10, `authorized_hashes` at 11, and `www_authenticate` realm at 12. RequestHttpFrontend gains eight: `redirect` policy at 8, `required_auth` at 9, `redirect_scheme` at 10, `redirect_template` at 11, `rewrite_host`/`rewrite_path`/`rewrite_port` at 12-14, and a repeated `headers` list at 15. Listener configs gain a parallel `answers` map at 31 (HttpListenerConfig) and 43 (HttpsListenerConfig); the legacy `CustomHttpAnswers http_answers` field is preserved on the wire so existing state files round-trip — the runtime will read both for one minor. New top-level enums RedirectPolicy / RedirectScheme / HeaderPosition and a Header message land alongside. An empty `Header.val` deletes the named header (HAProxy `del-header` parity). prost stops auto-deriving Hash/Eq once a message holds a map field, so the build script gains explicit `#[derive(Hash, Eq)]` for Cluster, HttpListenerConfig, HttpsListenerConfig, UpdateHttpListenerConfig, and UpdateHttpsListenerConfig. Existing initializers grow a `..Default::default()` fallthrough so this commit is a pure additive scaffolding step — no runtime behaviour changes yet. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Apr 28, 2026
Introduce the constant-time comparison primitive that Wave 3a will plug into `apply_route_decision`. The new module owns three small surfaces: - `extract_authorization_header` walks the front kawa once, case- insensitively matches `Authorization`, and returns the raw value bytes. Handles elided headers gracefully and never panics on hostile input. - `canonicalize_basic_credentials` decodes a `Basic <token>` value, base64-decodes the token, splits on the first `:`, hashes the password with SHA-256, and emits the canonical `<user>:<hex(sha256)>` form that matches every entry in `Cluster.authorized_hashes`. Caps the decoded payload at 4 KiB so a hostile peer can't force the worker to allocate unbounded transient buffers per failed attempt. - `check_authorized_hashes` compares the canonical form against every entry in the cluster's hash list using `subtle::ConstantTimeEq`, iterating the entire slice on every call (no early exit) so the time spent does not leak which entry matched or whether any did at all. Mitigates timing side-channel attacks on the credential boundary (CWE-208 family, specifically the credential-comparison flavour PR #1210's review fix `171a31ce` was hardening). `check_basic` is the convenience entry point the mux will call: header → canonicalise → constant-time compare. Empty cluster lists short-circuit to `false` so a frontend with `required_auth = true` on a cluster with no `authorized_hashes` reliably returns 401. Workspace gains `base64 = ^0.22.1` and `subtle = ^2.6.1`; only `sozu-lib` pulls them in, so the command-lib and e2e crates stay unaware. `Cargo.lock` refresh is included so `cargo vendor --locked` keeps the Docker build green. 10 unit tests cover round-trip canonicalisation, scheme case-insensitivity, non-Basic schemes, malformed base64, missing colon, oversized payload, matching at any list position, wrong-password rejection, and empty list. Signed-off-by: Florentin Dubois <[email protected]>
jrcribb
pushed a commit
to jrcribb/sozu
that referenced
this pull request
Aug 10, 2026
…chema Lay the wire schema for the bundled feature work that brings PR sozu-proxy#1206..sozu-proxy#1210 onto current main. Wave 1 of a multi-wave implementation; subsequent waves land the runtime engine, mux integration, auth helper, e2e tests, and docs. Cluster gains four fields: per-cluster `answers` (status code → template body) at field 9, `https_redirect_port` at 10, `authorized_hashes` at 11, and `www_authenticate` realm at 12. RequestHttpFrontend gains eight: `redirect` policy at 8, `required_auth` at 9, `redirect_scheme` at 10, `redirect_template` at 11, `rewrite_host`/`rewrite_path`/`rewrite_port` at 12-14, and a repeated `headers` list at 15. Listener configs gain a parallel `answers` map at 31 (HttpListenerConfig) and 43 (HttpsListenerConfig); the legacy `CustomHttpAnswers http_answers` field is preserved on the wire so existing state files round-trip — the runtime will read both for one minor. New top-level enums RedirectPolicy / RedirectScheme / HeaderPosition and a Header message land alongside. An empty `Header.val` deletes the named header (HAProxy `del-header` parity). prost stops auto-deriving Hash/Eq once a message holds a map field, so the build script gains explicit `#[derive(Hash, Eq)]` for Cluster, HttpListenerConfig, HttpsListenerConfig, UpdateHttpListenerConfig, and UpdateHttpsListenerConfig. Existing initializers grow a `..Default::default()` fallthrough so this commit is a pure additive scaffolding step — no runtime behaviour changes yet. Signed-off-by: Florentin Dubois <[email protected]>
jrcribb
pushed a commit
to jrcribb/sozu
that referenced
this pull request
Aug 10, 2026
Introduce the constant-time comparison primitive that Wave 3a will plug into `apply_route_decision`. The new module owns three small surfaces: - `extract_authorization_header` walks the front kawa once, case- insensitively matches `Authorization`, and returns the raw value bytes. Handles elided headers gracefully and never panics on hostile input. - `canonicalize_basic_credentials` decodes a `Basic <token>` value, base64-decodes the token, splits on the first `:`, hashes the password with SHA-256, and emits the canonical `<user>:<hex(sha256)>` form that matches every entry in `Cluster.authorized_hashes`. Caps the decoded payload at 4 KiB so a hostile peer can't force the worker to allocate unbounded transient buffers per failed attempt. - `check_authorized_hashes` compares the canonical form against every entry in the cluster's hash list using `subtle::ConstantTimeEq`, iterating the entire slice on every call (no early exit) so the time spent does not leak which entry matched or whether any did at all. Mitigates timing side-channel attacks on the credential boundary (CWE-208 family, specifically the credential-comparison flavour PR sozu-proxy#1210's review fix `171a31ce` was hardening). `check_basic` is the convenience entry point the mux will call: header → canonicalise → constant-time compare. Empty cluster lists short-circuit to `false` so a frontend with `required_auth = true` on a cluster with no `authorized_hashes` reliably returns 401. Workspace gains `base64 = ^0.22.1` and `subtle = ^2.6.1`; only `sozu-lib` pulls them in, so the command-lib and e2e crates stay unaware. `Cargo.lock` refresh is included so `cargo vendor --locked` keeps the Docker build green. 10 unit tests cover round-trip canonicalisation, scheme case-insensitivity, non-Basic schemes, malformed base64, missing colon, oversized payload, matching at any list position, wrong-password rejection, and empty list. 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.
Summary
authorized_hashesandwww_authenticateconfigurationrequired_authwired throughFrontend->RouteResult-> auth check flowChanges
authorized_hashes(field 10) andwww_authenticate(field 11) onClusterauthorized_hashesandwww_authenticateonFileClusterConfigandHttpClusterConfigAuthorization: Basicheader, decode base64, SHA256 hash password, store asauthorization_foundWWW_AUTHENTICATEtemplate variable for 401 responses (header-only, elide if empty)cluster_id_from_request- compare hash againstauthorized_hashesrequired_authfield onFrontendandRouteResultDepends on
Test plan
cargo build --workspace-- 0 errorscargo clippy --workspace-- no new warningscargo +nightly fmt-- clean