Skip to content

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

よく使うポリシー

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

次の Cloudflare Gateway DNS ポリシーは、DNS トラフィックの保護によく使われます。各例には、組織向けに調整できるダッシュボードと API の手順があります。

推奨ポリシーの基準セットは インターネットトラフィックと SaaS アプリを保護する を参照してください。

ほかのセレクター、演算子、アクションの一覧は DNS ポリシーのページ を参照してください。

社内ドメインを許可する

このポリシーは、公式の社内ドメインへのアクセスを許可します。優先順位 を高くしてデプロイすると、Newly seen domainsLogin pages などのブロック対象カテゴリに該当しても、従業員は信頼できるドメインへアクセスできます。

セレクター 演算子 アクション 優先度
Domain in list Allowed domains Allow 1
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Allow corporate domains",
		"description": "Allow any internal corporate domains added to a list",
		"precedence": 0,
		"enabled": true,
		"action": "allow",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.domains[*] in $<LIST_UUID>)",
		"identity": ""
	}'

リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。

セキュリティ脅威をブロックする

Cloudflare の脅威インテリジェンスに基づき、Command & Control、Botnet、Malware などの セキュリティカテゴリ をブロックします。

セレクター 演算子 アクション
Security Categories in All security risks Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "All-DNS-SecurityCategories-Blocklist",
		"description": "Block security categories based on Cloudflare'\''s threat intelligence",
		"precedence": 20,
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})",
		"identity": ""
	}'
resource "cloudflare_zero_trust_gateway_policy" "block_security_threats" {
  account_id  = var.cloudflare_account_id
  name        = "All-DNS-SecurityCategories-Blocklist"
  description = "Block security categories based on Cloudflare's threat intelligence"
  precedence  = 20
	enabled     = true
  action      = "block"
  filters     = ["dns"]
  traffic     = "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})"
}

コンテンツカテゴリをブロックする

このポリシーに含めるカテゴリは、常にセキュリティ脅威であるとは限りません。ただしブロックすると、組織がさらされるリスクを下げられます。詳細は ドメインカテゴリ を参照してください。

セレクター 演算子 アクション
Content Categories in Questionable Content, Security Risks, Miscellaneous Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "All-DNS-ContentCategories-Blocklist",
		"description": "Block common content categories that may pose a risk",
		"precedence": 30,
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.content_category[*] in {17 85 87 102 157 135 138 180 162 32 169 177 128 15 115 119 124 141 161})",
		"identity": ""
	}'
resource "cloudflare_zero_trust_gateway_policy" "block_content_categories" {
  account_id  = var.cloudflare_account_id
  name        = "All-DNS-ContentCategories-Blocklist"
  description = "Block common content categories that may pose a risk"
  enabled     = true
  action      = "block"
  filters     = ["dns"]
  traffic     = "any(dns.content_category[*] in {17 85 87 102 157 135 138 180 162 32 169 177 128 15 115 119 124 141 161})"
  identity    = ""
}

カテゴリの動的リストをブロックする

Gateway へ送るリクエストの EDNS(Extension Mechanisms for DNS) ヘッダーに、OPT コード 65050 を使い、カテゴリ ID のリストを JSON オブジェクトとして追加できます。EDNS では、標準フィールド以外の追加メタデータを DNS クエリに付けられます。例:

{
	"categories": [2, 67, 125, 133]
}

Request Context Categories セレクターを使うと、EDNS で送られたカテゴリ ID をブロックできます。ポリシー作成時に不明なカテゴリでフィルターする場合や、アカウント上限に達せずにデバイス固有の DNS コンテンツフィルタリングを適用する場合に便利です。Gateway がこのセレクターで DNS クエリをブロックすると、リクエストは Extended DNS Error(EDE)Code 15(Blocked)と、一致したカテゴリの配列を含むフィールドを返します。

セレクター 演算子 アクション
Request Context Category is Present Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "All-DNS-Bock-Category-Matches-In-Request",
		"description": "Block all category matches in the request EDNS context",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "dns.categories_in_request_context_matches",
		"identity": ""
	}'
resource "cloudflare_zero_trust_gateway_policy" "block_content_categories" {
  account_id  = var.cloudflare_account_id
  name        = "All-DNS-Bock-Category-Matches-In-Request"
  description = "Block all category matches in the request EDNS context"
  enabled     = true
  action      = "block"
  filters     = ["dns"]
  traffic     = "dns.categories_in_request_context_matches"
  identity    = ""
}

未承認のアプリケーションをブロックする

シャドーIT のリスクを抑えるため、一部の組織はユーザーが使えるウェブツールやアプリケーションを制限します。たとえば、次のポリシーは既知の AI ツールをブロックします。

セレクター 演算子 アクション
Application in Artificial Intelligence Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "All-DNS-Application-Blocklist",
		"description": "Block access to unauthorized AI applications",
		"precedence": 40,
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(app.type.ids[*] in {25})",
		"identity": ""
	}'
resource "cloudflare_zero_trust_gateway_policy" "block_unauthorized_apps" {
  account_id  = var.cloudflare_account_id
  name        = "All-DNS-Application-Blocklist"
  description = "Block access to unauthorized AI applications"
  enabled     = true
  action      = "block"
  filters     = ["dns"]
  traffic     = "any(app.type.ids[*] in {25})"
  identity    = ""
}

禁止国をブロックする

リスクが高いと分類された国でホストされている Web サイトをブロックするポリシーを実装できます。対象国の指定は、組織の要件や、EAR(Export Administration Regulations)OFAC(Office of Foreign Assets Control)ITAR(International Traffic in Arms Regulations) などの規制に基づくことがあります。このポリシーは、指定した国に地理位置される IP アドレスへ解決する DNS クエリをブロックします。

セレクター 演算子 アクション
Resolved Country IP Geolocation in AfghanistanBelarusCongo (Kinshasa)CubaIranIraqKorea, NorthMyanmarRussian FederationSudanSyriaUkraineZimbabwe Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Block banned countries",
		"description": "Block access to banned countries",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.dst.geo.country[*] in {\"AF\" \"BY\" \"CD\" \"CU\" \"IR\" \"IQ\" \"KP\" \"MM\" \"RU\" \"SD\" \"SY\" \"UA\" \"ZW\"})",
		"identity": ""
	}'

トップレベルドメインをブロックする

悪用されやすい トップレベルドメイン(TLD。ドメイン名の末尾、.com.ru など)をブロックすると、アクセスを許可する明確な利点がない場合に特に、セキュリティリスクを下げられます。同様に、特定の国別 TLD へのアクセス制限は、ITAROFAC などの規制への対応に必要なことがあります。

セレクター 演算子 論理演算 アクション
Domain matches regex [.](cn|ru)$ Or Block
Domain matches regex [.](rest|hair|top|live|cfd|boats|beauty|mom|skin|okinawa)$ Or
Domain matches regex [.](zip|mobi)$
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Block top-level domains",
		"description": "Block top-level domains that are frequently used for malicious practices",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.domains[*] matches \"[.](cn|ru)$\") or any(dns.domains[*] matches \"[.](rest|hair|top|live|cfd|boats|beauty|mom|skin|okinawa)$\") or any(dns.domains[*] matches \"[.](zip|mobi)$\")",
		"identity": ""
	}'

フィッシング攻撃をブロックする

高度なフィッシング攻撃 から守るため、組織を標的にしたフィッシングドメインへのアクセスを防げます。次のポリシーは、組織またはその認証サービスに関連する特定のキーワード(okta2facloudflaresso など)をブロックしつつ、公式の社内ドメインへのアクセスは許可します。

セレクター 演算子 論理演算 アクション
Domain not in list Corporate Domains And Block
Domain matches regex .*okta.*|.*cloudflare.*|.*mfa.*|.sso.*
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Block phishing attacks",
		"description": "Block attempts to phish specific domains targeting your organization",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "not(any(dns.domains[*] in $<LIST_UUID>)) and any(dns.domains[*] matches \".*okta.*\\|.*cloudflare.*\\|.*mfa.*\\|.sso.*\")",
		"identity": ""
	}'

リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。

オンライントラッキングをブロックする

ユーザーのプライバシーを守るため、一部の組織は dig.whatsapp.com などのトラッキングドメインや、OS レベルに埋め込まれたほかのトラッキングドメインをブロックします。このポリシーは、カスタムブロックリストを作成して実装します。ブロックリストに追加できる広く使われているトラッキングドメインの一覧は このリポジトリ を参照してください。

セレクター 演算子 アクション
Domain in list Top tracking domains Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Block online tracking",
		"description": "Block domains used for tracking at an OS level",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.domains[*] in $<LIST_UUID>)",
		"identity": ""
	}'

リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。

悪意のある IP をブロックする

組織に脅威となる、または悪意があると分かっている特定の IP アドレスをブロックします。このポリシーは通常、カスタムブロックリストを作成するか、脅威インテリジェンスパートナーや地域の Computer Emergency and Response Team(CERT)が提供するブロックリストを使って実装します。

セレクター 演算子 アクション
Resolved IP in list DShield Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Block malicious IPs",
		"description": "Block specific IP addresses that are known to be malicious or pose a threat to your organization",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.resolved_ips[*] in $<LIST_UUID>)",
		"identity": ""
	}'

リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。

CIPA フィルターを有効にする

CIPA(Children's Internet Protection Act、児童インターネット保護法)フィルターは、未成年者に有害または不適切な幅広いトピックを含むサブカテゴリの集合です。Project Cybersafe Schools の一部として、望ましくない、または有害なオンラインコンテンツへのアクセスをブロックするために使います。このポリシーを作成すると、組織は最低限の CIPA 準拠 を満たします。

セレクター 演算子 アクション
Content Categories in CIPA Filter Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Turn on CIPA filter",
		"description": "Block access to unwanted or harmful online content for children",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.content_category[*] in {182})",
		"identity": ""
	}'

露骨な検索結果を非表示にする

SafeSearch は、露骨または攻撃的なコンテンツをフィルターする検索エンジンの機能です。Google、Bing、Yandex、YouTube、DuckDuckGo などの検索エンジンで SafeSearch を強制できます。

セレクター 演算子 アクション
Content Categories in Search Engines Safe Search
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Hide explicit search results",
		"description": "Force SafeSearch on search engines to filter explicit or offensive content",
		"enabled": true,
		"action": "safesearch",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.content_category[*] in {145})",
		"identity": ""
	}'

ユーザー ID を確認する

ポリシーに ID ベースの条件 を追加して、ユーザーまたはグループ単位でアクセスを設定します。

セレクター 演算子 論理演算 アクション
Application in Salesforce And Block
User Group Names in Contractors
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Check user identity",
		"description": "Filter traffic based on a user identity group name",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(app.ids[*] in {606})",
		"identity": "any(identity.groups.name[*] in {\"Contractors\"})"
	}'

特定のグループにアクセスを制限する

DNS クエリをフィルターし、特定のユーザーだけにアクセスを許可します。

次の例は 2 つのポリシーで構成します。1 つ目のポリシーは指定したグループを許可し、2 つ目のポリシーはその他のユーザーをすべてブロックします。正しく評価されるよう、Allow ポリシーを Block ポリシーより上に置いてください。詳細は 優先順位 を参照してください。

1. グループを許可する

セレクター 演算子 論理演算 アクション
Content Categories in Social Networks And Allow
User Group Names in Marketing
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Allow social media for Marketing",
		"description": "Allow access to social media sites for users in the Marketing group",
		"precedence": 1,
		"enabled": true,
		"action": "allow",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.content_category[*] in {149})",
		"identity": "any(identity.groups.name[*] in {\"Marketing\"})"
	}'

2. その他のユーザーをすべてブロックする

セレクター 演算子 アクション
Content Categories in Social Networks Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Block social media",
		"description": "Block social media for all other users",
		"precedence": 2,
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "any(dns.content_category[*] in {149})",
		"identity": ""
	}'

IP バージョンを制御する

Enterprise ユーザーは、これらのポリシーを エグレスポリシー と組み合わせ、Gateway が宛先サーバーへ接続するときの IP バージョンを制御できます。

任意で Domain セレクターを使い、特定サイトの IP バージョンを制御することもできます。

IPv4 を強制する

AAAA(IPv6)レコードの解決をブロックし、ユーザーを IPv4 で接続させます。

セレクター 演算子 アクション
Query Record Type is AAAA Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Force IPv4",
		"description": "Force users to connect with IPv4 by blocking IPv6 resolution",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "dns.query_rtype == \"AAAA\"",
		"identity": ""
	}'

IPv6 を強制する

A(IPv4)レコードの解決をブロックし、ユーザーを IPv6 で接続させます。

セレクター 演算子 アクション
Query Record Type is A Block
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"name": "Force IPv6",
		"description": "Force users to connect with IPv6 by blocking IPv4 resolution",
		"enabled": true,
		"action": "block",
		"filters": [
				"dns"
		],
		"traffic": "dns.query_rtype == \"A\"",
		"identity": ""
	}'

役に立ちましたか?