HAProxy 速率限制 - 禁止滥用者 30 分钟

Ton*_*ony 6 haproxy rate-limiting

我有以下配置,它适用于速率限制连接。如果滥用者通过身份验证并且他每分钟访问定义的正则表达式位置超过 30 次,则会启动速率限制并将他转发到 rate_limiting 后端,在那里他收到错误消息:

frontend http_in

bind xx.xx.xx.xx:80
mode http
default_backend backend_nodes
tcp-request inspect-delay 5s
acl location_request path_reg ^/(.*)/(.*)/
acl too_many_requests sc0_gpc0_rate(context) ge 30
acl mark_seen sc0_inc_gpc0 gt 0
stick-table type string size 100k store gpc0_rate(60s)
tcp-request content track-sc0 cookie(authValidation) if location_request
use_backend rate_limiting if mark_seen too_many_requests


backend backend_nodes

mode    http
balance roundrobin
option  http-server-close
server  srv1 192.168.0.1:80 weight 5
server  srv2 192.168.0.2:80 weight 5

backend rate_limiting

mode http
timeout tarpit 2s
errorfile 500 /etc/haproxy/errorfiles/429.http
http-request tarpit
Run Code Online (Sandbox Code Playgroud)

此配置确保滥用者每分钟不能发出超过 30 个请求,但是,它不会完全阻止他超过一分钟。现在,我接下来想要实现的是在施虐者受到速率限制后完全阻止他 1 小时,但据我的研究表明,我什至不知道这个额外的步骤是否可能。

小智 5

安迪,诀窍是添加另一个仅用于额外棒表的后端。每个后端只能有一个棒表 - 但是你可以在任何前端/后端使用它们......所以我只添加一个名为 Abuse 的,然后你可以将其用作任何后端的全球 60 分钟禁令......你会需要改变我的例子,但尝试这样的事情:

# ABUSE SECTION works with http mode dependent on src ip
tcp-request content reject if { src_get_gpc0(Abuse) gt 0 }
acl abuse src_http_req_rate(Abuse) ge 10
acl flag_abuser src_inc_gpc0(Abuse) ge 0
acl scanner src_http_err_rate(Abuse) ge 10

# Returns a 403 to the abuser and flags for tcp-reject next time
http-request deny if abuse flag_abuser
http-request deny if scanner flag_abuser

backend Abuse
stick-table type ip size 1m expire 60m store conn_rate(3s),conn_cur,gpc0,http_req_rate(10s),http_err_rate(20s)
Run Code Online (Sandbox Code Playgroud)