Skip to content

Commit 66667a3

Browse files
author
OpenShift Bot
authored
Merge pull request #10513 from JacobTanenbaum/BZ1368050
Merged by openshift-bot
2 parents fc60ef5 + 43c0285 commit 66667a3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

images/router/haproxy/conf/haproxy-config.template

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,23 @@ backend be_tcp_{{$cfgIdx}}
339339
timeout tunnel {{$value}}
340340
{{ end }}
341341
{{ end }}
342+
343+
{{ if matchPattern "true|TRUE" (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections") }}
344+
stick-table type ip size 100k expire 30s store conn_cur,conn_rate(3s),http_req_rate(10s)
345+
tcp-request content track-sc2 src
346+
{{ if (isInteger (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.concurrent-tcp")) }}
347+
tcp-request content reject if { src_conn_cur ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.concurrent-tcp" }} }
348+
{{ else }}
349+
# concurrent TCP connections not restricted
350+
{{ end }}
351+
352+
{{ if (isInteger (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-tcp")) }}
353+
tcp-request content reject if { src_conn_rate ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-tcp" }} }
354+
{{ else }}
355+
#TCP connection rate not restricted
356+
{{ end }}
357+
{{ end }}
358+
342359
hash-type consistent
343360
timeout check 5000ms
344361
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
@@ -386,6 +403,28 @@ backend be_secure_{{$cfgIdx}}
386403
{{ end }}
387404
{{ end }}
388405

406+
{{ if matchPattern "true|TRUE" (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections") }}
407+
stick-table type ip size 100k expire 30s store conn_cur,conn_rate(3s),http_req_rate(10s)
408+
tcp-request content track-sc2 src
409+
{{ if (isInteger (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.concurrent-tcp")) }}
410+
tcp-request content reject if { src_conn_cur ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.concurrent-tcp" }} }
411+
{{ else }}
412+
# concurrent TCP connections not restricted
413+
{{ end }}
414+
415+
{{ if (isInteger (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-tcp")) }}
416+
tcp-request content reject if { src_conn_rate ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-tcp" }} }
417+
{{ else }}
418+
#TCP connection rate not restricted
419+
{{ end }}
420+
421+
{{ if (isInteger (index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-http")) }}
422+
tcp-request content reject if { src_http_req_rate ge {{ index $cfg.Annotations "haproxy.router.openshift.io/rate-limit-connections.rate-http" }} }
423+
{{ else }}
424+
#HTTP request rate not restricted
425+
{{ end }}
426+
{{ end }}
427+
389428
timeout check 5000ms
390429
http-request set-header X-Forwarded-Host %[req.hdr(host)]
391430
http-request set-header X-Forwarded-Port %[dst_port]

0 commit comments

Comments
 (0)