Repository navigation
workloadmanager: add per-owner sandbox creation rate limiter - #512
SoumaCloud wants to merge 2 commits into
Conversation
POST /sandbox already resolves owner identity via resolveSandboxOwnerID but placed no admission control on that identity. A single tenant could loop sandbox creation requests and exhaust cluster pod quota, node capacity, and network IPs for all other tenants with no HTTP-level protection. Add a per-owner token bucket rate limiter (burst=5, rate=0.5/s) checked immediately after owner identity is resolved in handleSandboxCreate. When the bucket is empty the handler returns 429 Too Many Requests with a Retry-After header so clients can back off gracefully. Each owner gets an independent bucket so a noisy tenant cannot affect others. Stale per-owner state is evicted after 10 minutes of inactivity to prevent unbounded memory growth in long-running deployments. The check is skipped when ownerID is empty (unauthenticated flows, integration tests, CLI tools) so existing admin paths are unaffected.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #512 +/- ##
==========================================
+ Coverage 60.45% 63.95% +3.49%
==========================================
Files 35 36 +1
Lines 3616 3695 +79
==========================================
+ Hits 2186 2363 +177
+ Misses 1211 1097 -114
- Partials 219 235 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… DCO sign-off - Extract inline rate-limit block into checkOwnerRateLimit helper to keep handleSandboxCreate cyclomatic complexity within gocyclo limit (<=15) - Promote golang.org/x/time from indirect to direct in go.mod (codegen check) - Add DCO Signed-off-by to satisfy Linux Foundation contributor requirements Signed-off-by: Soumadip Patra <tanmaytanmay1906@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Problem
handleSandboxCreatealready callsresolveSandboxOwnerID()on everyPOST /sandboxrequest and attaches the result to the sandbox store entry — but no admission control
acts on that identity. A single tenant can loop sandbox creation requests and exhaust
cluster pod quota, node capacity, and network IPs for all other tenants with zero
HTTP-level protection.
Solution
Add a per-owner token bucket rate limiter checked immediately after owner identity
is resolved.
Behaviour:
429 Too Many Requests+Retry-After: Nheader so clients back off gracefullyownerID == ""so integration tests, CLI tools, and admin flows continue workingEach owner gets an independent bucket — a noisy tenant cannot affect another tenant's quota.
Changes
pkg/workloadmanager/rate_limiter.goOwnerRateLimiterbacked bygolang.org/x/time/ratepkg/workloadmanager/rate_limiter_test.goRetryAfter, stale evictionpkg/workloadmanager/handlers.goresolveSandboxOwnerIDpkg/workloadmanager/server.gorateLimiterfield, initialize inNewServerTests
All existing tests continue to pass.
🤖 Generated with Claude Code