Add rate limiting to gRPC and HTTP APIs

Problem

The Knowledge Graph has no rate limiting on any API surface. One misbehaving client can starve the cluster for everyone else.

Affected entry points:

  • gRPC API (crates/gkg-server/src/grpc/) - query endpoints, redaction exchange
  • HTTP webserver (crates/gkg-server/src/webserver/) - REST API, health endpoints

gRPC layer

  • Token bucket or sliding window limiter as a gRPC interceptor
  • Per-namespace limits scoped by organization_id or namespace from JWT claims
  • Global fallback limit for unauthenticated or unscoped requests
  • Return RESOURCE_EXHAUSTED when limits are hit

HTTP layer

  • Rate limiting middleware on REST API endpoints
  • Return 429 Too Many Requests with Retry-After header

Query engine

  • Max concurrent queries per namespace
  • Query result size limits (currently unbounded - no cap on rows returned)
  • Query timeout enforcement with resource cleanup on abort

Configuration

  • Configurable via config/default.yaml and environment variables
  • Separate limits for read vs write operations
  • Separate limits for API queries vs indexer operations

Context

No rate limiting exists anywhere in the codebase. The worker pool uses semaphore-based concurrency control (crates/indexer/src/worker_pool.rs) but that only covers indexer workers, not API requests.

PREP assessment: https://gitlab.com/gitlab-org/architecture/readiness/-/merge_requests/67 PREP template: operational_lifecycle/error_handling_and_degraded_state_behavior.md (related)

Edited by Michael Angelo Rivera