haproxy在ACL表达式中缺少获取方法



我在代理中使用了这些条件

use_backend test if { path_beg -i /test/ } { { ssl_fc_has_crt } || { src 10.0.0.25 }  || { src 10.1.0.152 }  || { src 10.0.2.41 }  || { src 10.0.0.158}  || { src 64.32.12.252 }  || { src 35.43.19.101 } || { src 80.240.254.1 } || { src 82.10.80.7 } }

但是我看到这个错误:

error detected while parsing switching rule : missing fetch method in ACL expression '{'.

文档显示{ }可以对acl进行分组,但没有详细说明:

A condition is formed as a disjunctive form:
[!]acl1 [!]acl2 ... [!]acln  { or [!]acl1 [!]acl2 ... [!]acln } ...

所以它可能根本就不是分组。我看到的所有{}示例都是针对匿名acl的。你想在一个条件下结合AND和OR, haproxy不是很有用,但这里有一些应该工作:

acl allowed_to_test_site src 10.0.0.25 10.0.0.24 10.1.0.152 10.0.2.41 10.0.0.158 64.32.12.252 35.43.19.101 80.240.254.1 82.10.80.7
acl allowed_to_test_site ssl_fc_has_crt
use_backend backend-sonar if { path_beg -i /test/ } allowed_to_test_site                                                                                                           

这里有几点需要说明:

  1. src IP1 || src IP2可以声明为acl ip src IP1 IP2,以此类推。该列表工作于多个OR
  2. 多次声明ACL再次作为多个OR工作
    文档说:
acl <aclname> <criterion> [flags] [operator] <value> ...
Declare or complete an access list.

可以使用一些更明确的解释3.AND是隐式的

这样我们就得到了(path_beg -i /test/) AND ( ssl_fc_has_crt OR src matches one of the IPs)的逻辑
也许有一天haproxy会有更好的语法。

最新更新