-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allows authorized clients to bypass rate limiter #599
Conversation
@@ -28,6 +29,9 @@ func TestLimit1IP(t *testing.T) { | |||
|
|||
{name: "success", callRPS: 100, limitRPS: 500, forwardedFor: false}, | |||
{name: "block-me", callRPS: 1000, limitRPS: 500, forwardedFor: false}, | |||
|
|||
{name: "allow-me", callRPS: 1000, limitRPS: 500, forwardedFor: false, allow: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adds two more test cases where rps is greater than limit but it never gets 429
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
@@ -77,3 +81,62 @@ func extractClientIP(r *http.Request) (string, error) { | |||
} | |||
return ip, nil | |||
} | |||
|
|||
type middleware struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation borrowed from https://github.com/sethvargo/go-limiter/blob/main/httplimit/middleware.go with an extra tweak
return | ||
} | ||
|
||
// skip rate limiting checks if key is in allowlist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the additional change
cmd/api/main.go
Outdated
@@ -450,11 +450,14 @@ func createAPIServer( | |||
return nil, fmt.Errorf("parsing http ratelimiter interval: %s", err) | |||
} | |||
|
|||
allowList := strings.Split(httpConfig.AllowList, ",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this we can provide a list of addresses
30a70c5
to
b57fc75
Compare
Interval time.Duration | ||
MaxRPI uint64 | ||
Interval time.Duration | ||
AllowList []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cmd/api/config.go
Outdated
@@ -51,6 +51,7 @@ type HTTPConfig struct { | |||
|
|||
RateLimInterval string `default:"1s"` | |||
MaxRequestPerInterval uint64 `default:"10"` | |||
AllowList string `default:""` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a comment with an example of a list of IP addrs would be helpful here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Signed-off-by: Bruno Calza <[email protected]>
Signed-off-by: Bruno Calza <[email protected]>
43c91c0
to
fc7b33b
Compare
fc7b33b
to
22d6fe2
Compare
Signed-off-by: Bruno Calza <[email protected]>
22d6fe2
to
606165a
Compare
} | ||
|
||
// skip rate limiting checks if secret key is provided | ||
if key := r.Header.Get("Secret-Key"); key != "" && m.apiKey != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we name the header "Api-Key" instead of "Secret-Key" to make it consistent with the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm maybe i get your point now. this is the special "API key" that can bypass the checks. so it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Signed-off-by: Bruno Calza <[email protected]>
Summary
This PR adds a new config for the HTTP rate limiter:
ApiKey
. With that, authorized clients (clients that provide the same key) will not be rate limited.Context
Our Studio application is being rate limited fairly easily.
Implementation overview
Adds a new config to be configured via env. Makes a change to the rate limiter middleware to ignore the authorized clients