你可以通过按 IP 地址和端口等选择器过滤请求来控制网络层级的流量。你还可以将网络策略与身份提供程序集成,以应用基于身份的过滤。
要创建新的网络策略:
-
在 Cloudflare 仪表板 ↗中,转到 Zero Trust > Traffic policies(流量策略) > Firewall policies(防火墙策略)。
-
在 Network(网络) 选项卡中,选择 Add a network policy(添加网络策略)。
-
为策略命名。
-
在 Traffic(流量) 下,构建一个逻辑表达式,定义您要允许或阻止的流量。
-
选择当流量匹配该逻辑表达式时要采取的 Action(操作)。例如,您可以使用 设备序列号 列表,以确保用户只有在从公司设备使用 Cloudflare One 客户端连接时才能访问应用程序:
选择器 运算符 值 逻辑 操作 SNI 域名 (SNI Domain) is internalapp.com且 (And) 阻止 (Block) 通过设备状态检测 (Passed Device Posture Checks) not in 设备序列号 (Device serial numbers) -
选择 Create policy(创建策略)。
-
创建具有以下权限的 API 令牌:
类型 项目 权限 Account Zero Trust Edit
2.(可选)配置您的 API 环境变量以包含您的 账户 ID 和 API 令牌。
3. 向 创建 Zero Trust Gateway 规则 端点发送 POST 请求。例如,您可以使用 设备序列号 列表,以确保用户只有在从公司设备使用 Cloudflare One 客户端连接时才能访问应用程序:
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Enforce device posture",
"description": "Ensure only devices in Zero Trust organization can connect to application",
"precedence": 0,
"enabled": true,
"action": "block",
"filters": [
"l4"
],
"traffic": "any(net.sni.domains[*] == \"internalapp.com\")",
"identity": "",
"device_posture": "not(any(device_posture.checks.passed[*] in {\"LIST_UUID\"}))"
}'{
"success": true,
"errors": [],
"messages": []
}API 将返回该策略的摘要以及您的请求结果。
有关详细信息,请参阅 网络策略。