You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The HTTPS proxy could be refactored and renamed to be a generic SSL proxy #826
With the coming of Http2 and TCP over TLS, we may want to reuse and convert the HTTPS proxy as a generic SSL endpoint that redirects to Http2, Http1.1, or TCP clusters via ALPN.
For the moment I am mainly concerned with the TCP TLS implementation. The alternatives are:
add a completely new and independent proxy (similar to how HTTP and HTTPS are separated)
add TLS capabilities to the already existing TCP proxy (solution explored here TCP over TLS #823)
add TCP protocol to the already existing HTTPS proxy
The first solution requires a lot of code, mainly copy-pasted from the openssl and rustls implementation of the HTTPS proxy. Following the design of HTTPS, it would require the workers to have a TCPSProvider struct which hold either a tcps_openssl or tcps_rustls proxy. It also shares a common limitation/problem with solution 2: multiple proxies now are responsible for managing certificates. Which means more code duplication, it becomes hard to know if a certificate was added on unknown listeners, it makes it impossible to support both HTTPS and TCPS on the same listeners.
Solution 3 would be best implemented by refactoring the HTTPS proxy in a generic TLS proxy, as proposed at the beginning of this issue.
Equivalent solutions to 1 and 3 could be proposed to finish the HTTP2 implementation:
add a completely new and independent HTTP2 proxy
no equivalent
add HTTP2 to the already existing HTTPS proxy
The current implementation of HTTP2 (in 0.14) seems to stir in the proposed direction (solution 3) as it shares the HTTPS proxy with HTTP. To finish the implementation the HTTPS proxy has to become less "HTTP centric". For example, HTTP2 is already able to ask for backend connection, but connect_to_backend only works if it is in the Http state.
implement tls:Proxy as a generic TLS endpoint that redirects to other, independently implemented, protocols (in our case: HTTP, HTTP2 and TCP). Which, sadly, means an enormous State machine:
pubenumState{// do we need TCP's SendProxyProtocol and RelayProxyProtocol?ExpectOpenssl(protocol::proxy_protocol::expect::ExpectProxyProtocol<TcpStream>, ..),ExpectRustls(protocol::proxy_protocol::expect::ExpectProxyProtocol<TcpStream>, ..),HandshakeOpenssl(protocol::openssl::TlsHandshake),HandshakeRustls(protocol::rustls::TlsHandshake),HttpOpenssl(protocol::http::Http<SslStream<TcpStream>,Listener>),HttpRustls(protocol::http::Http<FrontRustls,Listener>),PipeOpenssl(protocol::pipe::Pipe<SslStream<TcpStream>,Listener>),PipeRustls(protocol::pipe::Pipe<FrontRustls,Listener>),Http2Openssl(protocol::h2::Http2<SslStream<TcpStream>>),Http2Rustls(protocol::h2::Http2<FrontRustls>),}
rewrite connect_to_backend to handle TCPS and H2
update every frontend lookup to use SNI switching
make sure the state machine is always coherent. With my current understanding it should look something like that:
one PR to remove HttpsProvider and merge https_openssl::Proxy and https_rustls::configuration::Proxy in a single tls::Proxy. This doesn't add any functionality to the HTTPS proxy
one PR to add TCPS in the tls::Proxy
one PR to finish the HTTP2 implementation in tls::Proxy
A caveat to this design: we need to have a single TLS Listener that accommodates all "TLS supported" protocols (TCP, HTTP, and HTTP2 for now). We also need to have a two-part scheme to filter frontends and find, for a given connection, which frontend to redirect to. Currently, demultiplexing is implemented in two phases:
L4 indicates a Listener, Listeners are linked to exactly one Proxy (TCP, HTTP, HTTPS)
the proxy finds the appropriate Frontend with:
nothing (TCP Listeners are linked to exactly one Frontend) for TCP proxy
L7 (hostname/path/method) for the HTTP proxy
L7 (hostname/path/method) for the HTTPS proxy
In the new architecture, I think we will have to rely on the SNI and ALPN protocol in the TLS proxy. So this should look like:
L4 indicates a Listener, Listeners are linked to exactly one Proxy (TCP, HTTP, TLS)
the proxy finds the appropriate Frontend with:
nothing for the TCP proxy
L7 (hostname/path/method) for the HTTP proxy
the TLS proxy first determines the Frontend Protocol using L6 (SNI/ALPN), then:
To me, the state machine for the TLS should not treat OpenSSL or Rustls differently. It should to me, be like:
SslStream::new(tls_provider);// we gave the tls provider to use at the creation, the provider could be hide behind a trait or a generic with a trait conditionpubenumState{// do we need TCP's SendProxyProtocol and RelayProxyProtocol?Expect(protocol::proxy_protocol::expect::ExpectProxyProtocol<TcpStream>, ..),Handshake(protocol::tls::TlsHandshake),Http(protocol::http::Http<SslStream<TcpStream>,Listener>),Pipe(protocol::pipe::Pipe<SslStream<TcpStream>,Listener>),H2(protocol::h2::H2<SslStream<TcpStream>>),}
taking a step back here, let's think about usage: while this would make more sense from an architecture point of view, I would not overestimate the need for TCP over TLS. Has this been asked a lot? If not I would put this off until other changes.
First, I'd recommend removing support for OpenSSL. It was kept mainly for TLS 1.0 and 1.1, that were not implemented in rustls. Now that everybody is moving off those protocols, keeping OpenSSL does not make sense. That should greatly simplify the code and configuration, and reduce the number of dependencies and build issues.
Something that could be done to make the architecture nicer, would be to reverse the hierarchy. Instead of having one global TCP proxy, one HTTP proxy and one HTTPS proxy, it would start at the listener. A listener then has some protocol (TCP or TLS) and routing (HTTP 1 & 2, passthrough).
From there you don't need to make one TLS proxy that handles everything, but stack them in a more natural way, with the outer protocol negotiating a stream (just returning a TCP stream or negotiating a TLS connection) then from there see to which rotocol it upgrades, depending on what's configured, and what's asked by the client (ALPN, websocket upgrade, etc).
But really, start by removing OpenSSL, because any change you can envision will be way easier with one less implementation 😄
Quick recap, since this issue has been quiet since November 2022 and several
pieces of the original proposal have either landed or been intentionally
reshaped on main.
Original 2022 plan (for reference)
Replace the HttpsProvider enum with a single tls::Proxy, merging https_openssl::Proxy and https_rustls::configuration::Proxy.
Add TCP-over-TLS (TCPS) inside that tls::Proxy.
Finish the HTTP/2 implementation inside the same proxy, ALPN-driven.
@Geal also recommended dropping OpenSSL entirely as a simplifying first step
before any of the above; @FlorentinDUBOIS proposed a single,
provider-agnostic state machine instead of parallel *Openssl / *Rustls
arms.
What landed on main
HttpsProvider enum is gone.https_openssl.rs and the https_rustls/ subtree have been merged into a single lib/src/https.rs. Server now holds one https::HttpsProxy instead of an enum dispatch
(lib/src/server.rs:485-486).
OpenSSL is no longer a separate TLS proxy implementation. It survives
only as a crypto provider for rustls via the rustls-openssl adapter,
selectable through the crypto-openssl cargo feature alongside crypto-ring (default), crypto-aws-lc-rs, and fips. Provider
precedence (fips > ring > aws-lc-rs > openssl) is resolved at runtime in lib/src/crypto.rs::default_provider(). This matches @Geal's "remove
OpenSSL first" recommendation in spirit: the TLS implementation is
single-stack rustls; OpenSSL is reduced to optional FFI for libcrypto.
HTTP/2 is finished, via the unified Mux session layer landed in PR feat(h2): HTTP/2 support via unified Mux session layer #1209 (merged 2026-04-27). The Mux layer replaces the old Http<Front>
protocol module: a single Mux<Front, L> session owns frontend and
backend Connection enums (Connection::H1(ConnectionH1) / Connection::H2(ConnectionH2)) and a shared Vec<Stream>, so all four
H1↔H2 frontend/backend combinations are covered. The lineage of this
work goes back to @Wonshtrum's mux_v1 design, with contributions from @hcaumeil on the H2↔H2 SETTINGS handshake and the H1→H2 upgrade path;
the feat/h2-mux branch extracted, hardened, and shipped that design for
production.
Provider-agnostic state machine. Per @FlorentinDUBOIS's earlier
proposal, the inner state machine is no longer parallelised by TLS
provider. There is one TLS handshake module
(lib/src/protocol/rustls.rs) and one HTTPS proxy.
ALPN-driven post-handshake dispatch is in place.lib/src/https.rs
branches on the negotiated ALPN protocol: h2 → mux::Connection::new_h2_server, http/1.1 → mux::Connection::new_h1_server. Listener-level disable_http11 and strict_sni_binding knobs were added; rejected ALPN values bump https.alpn.rejected.{unsupported,http11_disabled}.
What did not land (and why it matters)
TCP over TLS (TCPS). This was @Wonshtrum's primary motivator in the
original thread, and was already explored in the closed TCP over TLS #823. Drafts on
the tcp-tls and devel/edemolis/test/read_tls branches still exist,
but TCPS is not in main. The Mux layer does not include a Pipe-style passthrough as a fourth dispatch arm, and there is no
SNI-only frontend lookup for non-HTTP TLS clients. The L6/L7 demux flow
chart from the November 2022 thread (TLS proxy → SNI → {TCPS, HTTPS,
H2}) is still applicable as a design starting point for any TCPS
follow-up.
HttpsProxy → tls::Proxy rename. The proxy is still named https::HttpsProxy in Server. Server still owns three proxies
(http::HttpProxy, https::HttpsProxy, tcp::TcpProxy). Renaming
today, without a second protocol behind ALPN, would just be churn; it
should be bundled with TCPS when that work resumes.
Where the relevant code lives now
lib/src/https.rs — single HTTPS proxy (rustls-only).
lib/src/protocol/mux/ — unified H1/H2 session
(mod.rs, connection.rs, h1.rs, h2.rs, stream.rs, parser.rs, pkawa.rs, router.rs, converter.rs, serializer.rs, answers.rs, auth.rs, shared.rs). LIFECYCLE.md next to the module is the
canonical on-branch lifecycle reference.
lib/src/server.rs — still three proxies, no tls::Proxy yet.
The HTTPS-side scope of #826 is effectively done: openssl proxy retired,
H2 finished, ALPN dispatch in place, single provider-agnostic state
machine. The only remaining open item from this thread is TCPS, which #823 also targeted.
Activity
Wonshtrum commentedon Nov 9, 2022
For the moment I am mainly concerned with the TCP TLS implementation. The alternatives are:
The first solution requires a lot of code, mainly copy-pasted from the openssl and rustls implementation of the HTTPS proxy. Following the design of HTTPS, it would require the workers to have a TCPSProvider struct which hold either a tcps_openssl or tcps_rustls proxy. It also shares a common limitation/problem with solution 2: multiple proxies now are responsible for managing certificates. Which means more code duplication, it becomes hard to know if a certificate was added on unknown listeners, it makes it impossible to support both HTTPS and TCPS on the same listeners.
Solution 3 would be best implemented by refactoring the HTTPS proxy in a generic TLS proxy, as proposed at the beginning of this issue.
Equivalent solutions to 1 and 3 could be proposed to finish the HTTP2 implementation:
The current implementation of HTTP2 (in 0.14) seems to stir in the proposed direction (solution 3) as it shares the HTTPS proxy with HTTP. To finish the implementation the HTTPS proxy has to become less "HTTP centric". For example, HTTP2 is already able to ask for backend connection, but
connect_to_backendonly works if it is in theHttpstate.Wonshtrum commentedon Nov 9, 2022
What I propose:
HttpsProviderenum and replace it with atls::Proxysozu/lib/src/server.rs
Line 258 in ddec637
pub struct Server { pub poll: Poll, shutting_down: Option<MessageId>, accept_ready: HashSet<ListenToken>, channel: ProxyChannel, http: Rc<RefCell<http::Proxy>>, - https: HttpsProvider, + tls: Rc<RefCell<tls::Proxy>>, tcp: Rc<RefCell<tcp::Proxy>>, config_state: ConfigState, scm: ScmSocket, sessions: Rc<RefCell<SessionManager>>, pool: Rc<RefCell<Pool>>, backends: Rc<RefCell<BackendMap>>, scm_listeners: Option<Listeners>, zombie_check_interval: Duration, accept_queue: VecDeque<(TcpStream, ListenToken, Protocol, Instant)>, accept_queue_timeout: Duration, base_sessions_count: usize, }https_openssl::Proxyandhttps_rustls::configuration::Proxycommon parts (likeconnect_to_backend) to avoid unnecessary code duplicationsozu/lib/src/https_openssl.rs
Line 1146 in ddec637
sozu/lib/src/https_rustls/session.rs
Line 1110 in ddec637
tls:Proxyas a generic TLS endpoint that redirects to other, independently implemented, protocols (in our case: HTTP, HTTP2 and TCP). Which, sadly, means an enormous State machine:connect_to_backendto handle TCPS and H2flowchart LR start --> Swicth{expect? provider?} Swicth -->|true, openssl| ExpectOpenssl Swicth -->|true, rustls| ExpectRustls Swicth -->|false, openssl| HandshakeOpenssl Swicth -->|false, rustls| HandshakeRustls ExpectOpenssl --> HandshakeOpenssl ExpectRustls --> HandshakeRustls HandshakeOpenssl --> SwicthOpenssl{FindFrontendProto} HandshakeRustls --> SwicthRustls{FindFrontendProto} SwicthOpenssl -->|http2| Http2Openssl SwicthOpenssl -->|http| HttpOpenssl SwicthOpenssl -->|tcp| PipeOpenssl SwicthRustls -->|tcp| PipeRustls SwicthRustls -->|http| HttpRustls SwicthRustls -->|http2| Http2Rustls HttpOpenssl -->|websocket| PipeOpenssl HttpRustls -->|websocket| PipeRustlsWonshtrum commentedon Nov 9, 2022
This would enable a 3 phases plan:
HttpsProviderand mergehttps_openssl::Proxyandhttps_rustls::configuration::Proxyin a singletls::Proxy. This doesn't add any functionality to the HTTPS proxytls::Proxytls::ProxyKeksoj commentedon Nov 9, 2022
I'm all in.
Wonshtrum commentedon Nov 9, 2022
A caveat to this design: we need to have a single TLS Listener that accommodates all "TLS supported" protocols (TCP, HTTP, and HTTP2 for now). We also need to have a two-part scheme to filter frontends and find, for a given connection, which frontend to redirect to. Currently, demultiplexing is implemented in two phases:
In the new architecture, I think we will have to rely on the SNI and ALPN protocol in the TLS proxy. So this should look like:
flowchart LR L4{L4} -->|port| Listeners{Listeners} Listeners --> TCP Listeners --> HTTP Listeners --> TLS Protocol --> TCP Protocol --> HTTP Protocol --> HTTP2 L7 -->|path| Frontends L7 -->|method| Frontends L7 -->|hostname| Frontends L6 -->|sni, alpn| Protocol HTTP2 --> L7 HTTP --> L7{L7} TCP --> Frontends TLS --> L6{L6} Frontends -->|lb| ClusterFlorentinDUBOIS commentedon Nov 9, 2022
To me, the state machine for the TLS should not treat OpenSSL or Rustls differently. It should to me, be like:
Geal commentedon Nov 10, 2022
taking a step back here, let's think about usage: while this would make more sense from an architecture point of view, I would not overestimate the need for TCP over TLS. Has this been asked a lot? If not I would put this off until other changes.
First, I'd recommend removing support for OpenSSL. It was kept mainly for TLS 1.0 and 1.1, that were not implemented in rustls. Now that everybody is moving off those protocols, keeping OpenSSL does not make sense. That should greatly simplify the code and configuration, and reduce the number of dependencies and build issues.
Something that could be done to make the architecture nicer, would be to reverse the hierarchy. Instead of having one global TCP proxy, one HTTP proxy and one HTTPS proxy, it would start at the listener. A listener then has some protocol (TCP or TLS) and routing (HTTP 1 & 2, passthrough).
From there you don't need to make one TLS proxy that handles everything, but stack them in a more natural way, with the outer protocol negotiating a stream (just returning a TCP stream or negotiating a TLS connection) then from there see to which rotocol it upgrades, depending on what's configured, and what's asked by the client (ALPN, websocket upgrade, etc).
But really, start by removing OpenSSL, because any change you can envision will be way easier with one less implementation 😄
FlorentinDUBOIS commentedon May 2, 2026
State of #826 — May 2026
Quick recap, since this issue has been quiet since November 2022 and several
pieces of the original proposal have either landed or been intentionally
reshaped on
main.Original 2022 plan (for reference)
HttpsProviderenum with a singletls::Proxy, merginghttps_openssl::Proxyandhttps_rustls::configuration::Proxy.tls::Proxy.@Geal also recommended dropping OpenSSL entirely as a simplifying first step
before any of the above; @FlorentinDUBOIS proposed a single,
provider-agnostic state machine instead of parallel
*Openssl/*Rustlsarms.
What landed on
mainHttpsProviderenum is gone.https_openssl.rsand thehttps_rustls/subtree have been merged into a singlelib/src/https.rs.Servernow holds onehttps::HttpsProxyinstead of an enum dispatch(
lib/src/server.rs:485-486).only as a crypto provider for rustls via the
rustls-openssladapter,selectable through the
crypto-opensslcargo feature alongsidecrypto-ring(default),crypto-aws-lc-rs, andfips. Providerprecedence (
fips > ring > aws-lc-rs > openssl) is resolved at runtime inlib/src/crypto.rs::default_provider(). This matches @Geal's "removeOpenSSL first" recommendation in spirit: the TLS implementation is
single-stack rustls; OpenSSL is reduced to optional FFI for libcrypto.
feat(h2): HTTP/2 support via unified Mux session layer #1209 (merged 2026-04-27). The Mux layer replaces the old
Http<Front>protocol module: a single
Mux<Front, L>session owns frontend andbackend
Connectionenums (Connection::H1(ConnectionH1)/Connection::H2(ConnectionH2)) and a sharedVec<Stream>, so all fourH1↔H2 frontend/backend combinations are covered. The lineage of this
work goes back to @Wonshtrum's
mux_v1design, with contributions from@hcaumeil on the H2↔H2 SETTINGS handshake and the H1→H2 upgrade path;
the feat/h2-mux branch extracted, hardened, and shipped that design for
production.
proposal, the inner state machine is no longer parallelised by TLS
provider. There is one TLS handshake module
(
lib/src/protocol/rustls.rs) and one HTTPS proxy.lib/src/https.rsbranches on the negotiated ALPN protocol:
h2→mux::Connection::new_h2_server,http/1.1→mux::Connection::new_h1_server. Listener-leveldisable_http11andstrict_sni_bindingknobs were added; rejected ALPN values bumphttps.alpn.rejected.{unsupported,http11_disabled}.What did not land (and why it matters)
original thread, and was already explored in the closed TCP over TLS #823. Drafts on
the
tcp-tlsanddevel/edemolis/test/read_tlsbranches still exist,but TCPS is not in
main. The Mux layer does not include aPipe-style passthrough as a fourth dispatch arm, and there is noSNI-only frontend lookup for non-HTTP TLS clients. The L6/L7 demux flow
chart from the November 2022 thread (TLS proxy → SNI → {TCPS, HTTPS,
H2}) is still applicable as a design starting point for any TCPS
follow-up.
HttpsProxy→tls::Proxyrename. The proxy is still namedhttps::HttpsProxyinServer.Serverstill owns three proxies(
http::HttpProxy,https::HttpsProxy,tcp::TcpProxy). Renamingtoday, without a second protocol behind ALPN, would just be churn; it
should be bundled with TCPS when that work resumes.
Where the relevant code lives now
lib/src/https.rs— single HTTPS proxy (rustls-only).lib/src/tls.rs— certificate resolver, fingerprint cache, SNI policy.lib/src/protocol/rustls.rs— TLS handshake protocol module.lib/src/protocol/mux/— unified H1/H2 session(
mod.rs,connection.rs,h1.rs,h2.rs,stream.rs,parser.rs,pkawa.rs,router.rs,converter.rs,serializer.rs,answers.rs,auth.rs,shared.rs).LIFECYCLE.mdnext to the module is thecanonical on-branch lifecycle reference.
lib/src/server.rs— still three proxies, notls::Proxyyet.lib/src/crypto.rs— runtime crypto-provider selection.Where this leaves the issue
The HTTPS-side scope of #826 is effectively done: openssl proxy retired,
H2 finished, ALPN dispatch in place, single provider-agnostic state
machine. The only remaining open item from this thread is TCPS, which
#823 also targeted.