Problem#
There is no rate limiting on authentication attempts. The production metrics already track grain_auth_failures_total, and the metrics endpoint reveals significant reconnaissance traffic (probes for .env, .git/config, wp-login.php, etc.). A brute-force attack against the Basic Auth credentials would be unthrottled.
Proposed Solution#
- Add per-IP rate limiting middleware for authenticated endpoints (especially
/v2/) - Consider using
tower::limitor a dedicated rate limiting crate likegovernor - Configurable limits via CLI args (e.g.,
--auth-rate-limit 10/minute) - Return
429 Too Many RequestswithRetry-Afterheader when limit is exceeded - Add a
grain_rate_limited_totalPrometheus counter
Alternatives#
- Could rely on reverse proxy (Caddy) for rate limiting, but defense-in-depth is preferred
- IP-based limiting may not work well behind proxies without
X-Forwarded-Forhandling