Skip to content

Tiered rate limits with variables #7884

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Conversation

pdabelf5
Copy link
Collaborator

@pdabelf5 pdabelf5 commented Jun 12, 2025

Proposed changes

Add the ability to add a condition to the rate limit Policy to allow users to rate limit on an NGINX variable. This can allow users to rate limit based on a variable containing a certain value. For example, rate limit all POST requests to 1 r/s, or if an API Key client name matches a specific regex.

Examples

apiVersion: k8s.nginx.org/v1
kind: Policy
metadata:
  name: rate-limit-premium
spec:
  rateLimit:
    rate: 1r/s
    key: ${apikey_client_name}
    zoneSize: 10M
    condition:
      variables:
        - name: $apikey_client_name
          match: "~^.*-premium$"
---
apiVersion: k8s.nginx.org/v1
kind: Policy
metadata:
  name: rate-limit-basic
spec:
  rateLimit:
    rate: 1r/s
    key: ${apikey_client_name}
    zoneSize: 10M
    condition:
      variables:
        - name: $apikey_client_name
          match: "~^.*-basic$"
      default: true

Closes #7868

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@pdabelf5 pdabelf5 self-assigned this Jun 12, 2025
@github-actions github-actions bot added enhancement Pull requests for new features/feature enhancements documentation Pull requests/issues for documentation go Pull requests that update Go code python Pull requests that update Python code tests Pull requests that update tests labels Jun 12, 2025
Copy link
Contributor

Deploy Preview will be available once build job completes!

Name Link
😎 Deploy Preview https://frontdoor-test-docs.nginx.com/previews/nginx-ingress-controller/7884/

Copy link

codecov bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 97.29730% with 4 lines in your changes missing coverage. Please review.

Project coverage is 52.92%. Comparing base (5f037b9) to head (2a1009a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/apis/configuration/validation/common.go 0.00% 2 Missing ⚠️
pkg/apis/configuration/validation/policy.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7884      +/-   ##
==========================================
+ Coverage   52.82%   52.92%   +0.10%     
==========================================
  Files          90       90              
  Lines       21671    21732      +61     
==========================================
+ Hits        11447    11502      +55     
- Misses       9747     9751       +4     
- Partials      477      479       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pdabelf5 pdabelf5 marked this pull request as ready for review June 13, 2025 10:51
@pdabelf5 pdabelf5 requested review from a team as code owners June 13, 2025 10:51
AlexFenlon
AlexFenlon previously approved these changes Jun 16, 2025
vepatel
vepatel previously approved these changes Jun 17, 2025
Copy link
Contributor

@ADubhlaoich ADubhlaoich left a comment

Choose a reason for hiding this comment

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

I've given edit suggestions for a lot of style errors in the API key README.

All of the feedback applies to the request method README, too.

  • Incorrect product name (We never say just 'Ingress Controller')
  • Unnecessary nesting
  • Erroneous list numbering (Enumeration doesn't work in plain markdown)
  • Title Case instead of sentence case
  • Numbered headings

@pdabelf5 pdabelf5 dismissed stale reviews from vepatel and AlexFenlon via a01acf5 June 19, 2025 09:51
@pdabelf5 pdabelf5 force-pushed the feat/rate-limit-variables branch 3 times, most recently from a3c19f5 to 6165029 Compare June 19, 2025 09:57
@pdabelf5 pdabelf5 force-pushed the feat/rate-limit-variables branch from 6165029 to 2a1009a Compare June 19, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Pull requests/issues for documentation enhancement Pull requests for new features/feature enhancements go Pull requests that update Go code python Pull requests that update Python code tests Pull requests that update tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation - Rate Limit with API Key
5 participants