Private
Public Access
1
0

fix: replace broken DashMap rate limiting with tower-governor middleware
All checks were successful
CI Pipeline / Rust Format Check (push) Successful in 4s
CI Pipeline / Clippy Lints (push) Successful in 1m1s
CI Pipeline / Rust Unit Tests (push) Successful in 1m21s
CI Pipeline / Security Audit (push) Successful in 4s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 16s
CI Pipeline / Build .deb & Release (push) Has been skipped

- Replace custom DashMap<IpAddr, Instant> rate limiting in enrollment.rs
  that fell back to 0.0.0.0 when X-Forwarded-For was missing, causing
  ALL enrollment traffic to share a single global rate limit bucket
- Use tower_governor with SmartIpKeyExtractor for proper per-IP rate
  limiting that respects X-Forwarded-For headers (critical behind HAProxy)
- Add three configurable rate limit tiers via config.toml:
  * Enrollment: 5 req/min per IP, burst 3 (strict)
  * Auth: 20 req/min per IP, burst 10 (moderate)
  * API: 120 req/min per IP, burst 30 (normal)
- Remove enrollment_rate_limits from AppState and cleanup task
- Remove manual rate limit code from enrollment.rs (headers param, IP extraction)
- Add into_make_service_with_connect_info for ConnectInfo fallback
- Add RateLimitConfig to AppConfig with sensible defaults

Fixes: #1
This commit is contained in:
2026-05-21 02:27:10 +00:00
parent 6c72dc3ac6
commit 59794bc8f2
7 changed files with 395 additions and 79 deletions

View File

@ -107,3 +107,20 @@ web_tls_key_path = "/etc/patch-manager/tls/web.key"
# The backend sends tokens as query parameters to this URL.
# Default: "http://localhost:5173/auth/sso/callback" (Vite dev server)
sso_callback_url = "http://localhost:5173/auth/sso/callback"
# ============================================================
# Rate Limiting
# ============================================================
[rate_limit]
# Enrollment endpoint: requests per minute per IP (default: 5)
enrollment_rpm = 5
# Enrollment burst allowance (default: 3)
enrollment_burst = 3
# Public auth endpoints: requests per minute per IP (default: 20)
auth_rpm = 20
# Auth burst allowance (default: 10)
auth_burst = 10
# Authenticated API: requests per minute per IP (default: 120)
api_rpm = 120
# API burst allowance (default: 30)
api_burst = 30