-
Notifications
You must be signed in to change notification settings - Fork 743
Add support for the PROXY protocol #581
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
base: master
Are you sure you want to change the base?
Conversation
When there is a proxy in front of tinyproxy, the latter does not see the actual IP address of the client. This is a problem when using tools like fail2ban that parse the tinyproxy log to find and ban clients that try to break the authentication using brute force. Some proxies like stunnel or HAProxy support the PROXY protocol to overcome that issue, so that the next proxy in the chain can tell what the IP address of the original client is. See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt This commit adds support for clients that use the PROXY protocol to extract the real client IP address and report it in the logs. This is only implemented when the new ClientUsesProxyProtocol parameter is set to Yes. It should only be enabled when the client is trusted and known to be a proxy that support that protocol.
|
reading the document, it appears the protocol is widely enough supported so it may make sense to support it too. however, some questions arise:
as for the implementation presented:
also it needs to be documented that only v1 of the protocol is supported. |
|
My main goal was the authentication failure log message, so I didn't think about the other things like ACL. What do you think of applying these changes:
I'm not sure it is useful to update the client port too. Is it ever used anywhere in the code? I agree with the remarks about the implementation and will change it accordingly. |
Reading the PROXY line is the first thing done in handle_connection() so that the client IP address is updated before it is needed by the rest of the code (ACL, logging, etc.). The parsing implementation is now less generic and updates the sockaddr_union structure directly.
|
All of the review comments have been addressed in the latest commits. |
|
@rofl0r Let me know if you need anything else from me to accept this PR. |
|
looks mostly good now, but i still have no setup to test it. can you confirm whether the current impl here works in your setup ? |
|
OK, take your time. It works well on my 2 tinyproxy servers. With fail2ban, I do see brute force bots getting banned from time to time, using the following configuration (based on that message): /etc/fail2ban/filter.d/tinyproxy.conf[Definition]
failregex = .* Failed auth attempt .*, ip <HOST>/etc/fail2ban/jail.d/tinyproxy.conf[tinyproxy]
enabled = true
#port = 8888
# stunnel+tinyproxy
port = 3128
filter = tinyproxy
logpath = /var/log/tinyproxy/tinyproxy.log
maxretry = 10
findtime = 60
bantime = 300
backend = auto |
When there is a proxy in front of tinyproxy, the latter does not see the actual IP address of the client. This is a problem when using tools like fail2ban that parse the tinyproxy log to find and ban clients that try to break the authentication using brute force. Some proxies like stunnel or HAProxy support the PROXY protocol to overcome that issue, so that the next proxy in the chain can tell what the IP address of the original client is.
See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
This commit adds support for clients that use the PROXY protocol to extract the real client IP address and report it in the logs. This is only implemented when the new ClientUsesProxyProtocol parameter is set to Yes. It should only be enabled when the client is trusted and known to be a proxy that support that protocol.