我有以下configuration,适用于速率限制连接。 如果滥用者被authentication并且他每分钟访问定义的正则expression式位置超过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
这种configuration可以确保施虐者每分钟不能超过30个请求,但是,一分钟内不会完全阻止他。 现在我接下来要完成的是在受到限制的情况下将施虐者完全阻止了一个小时,但就我的研究显示,我甚至不知道这个额外的步骤是否可能。
安迪,诀窍是添加另一个后端,你只用于额外的棍子表。 每个后端只能有一个粘贴表 – 但是你可以在任何前端/后端使用它们…所以我只需添加一个叫做“滥用”的东西,然后你可以用它作为全局的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)