mholt / caddy-l4

Layer 4 (TCP/UDP) app for Caddy
Apache License 2.0
906 stars 69 forks source link

Accept connections with an without PROXY protocol on the same port #213

Open thegcat opened 2 months ago

thegcat commented 2 months ago

We are migrating away from a HAProxy-based setup and had one incoming port we used to proxy connection with the PROXY protocol to a backend service (exim in this case, but this is not important). On this port we had incoming connections directly from clients, i.e. without incoming PROXY protocol lines, and incoming connections that went through an upstream proxy and would already have PROXY protocol lines. This was not an issue.

We have been unable to replicate this setup with Caddy and the l4 plugin. Either we add the proxy_protocol handler on the incoming port used for this and only connections with the PROXY protocol lines are accepted/handled, or we do not add the handler and only connections without the PROXY protocol lines go through correctly, the others also go through but exim chokes on them (maybe they have both PROXY protocol lines? We didn’t tcpdump and check.)

Is it possible to create a port agnostic to the presence or not of the PROXY protocol line?

mholt commented 1 month ago

It sounds like you are looking for the PROXY protocol matcher? https://github.com/mholt/caddy-l4/blob/master/modules/l4proxyprotocol/matcher.go