feat(webapp): share rate limit bucket across additional API keys per environment - #4508
Conversation
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (18)
WalkthroughAPI rate limits now use environment-scoped buckets. A new resolver maps valid private API keys to an environment and limiter configuration. Rate-limit middleware carries optional identifiers through override resolution, caching, validation, and bucket checks. JWT limits retain fixed-window behavior. Limits presenter lookups now use environment identifiers instead of hashed API keys. Tests cover shared buckets, isolated token buckets, preview environments, and deleted projects. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ba817b9 to
316db63
Compare
@trigger.dev/build
trigger.dev
@trigger.dev/core
@trigger.dev/python
@trigger.dev/react-hooks
@trigger.dev/redis-worker
@trigger.dev/rsc
@trigger.dev/schema-to-json
@trigger.dev/sdk
commit: |
316db63 to
cd2a0c0
Compare
eb0e8f7 to
e9ae728
Compare
10388e2 to
15b81de
Compare
…environment remove comments fix(webapp): bucket restricted additional API keys by environment too feat(webapp): bucket root API keys per environment too fix(webapp): version rate-limit cache key and validate cached shape on read use new resolver for api keys fix(webapp): keep environment rate-limit buckets consistent Use environment identifiers when displaying remaining API capacity and ignore additional keys tied to deleted projects. Update .server-changes/additional-api-key-rate-limit-bucket.md Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> fix(webapp): keep public API keys on separate rate-limit buckets fix limits presenter for preview branches
15b81de to
ee84c89
Compare
What
Rate-limit the API by environment rather than per API key.
Previously the limiter keyed its bucket on the hash of the full
Authorizationheader — one bucket per key. With additional environment API keys (tr_*_sk_*), an environment can mint many keys and each got its own full bucket, so more keys = higher effective rate limit. This collapses all of an environment's keys onto a single shared per-environment bucket, so the ceiling is exactly the configured limit regardless of key mix.How
authorizationRateLimitMiddlewarenow lets the override return{ config?, identifier? }.identifier, when present, is the rate limit bucket key; otherwise it falls back to the hashedAuthorizationheader (unchanged legacy behavior, still used byengineRateLimiterand any unauthenticated fallthrough).apiRateLimiter's override resolves the environment id and uses it as the identifier:isAdditionalApiKey) resolve via a newresolveAdditionalApiKeyRateLimitScope()— a scope-agnostic keyHash → (environmentId, org limiter config) lookup. It is deliberately permissive (restricted keys resolve too) because it's used only for bucketing, never as an auth decision — request auth still goes through the RBAC bearer controller, which enforces scopes. Revoked/expired keys are excluded so they can't hold a bucket warm.authenticateAuthorizationHeaderand key onenvironment.idtoo.Behavior notes
Tests
{ config }return shape.Base:
feat/multi-keys-surface. Closes TRI-12888.