Serve static content from Cloud Run to static ip
I'm new to Google cloud but as I understand it I can serve my react content from Cloud Run. I want to filter traffic and only return the content if it's being requested from a specific ip I define. Is there a way to do that with just Cloud run and nginx or do I need a load balancer too?
3 comments · 100% upvoted · other discussions
Cloud Run provides the client's IP address to your container. In Express, I use this code to get that IP address from an incoming HTTP request:
I don't know what the equivalent would be in nginx. Maybe this is the right documentation?
aws2gcp 1 points · May 2023
I know Nginx can definitely be configured to log client IP via the x-forwarded-for header for scenarios where nginx is running behind an LB or reverse proxy, which is the case with Cloud Run. Just not sure if it supports performing behaviors based on that.
The LB solution would work, although it would also need to have a CloudArmor policy to do the ip whitelist.
TBD it might be easier to just implement this as the application layer.
martin_omander 1 points · May 2023 · :google: Googler
Yes, I didn't know if that was an option in your application. But I agree; that's an easy way to do it.