Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion images/router/haproxy/conf/haproxy-config.template
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,9 @@ backend {{ genBackendNamePrefix $cfg.TLSTermination }}:{{ $cfgIdx }}
{{- end }}

{{- if (isInteger (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-http")) }}
tcp-request content reject if { src_http_req_rate ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-http" }} }
# Return HTTP 429 when the per-source HTTP request rate limit is exceeded (RFE-2924).
# TCP connection limits above still use tcp-request reject because no HTTP response is possible there.
http-request deny deny_status 429 if { src_http_req_rate ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-http" }} }
{{- else }}
#HTTP request rate not restricted
{{- end }}
Expand Down
41 changes: 41 additions & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,47 @@ func TestConfigTemplate(t *testing.T) {
},
},
},
"HTTP rate limit returns 429": {
mustCreateWithConfig{
mustCreateRoute: mustCreateRoute{
name: "rate-limit-http",
host: "rate-limit-http.example.com",
path: "",
time: start,
annotations: map[string]string{
"haproxy.router.openshift.io/rate-limit-connections": "true",
"haproxy.router.openshift.io/rate-limit-connections.rate-http": "40",
},
tlsTermination: routev1.TLSTerminationEdge,
},
mustMatchConfig: mustMatchConfig{
section: "backend",
sectionName: edgeBackendName(h.namespace, "rate-limit-http"),
attribute: "http-request",
value: `deny deny_status 429 if { src_http_req_rate ge 40 }`,
},
},
},
"HTTP rate limit 429 on insecure backend": {
mustCreateWithConfig{
mustCreateRoute: mustCreateRoute{
name: "rate-limit-http-insecure",
host: "rate-limit-http-insecure.example.com",
path: "",
time: start,
annotations: map[string]string{
"haproxy.router.openshift.io/rate-limit-connections": "true",
"haproxy.router.openshift.io/rate-limit-connections.rate-http": "10",
},
},
mustMatchConfig: mustMatchConfig{
section: "backend",
sectionName: insecureBackendName(h.namespace, "rate-limit-http-insecure"),
attribute: "http-request",
value: `deny deny_status 429 if { src_http_req_rate ge 10 }`,
},
},
},
}

defer cleanUpRoutes(t)
Expand Down