以下示例介绍了使用 Cloudflare API 管理和配置泄露凭据检测的常用方案。
如果您使用的是 Terraform,请参阅 Terraform 配置示例。
以下 API 示例涵盖了启用和禁用泄露凭据检测等基本操作。
要开启泄露凭据检测,请使用类似于以下的 POST 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"enabled": true
}'要关闭泄露凭据检测,请使用类似于以下的 POST 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"enabled": false
}'要获取泄露凭据检测的当前状态,请使用类似于以下的 GET 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": {
"enabled": true
},
"success": true,
"errors": [],
"messages": []
}以下 API 示例涵盖了针对泄露凭据检测的 自定义检测位置 的操作。
要添加自定义检测位置,请使用类似于以下的 POST 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks/detections" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"username": "lookup_json_string(http.request.body.raw, \"user\")",
"password": "lookup_json_string(http.request.body.raw, \"secret\")"
}'要获取现有自定义检测位置的列表,请使用类似于以下的 GET 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks/detections" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": [
{
"id": "<DETECTION_ID>",
"username": "lookup_json_string(http.request.body.raw, \"user\")",
"password": "lookup_json_string(http.request.body.raw, \"secret\")"
}
// (...)
],
"success": true,
"errors": [],
"messages": []
}要删除自定义检测位置,请使用类似于以下的 DELETE 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks/detections/$DETECTION_ID" \
--request DELETE \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"