Skip to content

Conversation

@bjee19
Copy link
Contributor

@bjee19 bjee19 commented Nov 27, 2025

Proposed changes

Problem: A design is needed for the RateLimitPolicy.

Solution: Create an implementable RateLimitPolicy enhancement proposal.

Closes #4059

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

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.


@github-actions github-actions bot added the documentation Improvements or additions to documentation label Nov 27, 2025
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.11%. Comparing base (775388b) to head (2d0a081).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4346   +/-   ##
=======================================
  Coverage   86.10%   86.11%           
=======================================
  Files         132      132           
  Lines       14342    14342           
  Branches       35       35           
=======================================
+ Hits        12349    12350    +1     
+ Misses       1790     1789    -1     
  Partials      203      203           

☔ 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.


### Versioning and Installation

The version of the `RateLimitPolicy` API will be `v1alpha1`.
Copy link
Contributor

Choose a reason for hiding this comment

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

do we always aim to alpha1 and then duplicate for alpha2?


Downsides:

- Harder to reason about capacity of fleet, especially when auto-scaling is enabled
Copy link
Contributor

Choose a reason for hiding this comment

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

at least now i know a bit about fleets and zones in nginx but actually from the text below i'm not sure i can understand the difference. I understoon at first that zone is the area of shared memory, but below i see ratelimit is set per zone


- When there is a a Route with a `RateLimitPolicy` attached that sets a rate limit zone named `zone_one` with `rate = 3r/s` and `zoneSize = 5m`, and a Gateway that also has a `RateLimitPolicy` attached that sets a rate limit zone named `zone_one` with `rate = 5/rs` and `zoneSize = 100m`, the effective policy will choose the rate limit zone settings from the Gateway.
- When there is a Route with a `RateLimitPolicy` attached that sets a rate limit rule with `zoneName = default_zone_five` and `burst=5`, and a Gateway that also has a `RateLimitPolicy` attached that sets a rate limit rule with `zoneName = default_zone_three` and `burst = 2` and `noDelay = true`, the effective policy will choose the rate limit rule settings from the HTTPRoute.
- A Route without a policy attached will inherit all settings from the Gateway's policy.
Copy link
Contributor

Choose a reason for hiding this comment

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

will be possible to set ignorance like: ratelimit: off for some route to ignore inherited as well?

Comment on lines +214 to +221
// RateLimit contains settings for Rate Limitting.
type RateLimit struct {
// Local defines the local rate limit rules for this policy.
Local *LocalRateLimit `json:"local,omitempty"`

// Global defines the global rate limit rules for this policy.
Global *GlobalRateLimit `json:"global,omitempty"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a user required to set either one of Local or Global rate limiting?

For example, if I have a spec like this, will this be valid?

apiVersion: gateway.nginx.org/v1alpha1
kind: RateLimitPolicy
metadata:
  name: example-rl-policy
  namespace: default
spec:
  targetRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: example-gateway
  rateLimit:
  # Neither local or global is set

Comment on lines +264 to +267
// ZoneName is the name of the zone.
//
// Directive: https://nginx.org/en/docs/http/ngx_http_limit_req_module.html#limit_req_zone
ZoneName *string `json:"zoneName"`
Copy link
Contributor

@shaun-nx shaun-nx Nov 27, 2025

Choose a reason for hiding this comment

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

Is ZoneName optional?
From what I understand, using *string instead of string means it's an optional field?

I see this for a few other fields as well. Just want to make sure I understand how the API is structured.

Comment on lines +327 to +342
// RateLimitCondition represents a condition to determine if the request should be rate limited.
type RateLimitCondition struct {
// JWT defines a JWT condition to determine if the request should be rate limited.
//
// +optional
JWT *RateLimitJWTCondition `json:"jwt,omitempty"`
// Variable defines a Variable condition to determine if the request should be rate limited.
//
// +optional
Variable *RateLimitVariableCondition `json:"variable,omitempty"`
// Default sets the rate limit in this policy to be the default if no conditions are met. In a group of policies with the same condition,
// only one policy can be the default.
//
// +optional
Default *bool `json:"default,omitempty"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will a user be allowed to set multiple Rate Limiting conditions?

Comment on lines +135 to +137
### JWT Claim Condition

JWT Claim Condition on a RateLimitPolicy would define a condition for a rate limit by JWT claim. For example, a condition could be on the claim `user_details.level` and the match could be `premium`, meaning this RateLimitPolicy would only apply to requests with a JWT claim `user_details.level` with a value `premium`. The following JWT payload would match the condition:
Copy link
Contributor

Choose a reason for hiding this comment

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

Version 5.0.0 of NIC introduced Rate Limiting with JWT Claims.
The PR for that is here: nginx/kubernetes-ingress#7175

It's very much worth studying this PR. From what I remember there were quite a few edge cases that NIC encountered when implementing this. I don't yet know if we will hit the same problems. Mostly want to bring this to everyone's attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

Design Rate Limiting

4 participants