Skip to content

Add PROXY protocol support for rate limiting behind load balancers#6819

Open
raajheshkannaa wants to merge 1 commit intospiffe:mainfrom
raajheshkannaa:fix/rate-limit-behind-lb
Open

Add PROXY protocol support for rate limiting behind load balancers#6819
raajheshkannaa wants to merge 1 commit intospiffe:mainfrom
raajheshkannaa:fix/rate-limit-behind-lb

Conversation

@raajheshkannaa
Copy link
Copy Markdown

Summary

When SPIRE server sits behind a load balancer that doesn't preserve client IPs, per-IP rate limiting treats all agents as one client (the LB IP). This adds opt-in PROXY protocol support so the server can extract real client IPs from the PROXY protocol header.

  • Adds listen_proxy_protocol config option (defaults to false)
  • Wraps the TCP listener with github.com/pires/go-proxyproto when enabled, so conn.RemoteAddr() returns the real client IP
  • No changes to rate limiting middleware needed, since it already reads from the gRPC peer address
  • The library was recommended in the issue discussion by @sorindumitru

Configuration

server {
    listen_proxy_protocol = true
}

This must only be enabled when the load balancer is configured to send PROXY protocol headers.

Fixes #6678

Test plan

  • New unit test verifying PROXY protocol listener extracts real client IP from v1 header
  • Config parsing tests for listen_proxy_protocol in both file config and server config
  • Existing endpoint and rate limiting tests pass unchanged

When SPIRE server runs behind a load balancer that does not preserve
client IPs, all requests appear to originate from the load balancer,
causing per-IP rate limiting to incorrectly throttle all agents as
a single client.

This adds opt-in PROXY protocol (RFC 5765) support via a new
listen_proxy_protocol configuration option. When enabled, the TCP
listener is wrapped with a PROXY protocol listener (using
github.com/pires/go-proxyproto) so that conn.RemoteAddr() returns the
real client IP encoded in the PROXY protocol header. The existing rate
limiting middleware requires no changes since it already reads the
client IP from the gRPC peer address.

The option defaults to false and must be explicitly enabled, since the
load balancer and SPIRE server must agree on PROXY protocol usage.

Fixes spiffe#6678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPIRE server incorrectly rate limits when behind a load balancer that doesn't support client IP preservation

1 participant