feat(dns): per-identity rate limiting on DoH endpoints - #65
Merged
Conversation
Adds token-bucket rate limiting for DoH /dns/query endpoint with: - Per-identity tracking (JWT subject → SPIFFE ID → client IP) - In-memory backend with LRU eviction (10k keys default) - Optional Valkey backend via SQUAWK_RATE_LIMIT_BACKEND=valkey - Configurable RPS and burst via env vars (default 50 RPS, 100 burst) - 429 responses with Retry-After header when limited - Disabled by default (SQUAWK_RATE_LIMIT_ENABLED=false) - Prometheus metrics for allowed/limited requests by identity type - Comprehensive async test coverage (27 tests, 100% pass) No overhead when disabled (single boolean check). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🧙 Sourcery is reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Sorry @PenguinzTech, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
PenguinzTech
added a commit
that referenced
this pull request
Jul 27, 2026
- dns-server/app/main.py: combined imports -- this branch's domain_policy/jwt_verify additions plus already-merged #65's rate-limit config vars and RateLimiter import. Also removed a redundant local re-import of verify_squawk_jwt/JWT_PUBLIC_KEY (leftover from #65's original code) that was shadowing the combined module-level import and tripping flake8's F401 check. - dns-server/app/services/prometheus_metrics.py: combined two independent new methods (record_policy_denial from this branch, record_rate_limited_query from #65) on the same metrics class -- their backing Counter definitions survived the auto-merge intact. - manager/backend/app/services/auth_service.py: auto-merged cleanly but silently dropped the `List` import from typing while THIS branch's new allowed_domains: Optional[List[str]] parameter still uses it -- classic silent-auto-merge risk. Restored. Full manager suite: 264/264 passing. dns-server: 112/112 real tests passing (8 rate-limiter test errors are a pre-existing bug already fixed in #77, not yet in this branch's v2.1.x snapshot -- will re-verify after pulling latest v2.1.x). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-identity rate limiting on the DoH data plane (dns-server/app). Async token-bucket keyed by verified JWT
sub→ SPIFFE ID → client IP; in-memory backend with 10k-key LRU cap (IP churn can't exhaust memory) + optional Valkey fixed-window backend (SQUAWK_RATE_LIMIT_BACKEND=valkey). Off by default (SQUAWK_RATE_LIMIT_ENABLED, default RPS 50 / burst 100); over-limit → 429 + Retry-After. Prometheus counters labeled by key type only — no identity values in labels.Tests: 48 green (27 unit + 11 integration; injected clock, no sleeps).
Stack note: bases on
chore/dedup-reusable-code(top of the #53–#59 chain); auto-retargets towardv2.1.xas the stack merges bottom-up.🤖 Generated with Claude Code
Summary by Sourcery
Add configurable per-identity rate limiting to the DNS DoH server with metrics and status reporting.
New Features:
Enhancements:
Tests: