Feature availability
| Client modes | Zero Trust plans ↗ |
|---|---|
|
所有计划 |
| 系统 | 可用性 | 最低 WARP 版本 |
|---|---|---|
| Windows | ✅ | 2025.6.1400.0 |
| macOS | ❌ | |
| Linux | ❌ | |
| iOS | ❌ | |
| Android | ❌ | |
| ChromeOS | ❌ |
借助 Cloudflare Zero Trust,您可以使用本地 Active Directory(或类似)服务器来验证远程用户的 Windows 登录凭据。在用户首次输入其 Windows 登录信息之前,Cloudflare One Client(前身为 WARP)将使用服务令牌建立连接。此初始连接不与用户身份关联。用户完成 Windows 登录后,Cloudflare One Client 将切换到基于身份的会话,并将用户注册应用于未来的所有登录。
- Active Directory 资源已连接到 Cloudflare。
-
在 Cloudflare 仪表板 ↗中,前往 Zero Trust > Access controls(访问控制) > Service credentials(服务凭据) > Service Tokens(服务令牌)。
-
选择 Create Service Token(创建服务令牌)。
-
为服务令牌命名。该名称便于您在日志中识别与令牌相关的事件,并可单独撤销令牌。
-
选择 Service Token Duration(服务令牌有效期)。这将设置令牌的到期日期。
-
选择 Generate token(生成令牌)。您将看到为服务令牌生成的 Client ID 和 Client Secret,以及各自的请求头。
-
复制 Client Secret。
-
向 Access Service Tokens 端点发出
POST请求:
At least one of the following token permissions is required:Required API token permissions
Access: Service Tokens Write
Create a service tokenbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/access/service_tokens" \ --request POST \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "name": "CI/CD token", "duration": "8760h" }' -
复制响应中返回的
client_id和client_secret值。Responsejson "result": { "client_id": "88bf3b6d86161464f6509f7219099e57.access", "client_secret": "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5", "created_at": "2025-09-25T22:26:26Z", "expires_at": "2026-09-25T22:26:26Z", "id": "3537a672-e4d8-4d89-aab9-26cb622918a1", "name": "CI/CD token", "updated_at": "2025-09-25T22:26:26Z", "duration": "8760h", "client_secret_version": 1 }
-
向您的
cloudflare_api_token↗ 添加以下权限:Access: Service Tokens Write
-
配置
cloudflare_zero_trust_access_service_token↗ 资源:resource "cloudflare_zero_trust_access_service_token" "example_service_token" { account_id = var.cloudflare_account_id name = "Example service token" duration = "8760h" lifecycle { create_before_destroy = true } } -
获取服务令牌的 Client ID 和 Client Secret:
示例:输出到 CLI
- 将 Client ID 和 Client Secret 输出到 Terraform 状态文件:
output "example_service_token_client_id" { value = cloudflare_zero_trust_access_service_token.example_service_token.client_id } output "example_service_token_client_secret" { value = cloudflare_zero_trust_access_service_token.example_service_token.client_secret sensitive = true } - 应用配置:
terraform apply - 读取 Client ID 和 Client Secret:
terraform output -raw example_service_token_client_idterraform output -raw example_service_token_client_secret
示例:存储在 HashiCorp Vault 中
resource "vault_generic_secret" "example_service_token" { path = "kv/cloudflare/example_service_token" data_json = jsonencode({ "CLIENT_ID" = cloudflare_access_service_token.example_service_token.client_id "CLIENT_SECRET" = cloudflare_access_service_token.example_service_token.client_secret }) } - 将 Client ID 和 Client Secret 输出到 Terraform 状态文件:
在您的设备注册权限中,创建以下策略:
| Rule Action(规则操作) | Rule type(规则类型) | Selector(选择器) | Value(值) |
|---|---|---|---|
| Service Auth(服务身份验证) | Include(包含) | Service Token(服务令牌) | <TOKEN-NAME> |
通过服务令牌注册的设备由电子邮件地址 non_identity@<team-name>.cloudflareaccess.com 识别。使用此电子邮件地址,您可以在预登录状态期间应用特定的设备配置文件设置和 Gateway 网络策略。例如,您可以仅提供完成 Windows 登录和/或设备管理活动所必需的资源的访问权限。
示例设备配置文件规则
| Selector(选择器) | Operator(运算符) | Value(值) | Logic(逻辑) |
|---|---|---|---|
| User email(用户电子邮件) | in | non_identity@<team-name>.cloudflareaccess.com |
And(且) |
| Operating system(操作系统) | is | Windows |
示例 Gateway 网络策略
| Selector(选择器) | Operator(运算符) | Value(值) | Logic(逻辑) |
|---|---|---|---|
| Destination IP(目标 IP) | in list | Active Directory servers |
And(且) |
| User email(用户电子邮件) | in | non_identity@<team-name>.cloudflareaccess.com |
And(且) |
| Passed Device Posture Checks(已通过的设备状况检查) | in | Windows 10 or higher (OS version) |
| Action(操作) |
|---|
| Allow(允许) |
要启用 Windows 预登录功能,必须在设备上部署以下格式的 MDM 文件。在以下示例中,pre_login 键允许设备使用服务令牌进行连接,而 configs 包含您的默认 Zero Trust 配置。
<dict>
<key>pre_login</key>
<dict>
<key>organization</key>
<string>mycompany</string>
<key>auth_client_id</key>
<string>TOKEN-ID</string>
<key>auth_client_secret</key>
<string>TOKEN-SECRET</string>
</dict>
<key>configs</key>
<array>
<dict>
<key>organization</key>
<string>mycompany</string>
<key>display_name</key>
<string>Default</string>
</dict>
</array>
</dict>当不存在其他 Cloudflare One Client 注册且用户尚未登录 Windows 时,Cloudflare One Client 将应用预登录配置。当预登录配置生效时,该设备将显示在 Team & Resources(团队和资源) > Devices(设备) 上,电子邮件为 non_identity@<team-name>.cloudflareaccess.com。
在用户登录 Windows 后,Cloudflare One Client 将自动切换到默认的 MDM 配置,并提示用户向 IdP 进行身份验证。通过身份验证后,Cloudflare One Client 将使用用户身份进行注册并连接。此时,Team & Resources(团队和资源) > Devices(设备) 页面将显示与该用户电子邮件关联的新设备。
如果关闭了多用户模式,此用户注册将用于随后的任何连接,包括在下一次 Windows 用户登录之前。删除用户注册将导致 Cloudflare One Client 在用户注销 Windows 后立即切换回预登录配置。
要了解预登录配置如何与多用户模式配合使用,请参阅 Cloudflare One Client 注册流程图。