-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Problem Analysis
The SetIETFHeaders method in policies/advanced-ratelimit/limiter/result.go (from gateway-controllers PR #1) claims to implement the IETF draft standard draft-ietf-httpapi-ratelimit-headers-10 but actually implements a different, legacy header format.
Current Implementation
The code currently sets the following headers with plain integer values:
RateLimit-Limit: Maximum requests allowedRateLimit-Remaining: Remaining requests in current windowRateLimit-Reset: Seconds until reset (integer)RateLimit-Full-Quota-Reset: Seconds until full quota available (integer)RateLimit-Policy:<limit>;w=<window_in_seconds>(simple format)
Expected Behavior per draft-ietf-httpapi-ratelimit-headers-10
According to the IETF draft standard, the implementation should use:
Two primary headers using Structured Fields (SF) syntax:
-
RateLimit-Policy: Advertises quota policies (List[SF])- Parameters:
q(quota),w(window in seconds),qu(quota unit),pk(partition key) - Example:
RateLimit-Policy: "default";q=100;w=10
- Parameters:
-
RateLimit: Conveys current service limits (List[SF])- Parameters:
r(remaining),t(reset time),qu,pk - Example:
RateLimit: "default";r=50;t=30
- Parameters:
The draft does NOT define RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset, or RateLimit-Full-Quota-Reset as separate headers.
Suggested Fixes
Approach 1: Update Documentation (Quick Fix)
- Remove or update the reference to
draft-ietf-httpapi-ratelimit-headers-10 - Document that this follows a legacy/custom rate limit header format (X-RateLimit-* style)
- Clearly state this is not compliant with the IETF draft standard
Approach 2: Implement IETF Draft-10 Standard (Full Compliance)
Refactor SetIETFHeaders to emit proper Structured Fields:
-
Replace individual
RateLimit-*headers with:- Single
RateLimit-Policyheader:"<policy_name>";q=<limit>;w=<window_seconds> - Single
RateLimitheader:"<policy_name>";r=<remaining>;t=<reset_epoch>
- Single
-
Use Structured Fields syntax (RFC 8941) for parameter encoding
-
Convert time values appropriately:
- Use epoch seconds for
tparameter (reset time) - Use window duration in seconds for
wparameter
- Use epoch seconds for
-
Consider adding support for multiple policies if needed
Approach 3: Hybrid Approach
- Keep existing headers for backward compatibility
- Add new IETF-compliant headers alongside
- Use feature flag or configuration to control which headers are emitted
Impact
- Users: May be confused by documentation claiming IETF compliance
- Interoperability: Clients expecting IETF draft-10 format will not parse headers correctly
- Compliance: Claiming standard compliance when not following it could lead to integration issues
References
- Source PR: Consolidate APIM policies into gateway-controllers repository gateway-controllers#1
- Review Comment: Consolidate APIM policies into gateway-controllers repository gateway-controllers#1 (comment)
- IETF Draft: https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers-10
- Affected File:
policies/advanced-ratelimit/limiter/result.go
Requested By
@DakshithaS (from PR review)
Priority: Should be addressed before release to avoid claiming false standard compliance.