-
Notifications
You must be signed in to change notification settings - Fork 0
Rate limiting in PolicyEngine #39
Copy link
Copy link
Closed
Labels
complexity:averageModerate effort, some design neededModerate effort, some design neededphase:authRegistry, tokens, policyRegistry, tokens, policypriority:highCore functionalityCore functionalitysecuritySecurity-related issue or hardeningSecurity-related issue or hardeningsize:MMedium change, 50 to 200 linesMedium change, 50 to 200 linestype:featureNew functionalityNew functionality
Milestone
Metadata
Metadata
Assignees
Labels
complexity:averageModerate effort, some design neededModerate effort, some design neededphase:authRegistry, tokens, policyRegistry, tokens, policypriority:highCore functionalityCore functionalitysecuritySecurity-related issue or hardeningSecurity-related issue or hardeningsize:MMedium change, 50 to 200 linesMedium change, 50 to 200 linestype:featureNew functionalityNew functionality
Milestone: v0.2.0 | Tier: Medium | Effort: Medium
Problem
security.mdexplicitly lists rate limiting as a gap: there is no throttling of any kind. A compromised or runaway agent can invoke capabilities at unlimited rate, potentially:This is the #1 security gap identified in the repo's own documentation.
Proposed Change
1. Rate limiter implementation
Add a sliding-window rate limiter to
DefaultPolicyEngine, enforced per(principal_id, capability_id)pair:2. Default rate limits by safety class
3. Configuration
DefaultPolicyEngineconstructor:rate_limits: dict[SafetyClass, tuple[int, float]]"service"role principals get 10x the default limits4. Integration point
evaluate()after role/sensitivity checks pass, before returningPolicyDecision.PolicyDenied(f"Rate limit exceeded: {limit} {safety_class} invocations per {window}s for principal '{principal_id}'")time.monotonic()internally for testability with injectable clock.Acceptance Criteria
PolicyDeniedwith "Rate limit exceeded"PolicyDeniedPolicyDeniedDefaultPolicyEngineconstructor"service"role gets 10x limits (600/100/20)(principal_id, capability_id)pair (not global)time.sleep()in tests)Affected Files
src/agent_kernel/policy.py(RateLimiter class + evaluate() integration)tests/test_policy.py(rate limit tests with mock clock)docs/security.md(update gap list — rate limiting now implemented)