Skip to content

Implement source IP RateLimit#1129

Merged
zirain merged 6 commits intoenvoyproxy:mainfrom
zirain:ratelimit/sourceip
Mar 14, 2023
Merged

Implement source IP RateLimit#1129
zirain merged 6 commits intoenvoyproxy:mainfrom
zirain:ratelimit/sourceip

Conversation

@zirain
Copy link
Copy Markdown
Member

@zirain zirain commented Mar 11, 2023

fixes: #852

@zirain zirain requested a review from a team as a code owner March 11, 2023 08:23
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 11, 2023

Codecov Report

Merging #1129 (8dc5604) into main (27d14f8) will increase coverage by 0.01%.
The diff coverage is 69.23%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #1129      +/-   ##
==========================================
+ Coverage   62.55%   62.57%   +0.01%     
==========================================
  Files          72       72              
  Lines        9596     9646      +50     
==========================================
+ Hits         6003     6036      +33     
- Misses       3179     3192      +13     
- Partials      414      418       +4     
Impacted Files Coverage Δ
internal/ir/xds.go 72.42% <0.00%> (-0.49%) ⬇️
internal/ir/zz_generated.deepcopy.go 12.29% <0.00%> (-0.11%) ⬇️
internal/gatewayapi/filters.go 79.07% <57.14%> (-0.51%) ⬇️
internal/xds/translator/ratelimit.go 92.11% <90.32%> (-0.34%) ⬇️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Copy Markdown
Contributor

@arkodg arkodg Mar 13, 2023

Choose a reason for hiding this comment

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

from the spec it looks like the masked remote address is being sent to RLS https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#config-route-v3-ratelimit-action-maskedremoteaddress
how are individual IPs getting rate limited in a unique/distinct way ?

Copy link
Copy Markdown
Contributor

@arkodg arkodg Mar 13, 2023

Choose a reason for hiding this comment

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

this boils down to a top level API question, when a user specifies 192.168.1.0/24and a limit of 2 requests/hour, does this mean 192.168.1.1 and 192.168.1.2 are treated as the same client so limit is reached when 192.168.1.1 sends 1 request and 192.168.1.2 sends another request within the same hour ?
Or
is 192.168.1.1 and 192.168.1.2 allowed 2 requests each ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

in that case you should use 192.168.1.1/32 and 192.168.1.1/32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for clarifying , we should clarify this in the API

// SourceIP is the IP CIDR that represents the range of Source IP Addresses of the client.
i.e. All IP Addresses within the specified CIDR are treated as a single client selector and share the rate limit value

In the future, we could add a Distinct match type so each IP is treated in a unique way

Copy link
Copy Markdown
Member Author

@zirain zirain Mar 14, 2023

Choose a reason for hiding this comment

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

MaskedRemoteAddress is usefull for both Global and Local ratelimit.
In istio, we want to use local ratelimit between pod and pod, pod ip is short live, marked_remote_address will be very useful in this scenario.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

raised #1145 to clarify docs

@zirain zirain force-pushed the ratelimit/sourceip branch from b1ce0e8 to c491704 Compare March 14, 2023 01:18
hejianpeng added 4 commits March 14, 2023 09:55
Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
@zirain zirain force-pushed the ratelimit/sourceip branch from c491704 to 4a1c512 Compare March 14, 2023 01:59
@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Mar 14, 2023

hey @zirain has this been tested end to end ? would be great to track it with a GH issue so we track docs completion for this feature

Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
@zirain
Copy link
Copy Markdown
Member Author

zirain commented Mar 14, 2023

open #1144

Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
Copy link
Copy Markdown
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for building out this useful feature !

Copy link
Copy Markdown
Member

@Xunzhuo Xunzhuo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Can you update the ratelimit doc to describe this?

@zirain zirain merged commit d8fa756 into envoyproxy:main Mar 14, 2023
@zirain zirain deleted the ratelimit/sourceip branch March 14, 2023 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ratelimit based on IP Subnet

4 participants