Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOLVED] TLS Proxy: relaying the real client ip #296

Closed
blob42 opened this issue Nov 20, 2024 · 6 comments
Closed

[SOLVED] TLS Proxy: relaying the real client ip #296

blob42 opened this issue Nov 20, 2024 · 6 comments

Comments

@blob42
Copy link

blob42 commented Nov 20, 2024

Hi,

I am running a DoH and relaying https connections to my reverse proxy. All relayed tls traffic has the remote_ip set to the DoH server so implementing any kind of rate/spam control is difficult.

Is there any way I could pass along the real remote client ip when it is proxied ?
Or maybe add an extra header field ?

SOLUTION:

I found a way to bypass specific TLS traffic from dnscrypt server which keeps the original ip packet data. My solution relies and Docker, Caddy-L4 for tls proxy.

The process is roughly the following:

  • Catch all TLS traffic (443) on a Caddy-l4 docker instance
  • Anything that matches traffic I would like to bypass is ignored and handled directly by the Caddy-l4 http part. Anything else is TLS Proxied to the dnscrypt-server.

Here is a quick overview of the Caddyfile used with the caddy-l4 docker container:

{
    layer4 {
                # bypass foo traffic based on sni matcher
                :443 {
                    @tls_nofoo not tls sni foo.website.com

                    route @tls_nofoo {
                        proxy dnscrypt-server:443
                    }
                }
    }
}

foo.website.com {
    reverse_proxy foo_server
}

This would make any tls traffic to foo.website.com avoid any extra proxy and keep initial packet data.

Note that this Caddyfile only works with Caddy compiled with caddy-l4 support.

@jedisct1
Copy link
Member

Relaying happens at layer 4. The proxy never decrypts the relayed TLS traffic and is not even able to.

But rate limiting is something that can be implemented in the proxy itself. I'm using firewall rules to limit the number of sessions per client IP, but doing it in user land could be easier to configure.

@blob42
Copy link
Author

blob42 commented Nov 20, 2024 via email

@jedisct1
Copy link
Member

That would not work without breaking the TCP stream.

@blob42
Copy link
Author

blob42 commented Nov 20, 2024

Got it thanks again for the tips.

@blob42 blob42 closed this as completed Nov 20, 2024
@blob42 blob42 changed the title TLS Proxy: relaying the real client ip [SOLVED] TLS Proxy: relaying the real client ip Nov 21, 2024
@blob42
Copy link
Author

blob42 commented Nov 21, 2024

@jedisct1 I found a solution and updated the comment for future people who encounter the same problem

@jedisct1
Copy link
Member

Wow, well done!

I didn't know that Caddy could do that!

Thanks for the update!

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

No branches or pull requests

2 participants