|
52 | 52 | # Lower the amount of space we reserve for header rewriting
|
53 | 53 | tune.maxrewrite 1024
|
54 | 54 |
|
55 |
| - |
56 | 55 | defaults
|
57 | 56 | log global
|
58 | 57 |
|
@@ -117,6 +116,24 @@ frontend main
|
117 | 116 | bind :::80
|
118 | 117 | bind 127.0.0.1:19001 # This is our TLS socket.
|
119 | 118 |
|
| 119 | + # Define a stick table for all services |
| 120 | + stick-table type ipv6 size 100k expire 30s store http_req_rate(10s) |
| 121 | + # Track all requests using a single counter |
| 122 | + # We could use the 3 available (sc0,1,2) to maybe tier requests |
| 123 | + # into say <=100, 101-500, >= 501 if we needed to? |
| 124 | + http-request track-sc0 src |
| 125 | + # then create the ACL for services in haproxy.sls that have a 'rate_limit' key, |
| 126 | + # constrained to the host header using the domain key in haproxy.sls |
| 127 | + # then adds a rule to deny via HTTP 429 if the respective ACL is matched and the stick table http request rate |
| 128 | + # is higher than the 'rate_limit' from haproxy.sls pillar date |
| 129 | + {%- for service, config in haproxy.services.items() %} |
| 130 | + {%- if config.get('rate_limit') %} |
| 131 | + # Rate limit config for {{ service }} |
| 132 | + acl is_{{ service }} hdr(host) -i {% for domain in config.domains %}{{ domain }} {% endfor %} |
| 133 | + http-request deny deny_status 429 if is_{{ service }} { sc_http_req_rate(0) gt {{ config.rate_limit }} } |
| 134 | + {%- endif %} |
| 135 | + {%- endfor %} |
| 136 | + |
120 | 137 | # Custom logging format, this is the same as the normal "httplog" in
|
121 | 138 | # HAProxy except information about the TLS connection is included.
|
122 | 139 | log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %sslv/%sslc\ %ST\ %B\ %CC\ %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ %{+Q}r
|
|
0 commit comments