1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Cloudflare Zero Trust で DNS ポリシーのスケジュール設定を試す

Last updated at Posted at 2023-09-26

目的

こちらの内容を実際に確認します。

DNS ポリシーのスケジュール API

以下の API から schedule パラメータを設定可能です。

time_zone の扱いは以下のようになっていますが、正しく指定するのがよさそうです。

ルールが評価されるタイムゾーン。有効なタイムゾーン都市名が指定された場合、Gatewayは常にそのタイムゾーンの現在時刻を使用します。このパラメータが省略された場合、GatewayはユーザーのソースIPから推測されるタイムゾーンを使用してルールを評価します。GatewayがIPからタイムゾーンを判断できない場合、ユーザーが接続しているデータセンターのタイムゾーンにフォールバックします。

DNS ポリシーの作成

以下のコマンドでスケジュールされた DNS ポリシーを作成します。

export EMAIL='YOUR_EMAIL'
export APIKEY='YOUR_APIKEY'
export ACCOUNT_ID='YOUR_ACCOUNT_ID'

curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json" \
     --data '{
        "name": "office-no-youtube-policy",
        "action": "block",
        "traffic": "any(dns.domains[*] in {\"youtube.com\"})",
        "enabled": true,
        "schedule": {
                "time_zone": "Asia/Tokyo",
                "mon":  "08:00-12:30,13:30-17:00",
                "tue":  "08:00-12:30,14:30-17:00",
                "wed":  "08:00-12:30,13:30-17:00",
                "thu":  "08:00-12:30,13:30-17:00",
                "fri":  "08:00-12:30,13:30-17:00"
        }
    }'

スケジュールは、ポリシーの行を展開すると、Zero Trust の Gateway > Firewall Policies > DNS の下に表示されます。

image.png

動作確認

設定したスケジュールの時間内だと、DNS ポリシーが有効なことを確認できます。

not_in_schedule_time
% date
Tue Sep 26 14:33:10 JST 2023
% dig -4 @172.64.36.1 www.youtube.com A +short
youtube-ui.l.google.com.
142.250.198.14
142.250.199.110
172.217.31.174
142.250.207.46
172.217.175.238
172.217.175.46
172.217.161.46
172.217.175.78
142.250.196.110
142.250.196.142
142.250.207.14
216.58.220.110
142.251.222.14
142.251.42.142
142.251.42.174
142.251.42.206
in_schedule_time
% date
Tue Sep 26 14:40:02 JST 2023

% dig -4 @172.64.36.1 www.youtube.com A +short
0.0.0.0

まとめ

昼休みを除く平日のワーキングタイムのみ、DNS ポリシーを適用する等の運用が考えられます。
Cloudflare Zero Trust では、より詳細なポリシー設定が可能であると理解できました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?