Skip to content

TCP over TLS - #823

Closed
Wonshtrum wants to merge 3 commits into
mainfrom
tcp-tls
Closed

Wonshtrum wants to merge 3 commits into
mainfrom
tcp-tls

Conversation

@Wonshtrum

@Wonshtrum Wonshtrum commented Nov 7, 2022 •

Copy link
Copy Markdown
Member

TODO:

  • create specific "tcptls" protocol for Frontend
  • add hostname (for SNI) and certificates for each TCP-TLS listener
  • implement a CertificateResolver on TCP-TLS Frontend
  • potentially add validation steps:
    • only 1 cluster/listener per TCP Frontend
    • N TCP-TLS clusters/listeners per TCP-TLS Frontend
    • mandatory hostname for TCP-TLS Frontends
  • support openssl

Signed-off-by: Eloi DEMOLIS [email protected]

@Wonshtrum Wonshtrum self-assigned this Nov 7, 2022

@Keksoj Keksoj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

since it works, I trust the code. I only have cosmetic comments to make

Comment thread lib/src/tcp.rs Outdated
Some(State::Pipe(ref mut pipe)) => pipe.writable(&mut self.metrics),
Some(State::PipeTls(ref mut pipe)) => pipe.writable(&mut self.metrics),
Some(State::Handshake(ref mut handshake)) => {
let (upgrade, result) = handshake.writable();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please rename result to session_result for understandability.

Comment thread lib/src/tcp.rs Outdated
gauge_add!("protocol.proxy.send", -1);
gauge_add!("protocol.tcp", 1);
UpgradeResult::Continue
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

an early return with the error case would be preferable here, for a better reading flow

Comment thread lib/src/tcp.rs Outdated
gauge_add!("protocol.proxy.relay", -1);
gauge_add!("protocol.tcp", 1);
UpgradeResult::Continue
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same thing, return early in case of error

Comment thread lib/src/tcp.rs Outdated
gauge_add!("protocol.proxy.expect", -1);
gauge_add!("protocol.tcp", 1);
UpgradeResult::ConnectBackend
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

idem

Comment thread lib/src/tcp.rs Outdated
Comment on lines 755 to 763
if let Some(State::Handshake(_)) = self.protocol {
} else {
match self.connect_to_backend(session.clone()) {
// reuse connection or error we can continue
Ok(BackendConnectAction::Reuse) | Err(_) => {}
// New or Replace: stop here, we must wait for an event
_ => return SessionResult::Continue,
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if let Some(State::Handshake(_)) = self.protocol {
} else {
match self.connect_to_backend(session.clone()) {
// reuse connection or error we can continue
Ok(BackendConnectAction::Reuse) | Err(_) => {}
// New or Replace: stop here, we must wait for an event
_ => return SessionResult::Continue,
}
}
match self.protocol {
Some(State::Handshake(_)) => {}, // do nothing
_ => {
match self.connect_to_backend(session.clone()) {
// reuse connection or error we can continue
Ok(BackendConnectAction::Reuse) | Err(_) => {}
// New or Replace: stop here, we must wait for an event
_ => return SessionResult::Continue,
}
}

Comment thread lib/src/tcp.rs Outdated
token: Token,
) -> Result<Listener, rustls::Error> {
let server_config = ServerConfig::builder();
let ssl_config = if let Some(ref tls) = config.tls {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

replace with match config.tls please

Comment thread lib/src/tcp.rs Outdated
let mut key_reader = BufReader::new(tls.key.as_ref().unwrap().as_bytes());
let mut key_res = None;
let parsed_keys = rustls_pemfile::rsa_private_keys(&mut key_reader);
if let Ok(mut keys) = parsed_keys {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

replace with match parsed_keys please

Comment thread lib/src/tcp.rs Outdated
} else {
let mut key_reader = BufReader::new(tls.key.as_ref().unwrap().as_bytes());
let parsed_keys = rustls_pemfile::pkcs8_private_keys(&mut key_reader);
if let Ok(mut keys) = parsed_keys {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same

@Wonshtrum Wonshtrum changed the title TCP over TLS (no dedicated proxy, no SNI, 1 cluster per Frontend) TCP over TLS Nov 9, 2022
@Wonshtrum

Copy link
Copy Markdown
Member Author

It still lacks OpenSSL support and SNI dispatching: ignore no cluster_id in create_session if TLS and switch on SNI in connect_to_backend.

But it becomes apparent that this may not be the cleanest implementation. Validating the config is difficult, it is not possible to have both HTTPS and TCPS listeners on the same frontend, and a lot of code duplication is needed. The TCP proxy becomes cluttered by a lot of TLS logic copy-pasted both from openssl and rustls proxies (mainly for configuration and certificate handling). TCP Listeners hold logic for a 3 branches switch (plaintext, openssl, rustls).

more thoughts here #826

@Keksoj

Keksoj commented Dec 15, 2022

Copy link
Copy Markdown

I moved this into the HTTP2 milestone, since it's part of the conversation we have over there. I suggest we close this merge request since we moved on to other plans.

@Keksoj Keksoj closed this Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants