跳转到内容
搜索文档

Gateway 策略表达式

最后更新 查看 MarkdownAgent 设置

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 策略中阻止域名

dns.fqdn == "example.com"

在 HTTP 策略中阻止多个内容类别

any(http.request.uri.content_category[*] in {17 85 102})

允许来自特定用户组的流量

any(identity.groups[*].name in {"Engineering"})

在网络 (Network) 策略中阻止发往特定 IP 范围的流量

net.dst.ip in {10.0.0.0/8}

组合身份和流量条件

http.request.host == "internal.example.com" and identity.email matches ".*@company.com"

Gateway 与 Ruleset 引擎

下表总结了 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 语言 流量策略

相关资源

这篇文档对您有帮助吗?