4 months ago
Hi there! I'm currently evaluating whether I can move all my services from render to railway.
One absolutely key feature render provides is the ability to expose databases to the public internet only from certain IP addresses - this extra layer of safety is crucial for me, to ensure I can still access the database locally without exposing it to the world with only a flimsy password as protection.
I realize that one way to achieve this on render is to expose the private network via a tailscale node. I tried this, and it wasn't fit for purpose. The connection was extremely slow (around 10 seconds to connect), it timed out consistently during a pg_restore, and didn't work in the dbeaver GUI for some reason. The TCP proxy works great, but is open to the world.
Does railway have any plan to offer such a service in the future? I really hope so, because I love everything else I've seen about railway so far!
Thanks!
Pinned Solution
2 months ago
In conclusion: After a lot of research, this can't be done on Railway currently, and there is no workaround for it either. However, I'd recommend you use a service like Neon for the database. They offer IP-whitelisting for their Scale subscription. And you could host the rest of your services here on Railway.
16 Replies
4 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open Railway • 4 months ago
4 months ago
Inbound IP rules are not available on railway currently. But you can deploy an Nginx service infront of your db, expose it via TCP, and manage the allow-list manually in the Nginx config as a workaround.
2 months ago
Thanks @darseen . If you can give me detailed instructions on how to do this in railway, I'd be happy to mark this as the accepted solution! Thank you!
danguetta
Thanks @darseen . If you can give me detailed instructions on how to do this in railway, I'd be happy to mark this as the accepted solution! Thank you!
2 months ago
I will make an Nginx template that handles this, to make it easier for you. It shouldn't take long. I will write here when it's done.
2 months ago
I spent some time testing and trying to build out that Nginx template to manage the database IP allow-list, but I ran into a hard platform limitation.
Unfortunately, IP allow-listing for TCP traffic isn't currently possible on Railway.
When you expose a service via a public TCP port, Railway routes that traffic through their internal load balancers. This means the Nginx container never sees your actual public IP, it only sees Railway's internal network IPs.
2 months ago
Ah that makes sense. Doesn't Railway set headers to include the original IP? Could we use those, or could these be spoofed? Thanks so much for trying.
danguetta
Ah that makes sense. Doesn't Railway set headers to include the original IP? Could we use those, or could these be spoofed? Thanks so much for trying.
2 months ago
Because database connections are raw TCP streams (layer 4), we can't rely on HTTP (layer 7) headers like X-Forwarded-For to grab the real IP. You're welcome though.
2 months ago
It's worth mentioning that the industry standard way to fix this for TCP is the "PROXY protocol", but Railway doesn't currently support injecting that on their public TCP endpoints.
2 months ago
In conclusion: After a lot of research, this can't be done on Railway currently, and there is no workaround for it either. However, I'd recommend you use a service like Neon for the database. They offer IP-whitelisting for their Scale subscription. And you could host the rest of your services here on Railway.
2 months ago
OK, thank you for all your work on this; I just marked the answer is approved. I hope Railway adds this feature down the line. Do you think using an external service for the database (Neon) would add noticeable latency to the service (compared to putting everything inside Railway's private network)? If not, it seems worth trying.
2 months ago
You're welcome! As for the latency, yes, it will add some latency, but whether it is noticeable depends on region alignment and how your code queries the database. And since IP-whitelisting is crucial for you, I think it's worth the trade off.
2 months ago
I forgot to mention that egress costs will increase as well. So, I suggest you take that into consideration, and see if it's feasable to host the db using an external service like Neon.
After all, if IP-whitelisting is your top priority, these are the trade offs that you need to consider.
Status changed to Solved chandrika • about 2 months ago
2 months ago
That's correct. Headers like X-Forwarded-For only apply to HTTP traffic through our edge proxy. The TCP proxy operates at Layer 4, so database connections over it don't carry HTTP headers, and there's no mechanism to retrieve the original client IP. IP allowlisting for TCP proxy is a known feature request that we're tracking.
Status changed to Awaiting User Response Railway • about 2 months ago
2 months ago
If you want my advice; I suggest you host your db on Railway, remove public TCP connection for the database, and rely only on internal connection. As for development, you can set up a development database locally. You can dump data from your production db, and restore to your local development one. I have a template to back up your database using its internal URL. It will download a dump file to your machine that you can use to restore to your local dev db.
Status changed to Awaiting Railway Response Railway • about 2 months ago
Status changed to Solved sam-a • about 2 months ago
chandrika
That's correct. Headers like X-Forwarded-For only apply to HTTP traffic through our edge proxy. The TCP proxy operates at Layer 4, so database connections over it don't carry HTTP headers, and there's no mechanism to retrieve the original client IP. IP allowlisting for TCP proxy is a known feature request that we're tracking.
2 months ago
Thanks @chandrika . Is there anywhere public you're tracking the request that I can keep bookmarked? This is the only feature stopping me from moving my apps over from render, so when it happens I'd love to know!
And thanks for the advice and help @darseen
Status changed to Awaiting Railway Response Railway • about 2 months ago
2 months ago
You can track and upvote feature requests on our public roadmap here: https://station.railway.com/roadmap
We are also tracking this thread against the request, so it is likely you would be notified here if we added the feature as well.
Status changed to Awaiting User Response Railway • about 2 months ago
2 months ago
One more question if I may - does the Railway API allow me to create/delete a TCP proxy from Python? If so, I think my solution here will be to use a public TCP Proxy, but only very briefly open it when I need it and then close it as soon as I'm done - is that doable? The GraphQL docs do have TCPProxy mentioned there, so it looks doable, but it's my first time using GraphQL so I still need to do some digging. If I figure it out before someone answers, I'll post the code to do it here. Thanks again!
Status changed to Awaiting Railway Response Railway • about 2 months ago
Status changed to Open brody • about 2 months ago