google-cloud-platformrate-limitinggoogle-cloud-load-balancergoogle-cloud-armor

Add x-rate-limit response headers to the load balancer


I configured a Cloud Armor rate limiting rule and i would like to attach the following custom response headers to my global external HTTP(S) load balancer backend.

x-ratelimit-limit: The maximum number of requests available in the current time frame.
x-ratelimit-remaining: The number of remaining requests in the current time frame.
x-ratelimit-reset: A UNIX timestamp of the expected time when the rate limit will reset.

In the custom headers documentation no rate limit variable seems to exist. There is however a notice about Cloud Armor Response Headers further down:

You can configure Google Cloud Armor to insert a custom header and value.

I found the --request-headers-to-add rule setting but i need some way to access the current Cloud Armor rate limit values.

Is my use case not possible or can anyone point me in the right direction?


Solution

  • You can create a Cloud Function to retrieve Cloud Armor rate limit values to do this: