Cloud Run Client Request IP address gets overridden by proxy Python Fast API

Viewed 570

There is an issue of getting real user request IP address inside web application that is running on Cloud Run service. By some reason the web application obtains the same IP address for all users requests - 169.254.8.129 . I'm assuming it's a load balancer in front of cloud run service overrides requests IPs with his own. I have double checked already this issue with different apps on Flask, FastApi and ASP.NET Core in Cloud Run. All apps returning the same results and all having the same issue.

But, when I am checking those apps on VM and everything works fine there.

How can I get the user's IP-Address in my Cloud-Run Flask app?

I have found some part of the answer, but still cannot handle the same for FastApi.

1 Answers

The address 169.254.8.129 is the address of the proxy sitting in front of your Cloud Run service.

You can extract the list of IP addresses from the HTTP header X-Forwarded-For. This list usually includes the client and each proxy or load balancer in between the client and your application.

X-Forwarded-For

Related