-
Notifications
You must be signed in to change notification settings - Fork 503
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
Origin IP forwarding for security (e.g. geoblocking) #250
Comments
Personally, I have not used a firewall with geoblocking. In the case of web applications on the client side, rathole tries to avoid overhead. Not everyone needs the original IPs, and for those in need, I bet the feature is already there in the upper protocol, e.g. HTTP. |
Yes "X-Forwarded-For" is known to me but as far as I know this is not "safe" and can be manipulated. So it seems that only a server side solution is possible. That is where rathole is active in "server" mode. I'm currently working with ufw but for example geoblocking is not easily possible. I don't want to generate spam or an unnecessary post, but I think it would be good if the security aspect would be addressed here at the repository. Just for example that it is recommended to set up a server-side firewall. Would be exciting to know if and how there are users here who have set up a server-side solution for geoblocking. |
It's not safe when not configured appropriately. For most use cases, I think let the reverse proxy always removes any existing x-forwarded-for headers and always adds its own header is enough. It prevents visitors from bringing their own fake headers.
I have no experience with ufw and geoblocking. But I can't see how rathole server is different from other normal services with geoblocking. If you can set up a geoblocking rule with ufw for port 8000, at which some normal service is running, what blocks setting up a rule for port 9000, at which a service from rathole is running?
Agree. In the future maybe a repo wiki is needed. README has grown a lot since the project launch. |
I don't think rathole should do anything with firewall, why not just use ufw with fail2ban? That's really simple to do these kind of things. |
It's not about rathole doing anything with firewall for me either. I just think it is important that at least it is pointed out that you should pay attention to security and a firewall is recommended. How would a solution with fail2ban be implemented, roughly? Assuming the service behind the tunnel is Plex, it would be very difficult to integrate fail2ban. How does Plex communicate on the private network with fail2ban on the Rathole server? Plex is very special because you have to log in with your Plex account. |
Actually, fail2ban can read the log, you can just set |
Yes fail2ban is known to me. But how exactly should this work if all requests via the rathole tunnel have the LOCAL ip address 127.0.0.1? That is the problem and 127.0.0.1 can not be blocked. You have the same problem with a Synology NAS with active geoblocking and active tunneling. Maybe I'm misunderstanding something, but a fail2ban solution is not possible in the private network. Not as long as each user simply has the IP address 127.0.0.1 which I can see at least in the Synology logs when a user uses incorrect login data. |
Ah, I see your doubts, what do you think about |
The logic does not work, because all accesses to my private network, which run over the tunnel, have the local IP 127.0.0.1. Every incorrect login attempt has the IP address 127.0.0.1 stored and I can not block this, because then the tunnel is blocked and this is a local IP address. |
What if you put a reverse proxy like NGINX to use proxy protocol? Not like |
I will look at this as soon as I have time. Thanks for your help :) |
Glad to help :) |
So I have now partially implemented a solution.
Thanks to NPM the correct IP of the visitor is added as header and my devices (e.g. Synology NAS) can block P addresses after x failed login attempts. Now I would just have to find a solution to send the failed login attempts from Plex to my Rathole server so that fail2ban takes this into account. Maybe I will do this one day. Important to mention:Docker sets rules in the iptables by default. Therefore, ufw rules would then be ignored. For me it was the file: And I had to add "--iptables=false" to the ExecStart command: |
Is there a chance perhaps the rathole client could forward the TCP stream to a unix domain socket, rather than an IP and a port? Would that help? i.e. "unix:/tmp/sock" or "unix:/var/run/nginx.sock" |
(Let's have a VPS with public IP; home LAN server behind CGNAT providing various services). So:
This actually makes me re-consider the WireGuard tunnel between VPS and LAN server (with port fowarding without masquerade/snat to keep the external source ip address). The down-side of this approach is that the route for replying packets from LAN server must go via VPS and not via my local internet connection. Not sure at the moment, if this means a default home LAN server's route for every out-going packets to go via VPS (which would consume VPS's bandwidth unnecessarily) or some kind of dynamic routing for selected packets (Use of iptables connmark for anything coming via tunnel? Would this also work for dockerised services?). |
I had the similar use case (open access on local network, but fail2ban + lower ratelimits per IP + client certs for external connections) . However, the nginx and sshd access logs indicated all requests to have been coming from the local machine. Setting up haproxy / nginx on the VPS (rathole server) side to add the proxy protocol header would have worked, but it seemed like an overkill. Reading up the Proxy Protocol specification, the V1 implementation seemed simple enough. So, I added the logic in rathole server to natively emit the proxy protocol v1 header. That way no additional setup is required on the VPS / rathole server side. Its available in my fork and this diff. Hope it helps someone else. |
Should the game server also have the "Proxy Protocolhaproxy-protocol"? |
I wanted to add that PROXY protocol is the standard solution for this, which can be found in many reverse proxies. I know rathole is not trying to be a reverse proxy per se, but it is proxying the TCP/UDP traffic. This is the PROXY protocol spec: I have seen in many other issues that there seems to be some confusion about application layers and http. This proxy protocol we are talking about does not work on the application layer, it works on the transport layer (TCP). Since rathole proxies our traffic, I think it would be very useful for it to support PROXY protocol , which is defined for the purpose of allowing downstream servers to know the original requesting IP. This would make it work transparently with security systems like geoblocking, Fail2Ban, crowdsec etc. @shshekhar93 already did some great work implementing v1, if that could be merged and potentially v2 added (v2 is just faster because it uses less bytes to represent the data) I think that would be a great feature. I know we can use nginx to add the proxy protocol data, but then what is the point of using rathole? I can just tell nginx to send the TCP down a wireguard tunnel to my server. Rathole could be a brilliant all in one solution, (it already is) but for me the proxy protocol is a really important part. I use it to restrict access to certain internal services. |
how to build your project? |
@linnuxx, The build process is same as the original project. |
Hi @
Hi @shshekhar93 , I tried to compile your project and didn't succeed, would you be so kind to provide the instructions, I compiled Error:
With
Please provide more detail, Thanks, this software is great. |
Hi, please provide linux binary versions, I have |
Hi @shshekhar93 , thanks for you help, I compiled it successfully in a new Ubuntu 22.04 VM and the option, Browser: Note: I copied your compiled version on both machines. Client:
Server:
Thanks for your help. |
Hello! Thank you so much for the PR, @shshekhar93; I hope it will get accepted soon. 👍 @nando2301, Proxy Protocol v1 is working fine on my side. I believe your issue is on the backend, which needs to be configured as well to accept the proxy protocol. In my case, I'm using Traefik v3.0.0. If you want to make sure it's not related to the rathole build, you can test with this image: https://hub.docker.com/r/mydoomfr/rathole |
Thanks for the comment, I have HAProxy in front of my services, I will check that you comment. Thanks. |
Thanks @mydoomfr Ready! Now the IP Blocking is Working Attack (IP received on HAProxy due to proxy protocol v1 is enabled):
HAProxy Config (I just added
Synology Blocked IPs: Thanks for all information and guidance, This project is great! |
I can confirm that the @shshekhar93 branch work pretty well, also supporting v2 binary would be very useful as rathole tries its bets to avoid overhead. cheers @shshekhar93 and thank you. BTW the PR(#352 ) is stuck on linting |
Follow up this issue I end up doing some work on the proxy protocol support suggest by @shshekhar93 now supporting v2 as well, I'm using this right now without any issue Any feedback is really appreciated, as its my first time using RUST |
I'm using rathole to forward ssh connections to a local sftp server, wich works great. But I have no experience with ssh proxies or anything like that. Is it possible to get the original ip when using ssh so I can use fail2ban? I can't use |
Try use proxy protocol. Since Rathole does not work at the application layer, you need to use an application that supports the proxy protocol. |
How would I go about doing that? I currently only use a proxy (caddy) for my http/https webservices wich usually understand the |
@hendrikbl As I said above, you have to use third-party applications, such as gost/proxy-protocol. |
Feature Proposed
I have seen that there were already some posts here where the idea came up to forward and process the IP address of the users accessing a service through such rathole tunnels.
As far as I have seen this is not possible and every user/visitor of a rathole tunnel gets the local IP address 127.0.0.1 - Is this not dangerous from a security point of view? So you can no longer see or distinguish in the network where this access came from. So a firewall with geoblocking (e.g. also on a Synology NAS) is useless.
It goes without saying that the applications behind these tunnels should always be secured as well as possible. However, initial protection against this should not be neglected.
I would like to know if no one really thinks or worries about this or how appropriate solutions have perhaps already been implemented.
Use Case
Geoblocking
Security
Better monitoring
The text was updated successfully, but these errors were encountered: