tokio-rs / tls

A collection of Tokio based TLS libraries.
https://tokio.rs
MIT License
253 stars 86 forks source link

Proxy protocol support #121

Open thijsc opened 1 year ago

thijsc commented 1 year ago

We run some services behind Haproxy and Nginx which use proxy protocol to preserve the clients ip address. It would be really nice if we could do this using Tokio directly too. Is it possible to do this somehow? If not this is something I'd be interested in help figure out or write.

djc commented 1 year ago

It's probably possible, but it's not obvious to me that these crates are the place to add it? Why couldn't it be a wrapper around a tokio-rustls (or tokio-native-tls) stream?

thijsc commented 1 year ago

Why couldn't it be a wrapper around a tokio-rustls (or tokio-native-tls) stream?

Good question. I was assuming as much because I see a TlsAcceptor being used in the examples. For proxy protocol support it would have to read some bytes off the connection before initiating the handshake. So it seems like some option on this acceptor would make sense. Or do you think it should be in another place?

djc commented 1 year ago

Ahh, okay, that makes sense. I'm still not very familiar with the proxy protocol and unlikely to have much time to learn it. @hawkw do you have experience with it? In any case, I think it couldn't hurt to write some code for protocol support and then figure out how best to incorporate/publish it on crates.io.

thijsc commented 1 year ago

I will do some experimentation as well.