Skip to content

feat(nms): add rate limiting on a subset of endpoints#15404

Merged
lucasgonze merged 19 commits intomasterfrom
pierre/ratelimiting
Apr 16, 2024
Merged

feat(nms): add rate limiting on a subset of endpoints#15404
lucasgonze merged 19 commits intomasterfrom
pierre/ratelimiting

Conversation

@tmdzk
Copy link
Copy Markdown
Collaborator

@tmdzk tmdzk commented Apr 9, 2024

Summary

Adds rate limiting to a small subset of computationally expensive endpoints in NMS, outlined in #15348:

  • /user/login
  • /user/logout
  • /login/oidc/callback
  • /user/login/oidc/callback

Test Plan

Middleware is unit tested to ensure proper behavior, local testing was used to confirm the desired behavior.

On rate limited endpoints:

curl localhost:8081/user/login?[1-100]

After 100 request within 15 minutes for a given IP, a 429: too many request error code is returned by the endpoint for the offending IP, other endpoints still work as expected.

Other rate limited endpoints to test:

  • curl localhost:8081/user/logout
  • curl localhost:8081/login/oidc/callback
  • curl localhost:8081/user/login/oidc/callback

Additional Information

The configuration for the rate limit is located under: magma/nms/config/config.ts in RATE_LIMIT_CONFIG.

To be determined:

  • the exact configuration method, a simple node.js const is used at the moment, switching to an environment variable would allow for per deploy configuration
  • the base rate limiting config is set to 100 request within a 15min time window (this seems fairly conservative but I've got limited context on those endpoints)

pierre-roussel and others added 19 commits March 22, 2024 15:19
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
* fix(amf): Added statistics support for AMF

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added wrapper functions

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added nb_ue_connected and nb_pdu_session stats

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added nb_idle stats

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Addressed internal review comments

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added pb.go file

Signed-off-by: shashidhar-patil <[email protected]>

---------

Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: moinuddin khan <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>
@tmdzk tmdzk requested review from a team as code owners April 9, 2024 23:08
@tmdzk tmdzk requested review from andreilee and ardzoht April 9, 2024 23:08
@pull-request-size pull-request-size bot added the size/L Denotes a Pull Request that changes 100-499 lines. label Apr 9, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2024

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions github-actions bot added component: ci All updates on CI (Jenkins/CircleCi/Github Action) component: nms NMS-related issue labels Apr 9, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2024

✔️ The Semantic PR check ended with status success. See instructions on formatting your commit and pull request titles.

@tmdzk tmdzk changed the title Pierre/ratelimiting feat(nms): add rate limiting on a subset of endpoints Apr 11, 2024
@lucasgonze lucasgonze merged commit 2d2fb70 into master Apr 16, 2024
@lucasgonze lucasgonze deleted the pierre/ratelimiting branch April 16, 2024 20:53
brunohcfaria pushed a commit to brunohcfaria/magma that referenced this pull request Apr 22, 2024
* feat: add the rate limit library

Signed-off-by: Pierre Roussel <[email protected]>

* feat: add all the tested changes

Signed-off-by: Pierre Roussel <[email protected]>

* refactor: move the rate limit config to the config file

Signed-off-by: Pierre Roussel <[email protected]>

* refactor: move the middleware in the correct folder

Signed-off-by: Pierre Roussel <[email protected]>

* test: rate limit middleware

Signed-off-by: Pierre Roussel <[email protected]>

* fix: eslint warnings

Signed-off-by: Pierre Roussel <[email protected]>

* feat: add support for env rate limiting env variables

Signed-off-by: Pierre Roussel <[email protected]>

* fix: attempt to use a default config

Signed-off-by: Pierre Roussel <[email protected]>

* fix: linting

Signed-off-by: Pierre Roussel <[email protected]>

* fix(amf): Added statistics support for AMF (magma#14976)

* fix(amf): Added statistics support for AMF

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added wrapper functions

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added nb_ue_connected and nb_pdu_session stats

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added nb_idle stats

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Addressed internal review comments

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added pb.go file

Signed-off-by: shashidhar-patil <[email protected]>

---------

Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>

* fix(cwg): Add conntrack configuration (magma#15391)

Signed-off-by: moinuddin khan <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>

* nit: explicit rate limit response message

Signed-off-by: Pierre Roussel <[email protected]>

* fix: eslint

Signed-off-by: Pierre Roussel <[email protected]>

* fix: attempt to fix unit tests in CI

Signed-off-by: Pierre Roussel <[email protected]>

* fix: attempt fix from GH

Signed-off-by: Pierre Roussel <[email protected]>

* fix: eslint

Signed-off-by: Pierre Roussel <[email protected]>

* Readme change to trigger CI

Signed-off-by: tmdzk <[email protected]>

---------

Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: moinuddin khan <[email protected]>
Signed-off-by: tmdzk <[email protected]>
Co-authored-by: Pierre Roussel <[email protected]>
Co-authored-by: Shashidhar B Patil <[email protected]>
Co-authored-by: moinuddin1980 <[email protected]>
Co-authored-by: tmdzk <[email protected]>
brunohcfaria pushed a commit to brunohcfaria/magma that referenced this pull request Aug 2, 2024
* feat: add the rate limit library

Signed-off-by: Pierre Roussel <[email protected]>

* feat: add all the tested changes

Signed-off-by: Pierre Roussel <[email protected]>

* refactor: move the rate limit config to the config file

Signed-off-by: Pierre Roussel <[email protected]>

* refactor: move the middleware in the correct folder

Signed-off-by: Pierre Roussel <[email protected]>

* test: rate limit middleware

Signed-off-by: Pierre Roussel <[email protected]>

* fix: eslint warnings

Signed-off-by: Pierre Roussel <[email protected]>

* feat: add support for env rate limiting env variables

Signed-off-by: Pierre Roussel <[email protected]>

* fix: attempt to use a default config

Signed-off-by: Pierre Roussel <[email protected]>

* fix: linting

Signed-off-by: Pierre Roussel <[email protected]>

* fix(amf): Added statistics support for AMF (magma#14976)

* fix(amf): Added statistics support for AMF

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added wrapper functions

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added nb_ue_connected and nb_pdu_session stats

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added nb_idle stats

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Addressed internal review comments

Signed-off-by: shashidhar-patil <[email protected]>

* fix(amf): Added pb.go file

Signed-off-by: shashidhar-patil <[email protected]>

---------

Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>

* fix(cwg): Add conntrack configuration (magma#15391)

Signed-off-by: moinuddin khan <[email protected]>
Signed-off-by: Pierre Roussel <[email protected]>

* nit: explicit rate limit response message

Signed-off-by: Pierre Roussel <[email protected]>

* fix: eslint

Signed-off-by: Pierre Roussel <[email protected]>

* fix: attempt to fix unit tests in CI

Signed-off-by: Pierre Roussel <[email protected]>

* fix: attempt fix from GH

Signed-off-by: Pierre Roussel <[email protected]>

* fix: eslint

Signed-off-by: Pierre Roussel <[email protected]>

* Readme change to trigger CI

Signed-off-by: tmdzk <[email protected]>

---------

Signed-off-by: Pierre Roussel <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: shashidhar-patil <[email protected]>
Signed-off-by: moinuddin khan <[email protected]>
Signed-off-by: tmdzk <[email protected]>
Co-authored-by: Pierre Roussel <[email protected]>
Co-authored-by: Shashidhar B Patil <[email protected]>
Co-authored-by: moinuddin1980 <[email protected]>
Co-authored-by: tmdzk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: ci All updates on CI (Jenkins/CircleCi/Github Action) component: nms NMS-related issue size/L Denotes a Pull Request that changes 100-499 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants