Skip to content

coderd: tighten /login rate limiting #4432

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

Merged
merged 5 commits into from
Oct 20, 2022
Merged

coderd: tighten /login rate limiting #4432

merged 5 commits into from
Oct 20, 2022

Conversation

ammario
Copy link
Member

@ammario ammario commented Oct 8, 2022

  • Add ability for Owners to bypass rate limiting
  • Improve overall test coverage of rate limit middleware

@ammario ammario requested a review from Emyrk October 8, 2022 20:13
@ammario ammario enabled auto-merge (squash) October 8, 2022 20:13
@ammario ammario disabled auto-merge October 9, 2022 18:32
@ammario ammario enabled auto-merge (squash) October 9, 2022 18:32
@@ -24,6 +24,9 @@ const (
SessionCustomHeader = "Coder-Session-Token"
OAuth2StateKey = "oauth_state"
OAuth2RedirectKey = "oauth_redirect"

// nolint: gosec
BypassRatelimitHeader = "X-Coder-Bypass-Ratelimit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just allow owner to bypass implicitly without needing to set a header?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it may lead to bugs / misunderstandings with other features that rely on the rate limit. For example, a spinning script.

Also, we may not realize if the front end is sending too many requests since we usually test with Owner.

@ammario ammario requested review from kylecarbs and f0ssel October 16, 2022 17:02
return httprate.KeyByIP(r)
}

if r.Header.Get(codersdk.BypassRatelimitHeader) == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you care if the value of the header is false? Should you strconv.ParseBool?

Comment on lines +44 to +53
for _, role := range auth.Roles {
if role == rbac.RoleOwner() {
// HACK: use a random key each time to
// de facto disable rate limiting. The
// `httprate` package has no
// support for selectively changing the limit
// for particular keys.
return cryptorand.String(16)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to do this is add a resource for bypassing the rate limit. Then the FE can actually check if the capability exists, and we can give this to other roles as well.

ResourceRateLimitBypass = Object {
  Type: "bypass_rate_limit",
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last I checked Rego was taking 20%+ of test CPU time, so it seems counterproductive the DoS prevention goals of the rate limiter. I added a comment to that effect.

@ammario ammario disabled auto-merge October 20, 2022 16:50
@ammario ammario enabled auto-merge (squash) October 20, 2022 16:50
@ammario ammario merged commit 423ac04 into main Oct 20, 2022
@ammario ammario deleted the secure-auth branch October 20, 2022 17:01
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants