Gateway 策略使用基于 wirefilter 的表达式语言来将流量与选择器(标准)进行匹配。该语法与 WAF、Rules 机制和其他 Cloudflare 产品使用的 Rules 语言相似但又有所不同。有关差异的详细信息,请参阅 Gateway 与 Ruleset 引擎的区别。
Gateway 表达式遵循以下模式:
<field> <operator> <value>例如:
dns.fqdn == "example.com"
http.request.host == "api.example.com"
identity.email == "[email protected]"Gateway 支持以下运算符:
| 运算符 | 名称 | 示例 |
|---|---|---|
== |
等于 | dns.fqdn == "example.com" |
!= |
不等于 | http.request.host != "blocked.com" |
in |
值在集合中 | net.dst.port in {80 443} |
matches |
匹配正则表达式 | http.request.host matches ".*\\.example\\.com" |
> |
大于 | http.upload.file.size > 10 |
>= |
大于或等于 | http.download.file.size >= 100 |
< |
小于 | http.upload.file.size < 50 |
<= |
小于或等于 | http.download.file.size <= 200 |
使用逻辑运算符组合多个条件:
| 运算符 | 名称 | 示例 |
|---|---|---|
and |
逻辑与 | dns.fqdn == "example.com" and identity.email == "[email protected]" |
or |
逻辑或 | net.dst.port == 80 or net.dst.port == 443 |
not |
逻辑非 | not(identity.email == "[email protected]") |
某些 Gateway 字段返回数组(多个值)。使用 any() 函数匹配数组中是否有任何元素满足条件:
any(http.request.uri.content_category[*] in {17 85 102})any(identity.groups[*].name in {"Engineering" "Security"})any(http.request.domains[*] == "example.com")[*] 表示法表示函数应评估数组中的所有元素。
您可以在表达式中使用列表的 UUID 引用列表:
http.request.host in $<LIST_UUID>any(http.request.domains[*] in $<LIST_UUID>)要查找列表的 UUID,请在 Zero Trust 中转到 My Team(我的团队) > Lists(列表) 并选择该列表。UUID 将显示在浏览器 URL 中。
每种 Gateway 策略类型都有自己的一套可用字段。下表显示了每种策略类型所使用的字段前缀:
| 策略类型 | 字段前缀 | 示例字段 |
|---|---|---|
| DNS | dns. |
dns.fqdn, dns.content_category, dns.src_ip |
| HTTP | http. |
http.request.host, http.request.uri, http.request.domains |
| Network | net. |
net.dst.ip, net.dst.port, net.src.ip |
| Identity | identity. |
identity.email, identity.groups, identity.name |
| Device posture | device_posture. |
device_posture.checks.passed |
有关每种策略类型可用字段的完整列表,请参阅本页面顶部链接的选择器文档。
dns.fqdn == "example.com"any(http.request.uri.content_category[*] in {17 85 102})any(identity.groups[*].name in {"Engineering"})net.dst.ip in {10.0.0.0/8}http.request.host == "internal.example.com" and identity.email matches ".*@company.com"下表总结了 Ruleset 引擎支持的 Rules 语言与 Gateway 策略表达式之间的主要区别:
| Ruleset 引擎 | Gateway | |
|---|---|---|
| 产品 | WAF、变换规则、缓存规则、配置规则 | DNS、HTTP、Network、Egress、解析器 (Resolver) 策略 |
| 字段示例 | http.request.uri.path, cf.bot_management.score, ip.src |
dns.fqdn, http.request.host, identity.email |
| 身份字段 | 不可用 | 可用(例如 identity.email, identity.groups) |
| DNS 字段 | 不可用 | 可用(例如 dns.fqdn, dns.content_category) |
| 文档 | Rules 语言 | 流量策略 |