Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

フェーズのエントリポイントルールセットへルールを追加する

最終更新 Markdown で表示Agent セットアップ

フェーズのエントリポイントルールセット には、そのフェーズで実行されるルールの順序付き一覧があります。エントリポイントルールセット内のルールは、別のルールセットを実行できます。アカウントレベルとゾーンレベルのそれぞれで、フェーズごとにエントリポイントルールセットを持てます。

フェーズのエントリポイントルールセットへルールを 1 件以上追加するには、Rulesets APIルールセット更新操作 のいずれかを使います。エントリポイントルールセットへルールを追加するとき、そのエントリポイントルールセットがなければ自動で作成されます。この API メソッドでは、残したいルールをすべてリクエストに含める必要があります。含めないと削除されます。

ルールセットへルールを 1 件だけ追加する場合は、ルール作成操作 のいずれかを検討してください。この場合、リクエストには新しいルールの定義だけを含めます。

例: ゾーンレベルでフェーズのエントリポイントルールセットのルールを設定する

次の例は、ゾーンのエントリポイントルールセットを更新する 操作を使い、http_request_firewall_managed フェーズについて、ゾーンレベルでフェーズのエントリポイントルールセットのルールを設定します。

Required API token permissions

At least one of the following token permissions is required:
  • Response Compression Write
  • Config Settings Write
  • Dynamic URL Redirects Write
  • Cache Settings Write
  • Custom Errors Write
  • Origin Write
  • Managed headers Write
  • Zone Transform Rules Write
  • Mass URL Redirects Write
  • Magic Firewall Write
  • L4 DDoS Managed Ruleset Write
  • HTTP DDoS Managed Ruleset Write
  • Sanitize Write
  • Transform Rules Write
  • Select Configuration Write
  • Bot Management Write
  • Zone WAF Write
  • Account WAF Write
  • Account Rulesets Write
  • Logs Write
  • Logs Write
Update a zone entry point rulesetbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/phases/http_request_firewall_managed/entrypoint" \
	--request PUT \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"rules": [
				{
						"action": "execute",
						"action_parameters": {
								"id": "<MANAGED_RULESET_ID_1>"
						},
						"expression": "true"
				},
				{
						"action": "execute",
						"action_parameters": {
								"id": "<MANAGED_RULESET_ID_2>"
						},
						"expression": "true"
				}
		]
	}'
{
	"result": {
		"id": "<RULESET_ID>",
		"name": "Default",
		"description": "",
		"kind": "zone",
		"version": "1",
		"rules": [
			{
				"id": "<RULE_ID_1>",
				"version": "1",
				"action": "execute",
				"expression": "true",
				"action_parameters": {
					"id": "<MANAGED_RULESET_ID_1>"
				},
				"last_updated": "2021-06-17T15:42:37.917815Z"
			},
			{
				"id": "<RULE_ID_2>",
				"version": "1",
				"action": "execute",
				"expression": "true",
				"action_parameters": {
					"id": "<MANAGED_RULESET_ID_2>"
				},
				"last_updated": "2021-06-17T15:42:37.917815Z"
			}
		],
		"last_updated": "2021-06-17T15:42:37.917815Z",
		"phase": "http_request_firewall_managed"
	},
	"success": true,
	"errors": [],
	"messages": []
}

例: ゾーンレベルのフェーズエントリポイントルールセットへルールを 1 件追加する

次の例は、ゾーンルールセットにルールを作成する 操作を使い、ゾーンレベルでフェーズのエントリポイントルールセット(ID は $RULESET_ID)へルールを 1 件追加します。

Required API token permissions

At least one of the following token permissions is required:
  • Response Compression Write
  • Config Settings Write
  • Dynamic URL Redirects Write
  • Cache Settings Write
  • Custom Errors Write
  • Origin Write
  • Managed headers Write
  • Zone Transform Rules Write
  • Mass URL Redirects Write
  • Magic Firewall Write
  • L4 DDoS Managed Ruleset Write
  • HTTP DDoS Managed Ruleset Write
  • Sanitize Write
  • Transform Rules Write
  • Select Configuration Write
  • Bot Management Write
  • Zone WAF Write
  • Account WAF Write
  • Account Rulesets Write
  • Logs Write
  • Logs Write
Create a zone ruleset rulebash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$RULESET_ID/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"action": "execute",
		"action_parameters": {
				"id": "<MANAGED_RULESET_ID>"
		},
		"expression": "true"
	}'
{
	"result": {
		"id": "<RULESET_ID>",
		"name": "Zone-level phase entry point ruleset",
		"description": "",
		"kind": "root",
		"version": "2",
		"rules": [
			{
				"id": "<EXISTING_RULE_ID>",
				"version": "1",
				"action": "execute",
				"expression": "true",
				"action_parameters": {
					"id": "<ANOTHER_MANAGED_RULESET_ID>"
				},
				"last_updated": "2021-03-17T15:42:37.917815Z"
			},
			{
				"id": "<NEW_RULE_ID>",
				"version": "1",
				"action": "execute",
				"expression": "true",
				"action_parameters": {
					"id": "<MANAGED_RULESET_ID>"
				},
				"last_updated": "2021-06-30T15:42:37.917815Z"
			}
		],
		"last_updated": "2021-06-30T15:42:37.917815Z",
		"phase": "http_request_firewall_managed"
	},
	"success": true,
	"errors": [],
	"messages": []
}

役に立ちましたか?