-
Notifications
You must be signed in to change notification settings - Fork 84
Rate limiting via socket #899
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -319,6 +319,14 @@ global | |||||
| <%- if backend_match_http_protocol && backends.length == 2 -%> | ||||||
| set-var proc.h2_alpn_tag str(h2) | ||||||
| <%- end -%> | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.table_size", "ha_proxy.connections_rate_limit.window_size") do -%> | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.connections") do |connections| -%> | ||||||
| set-var proc.conn_rate_limit int(<%= connections %>) | ||||||
| <%- end -%> | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.block") do |block| -%> | ||||||
| set-var proc.conn_rate_limit_enabled bool(<%= block ? 1 : 0 %>) | ||||||
| <%- end -%> | ||||||
| <%- end -%> | ||||||
| <%- if p("ha_proxy.always_allow_body_http10") %> | ||||||
| h1-accept-payload-with-any-method | ||||||
| <%- end %> | ||||||
|
|
@@ -432,11 +440,7 @@ frontend http-in | |||||
| tcp-request connection reject if layer4_block | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.table_size", "ha_proxy.connections_rate_limit.window_size") do -%> | ||||||
| tcp-request connection track-sc0 src table st_tcp_conn_rate | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.block", "ha_proxy.connections_rate_limit.connections") do |block, connections| -%> | ||||||
| <%-if block -%> | ||||||
| tcp-request connection reject if { sc_conn_rate(0) gt <%= connections %> } | ||||||
| <%- end -%> | ||||||
| <%- end -%> | ||||||
| tcp-request connection reject if { var(proc.conn_rate_limit_enabled) -m bool } { sc_conn_rate(0),sub(proc.conn_rate_limit) gt 0 } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we should do this, even though it's a breaking change. |
||||||
| <%- end -%> | ||||||
| <%- if_p("ha_proxy.requests_rate_limit.table_size", "ha_proxy.requests_rate_limit.window_size") do -%> | ||||||
| http-request track-sc1 src table st_http_req_rate | ||||||
|
|
@@ -566,11 +570,7 @@ frontend https-in | |||||
| tcp-request connection reject if layer4_block | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.table_size", "ha_proxy.connections_rate_limit.window_size") do -%> | ||||||
| tcp-request connection track-sc0 src table st_tcp_conn_rate | ||||||
| <%- if_p("ha_proxy.connections_rate_limit.block", "ha_proxy.connections_rate_limit.connections") do |block, connections| -%> | ||||||
| <%-if block -%> | ||||||
| tcp-request connection reject if { sc_conn_rate(0) gt <%= connections %> } | ||||||
| <%- end -%> | ||||||
| <%- end -%> | ||||||
| tcp-request connection reject if { var(proc.conn_rate_limit_enabled) -m bool } { sc_conn_rate(0),sub(proc.conn_rate_limit) gt 0 } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we substract instead of comparing directly? Did you test that this is more performant?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I tried with comparison first but turns our haproxy comparator expects static integer on the right, not variables reference in any form. Subtraction approach is a way to compare against dynamic variables. |
||||||
| <%- end -%> | ||||||
| <%- if_p("ha_proxy.requests_rate_limit.table_size", "ha_proxy.requests_rate_limit.window_size") do -%> | ||||||
| http-request track-sc1 src table st_http_req_rate | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you investigate what the drawbacks of experimental-mode are? Do we even still require this? How long will this stay experimental?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set var is only available in experimental mode (since HAProxy 2.4, HAProxy Enterprise 2.4r1). Unfortunately, this operation is still in development and may change in the future (see HAProxy documentation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is by design from haproxy version until now, this commands are still in development mode and may change later on. see: https://www.haproxy.com/documentation/haproxy-runtime-api/reference/set-var/ and https://www.haproxy.com/documentation/haproxy-runtime-api/reference/experimental-mode/
Drawback: Its per-connection only - doesn't persist across sessions. experimental-mode on is required because set var is classified as an experimental/unstable feature in HAProxy's runtime API