Skip to content
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

beater: even more refactoring #5502

Merged
merged 3 commits into from
Jun 21, 2021
Merged

Conversation

axw
Copy link
Member

@axw axw commented Jun 21, 2021

Motivation/summary

  • rate limiting middleware is now installed for both RUM and backend agent APIs, but only applies for anonymous clients (currently only RUM)
  • rate limiting middleware now performs an initial Allow check at the request level, for consistent request rate limiting of those endpoints that are rate limited. Handlers only need to perform route-specific rate limiting, such as per-event rate limiting.
  • agent config now restricts "insecure" (RUM) agents on the basis that they are anonymous, rather than being RUM specifically. The list of insecure agent names (those allowed for anonymous auth) is now passed in to support making this configurable later.

How to test these changes

The only functional change is the response body for rate-limited RUM intake requests has changed slightly. This is not a problem in practice as the RUM agent does not parse the response.

Related issues

Part of #5347

- rate limiting middleware is now installed for
  both RUM and backend agent APIs, but only applies
  for anonymous clients (currently only RUM)
- rate limiting middleware now performs an initial
  Allow check at the request level, for consistent
  request rate limiting of those endpoints that are
  rate limited
- agent config now restricts "insecure" (RUM) agents
  on the basis that they are anonymous, rather than
  being RUM specifically. The list of insecure agent
  names (those allowed for anonymous auth) is now
  passed in
@apmmachine
Copy link
Contributor

apmmachine commented Jun 21, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #5502 updated

  • Start Time: 2021-06-21T08:15:01.368+0000

  • Duration: 38 min 4 sec

  • Commit: 296f2ed

Test stats 🧪

Test Results
Failed 0
Passed 6122
Skipped 120
Total 6242

Trends 🧪

Image of Build Times

Image of Tests

@axw axw added the v7.14.0 label Jun 21, 2021
@axw axw marked this pull request as ready for review June 21, 2021 08:55
@axw axw requested a review from a team June 21, 2021 08:55
middleware.CORSMiddleware(cfg.RumConfig.AllowOrigins, cfg.RumConfig.AllowHeaders),
middleware.AnonymousAuthorizationMiddleware(),
middleware.KillSwitchMiddleware(cfg.RumConfig.Enabled, msg),
middleware.AnonymousRateLimitMiddleware(ratelimitStore),
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the order wrong now for Authorization and RateLimiting middleware? (the AnonymousRateLimitMiddleware checks c.AuthResult.Anonymous which will only be set afterwards)

Copy link
Member Author

Choose a reason for hiding this comment

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

middleware.Wrap calls the Middleware functions in reverse order:

func Wrap(h request.Handler, m ...Middleware) (request.Handler, error) {

So Wrap(handler, Auth, RateLimit) leads to Auth(RateLimit(handler))

i.e. the first in the chain is outermost, last is innermost after the wrapped handler

Copy link
Contributor

Choose a reason for hiding this comment

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

right, I still get confused with the KillSwitch not being the first middleware in the chain; looks good then

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 found it pretty confusing too. Probably something to come back and clarify later.

@axw axw merged commit d577ec8 into elastic:master Jun 21, 2021
mergify bot pushed a commit that referenced this pull request Jun 21, 2021
* beater: even more refactoring

- rate limiting middleware is now installed for
  both RUM and backend agent APIs, but only applies
  for anonymous clients (currently only RUM)
- rate limiting middleware now performs an initial
  Allow check at the request level, for consistent
  request rate limiting of those endpoints that are
  rate limited
- agent config now restricts "insecure" (RUM) agents
  on the basis that they are anonymous, rather than
  being RUM specifically. The list of insecure agent
  names (those allowed for anonymous auth) is now
  passed in

* make gofmt

* beater/api/profile: remove unused field

(cherry picked from commit d577ec8)
axw added a commit that referenced this pull request Jun 22, 2021
* beater: even more refactoring

- rate limiting middleware is now installed for
  both RUM and backend agent APIs, but only applies
  for anonymous clients (currently only RUM)
- rate limiting middleware now performs an initial
  Allow check at the request level, for consistent
  request rate limiting of those endpoints that are
  rate limited
- agent config now restricts "insecure" (RUM) agents
  on the basis that they are anonymous, rather than
  being RUM specifically. The list of insecure agent
  names (those allowed for anonymous auth) is now
  passed in

* make gofmt

* beater/api/profile: remove unused field

(cherry picked from commit d577ec8)

Co-authored-by: Andrew Wilkins <[email protected]>
stuartnelson3 pushed a commit to stuartnelson3/apm-server that referenced this pull request Jun 22, 2021
* beater: even more refactoring

- rate limiting middleware is now installed for
  both RUM and backend agent APIs, but only applies
  for anonymous clients (currently only RUM)
- rate limiting middleware now performs an initial
  Allow check at the request level, for consistent
  request rate limiting of those endpoints that are
  rate limited
- agent config now restricts "insecure" (RUM) agents
  on the basis that they are anonymous, rather than
  being RUM specifically. The list of insecure agent
  names (those allowed for anonymous auth) is now
  passed in

* make gofmt

* beater/api/profile: remove unused field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants