Expand description
Throttling a peer that keeps failing authentication (spec §13.4: agents SHOULD implement rate limiting to prevent brute-force attacks).
RateLimitInterceptor cannot do this. Set
after the authenticating interceptor, it never sees a call whose
credential was refused; set before it, it keys every caller nobody has
identified yet alike. AuthFailureThrottle counts, per peer, the calls
an authenticating interceptor refused as unauthenticated, and refuses a
peer that reached the limit in the current window with a rate-limit error
(HTTP 429, gRPC RESOURCE_EXHAUSTED) carrying the delay until the window
ends. Opt-in: nothing throttles failed authentication unless it is
registered.
§Placing it
Register it before the authenticating interceptor. Its
before then refuses a throttled peer
without the credential being checked, and its
on_complete, which runs once the
authenticator has refused the call, counts the failure.
§Who a peer is
- With
trusted_proxy_hopsset, the client address those proxies appended tox-forwarded-for: thehops-th entry from the right, asRateLimitConfig::trusted_proxy_hopsdescribes. - Otherwise, or when the header has fewer entries than that, the address
of the connection,
CallContext::peer_addr, which every binding sets when it is served by the SDK (seecall_context). - A call with neither is not throttled. Counting such calls under one shared key would let any caller lock every other one out.
The key is the IP address alone, without the port, with an IPv4-mapped
IPv6 address taken as its IPv4 form and an IPv6 address as its /64 (a
host is routinely given a whole /64; the rate limiter keys it the same
way). Everyone behind one address (a NAT,
or a proxy whose hop is not trusted) therefore shares one count: a peer
that keeps failing locks the others there out until the window ends.
§Bounds
Failures are counted in fixed windows of window_secs; a successful call
does not reset the count. A failure is counted when its call ends, so the
calls a peer already has in flight when it reaches the limit are still
checked: in one window a peer gets max_failures plus that many attempts.
At most max_peers peers are tracked: when the map is full, peers whose
window has passed are dropped, and a new peer that still does not fit is
not counted (fail-open), so the map cannot grow without bound under an
address-rotating attack.
§Replicas
Counts are per process unless
with_shared_counter gives the
throttle a RateLimitCounter every replica reaches. Without one, a fleet
of N replicas gives a peer up to N × max_failures guesses a window: a
balancer that spreads one peer’s failures leaves each replica seeing about
1/N of them. With one, each failure is also counted there, and the throttle
keeps the larger of its own count and the total the counter reports; see
the method for what that costs and what it leaves open.
Structs§
- Auth
Failure Throttle - Refuses a peer that has failed authentication too often; see the module docs.
- Auth
Failure Throttle Config - Configuration for an
AuthFailureThrottle.