bot 管理を構成する

このページでは、Google Cloud Armor セキュリティ ポリシー ルールを bot 管理用に構成する方法について説明します。bot 管理を構成する前に、bot 管理の概要の情報をよく理解してください。

準備

以降のセクションでは、Google Cloud Armor セキュリティ ポリシーの構成に必要なすべての Identity and Access Management(IAM)のロールと権限について説明します。このドキュメントのユースケースでは、compute.securityPolicies.create 権限と compute.securityPolicies.update 権限のみが必要です。

Google Cloud Armor セキュリティ ポリシーの IAM 権限を設定する

次の操作を行うには、Identity and Access Management(IAM)の Compute セキュリティ管理者のロール(roles/compute.securityAdminが必要です。

  • Google Cloud Armor セキュリティ ポリシーの構成、変更、更新、削除
  • 次の API メソッドの使用:
    • SecurityPolicies insert
    • SecurityPolicies delete
    • SecurityPolicies patch
    • SecurityPolicies addRule
    • SecurityPolicies patchRule
    • SecurityPolicies removeRule

Compute ネットワーク管理者のロール(roles/compute.networkAdminを付与されたユーザーは、次の操作を実行できます。

  • バックエンド サービスの Google Cloud Armor セキュリティ ポリシーの設定
  • 次の API メソッドの使用:
    • BackendServices setSecurityPolicy
    • BackendServices listgcloud のみ)

セキュリティ管理者ロール(roles/iam.securityAdminとネットワーク管理者ロールを持つユーザーは、SecurityPolicies API メソッドの getlist、および getRule を使用して、Google Cloud Armor セキュリティ ポリシーを閲覧できます。

カスタムロールの IAM 権限を設定する

次の表に、IAM のロールの基本的な権限と、関連する API メソッドを示します。

IAM 権限 API メソッド
compute.securityPolicies.create SecurityPolicies insert
compute.securityPolicies.delete SecurityPolicies delete
compute.securityPolicies.get SecurityPolicies get
SecurityPolicies getRule
compute.securityPolicies.list SecurityPolicies list
compute.securityPolicies.use BackendServices setSecurityPolicy
compute.securityPolicies.update SecurityPolicies patch
SecurityPolicies addRule
SecurityPolicies patchRule
SecurityPolicies removeRule
compute.backendServices.setSecurityPolicy BackendServices setSecurityPolicy

reCAPTCHA Enterprise の手動チャレンジで人と自動クライアントを区別する

reCAPTCHA Enterprise と Google Cloud Armor を連携して使用するには、CHALLENGEPAGE タイプの reCAPTCHA WAF サイトキー(reCAPTCHA キー)をセキュリティ ポリシーに関連付ける必要があります。reCAPTCHA キーの詳細については、reCAPTCHA キーの概要をご覧ください。

独自の reCAPTCHA キーをセキュリティ ポリシーに関連付ける(または関連付けを解除する)には、次のコマンドを使用します。

gcloud compute security-policies update SECURITY_POLICY \
    --recaptcha-redirect-site-key SITE_KEY

次のように置き換えます。

  • SECURITY_POLICY: セキュリティ ポリシーの名前
  • SITE_KEY: reCAPTCHA の CHALLENGEPAGE キー

reCAPTCHA キーを関連付ける

次の例では、reCAPTCHA キーをセキュリティ ポリシーに関連付けます。関連する reCAPTCHA キーは、特定のセキュリティ ポリシーで手動チャレンジ機能を使用するすべてのルールに適用されます。

gcloud compute security-policies update SECURITY_POLICY \
    --recaptcha-redirect-site-key "SITE_KEY"

reCAPTCHA キーの関連付けの解除

reCAPTCHA キーとセキュリティ ポリシーの関連付けを解除するには、次のコマンドを使用します。

gcloud compute security-policies update SECURITY_POLICY \
    --recaptcha-redirect-site-key ""

reCAPTCHA Enterprise の評価のためにトラフィックをリダイレクトする

reCAPTCHA キーをセキュリティ ポリシーに関連付けると、ポリシー内に reCAPTCHA Enterprise の評価のためにトラフィックを内部でリダイレクトするルールを作成できます。トラフィックをリダイレクトするには、gcloud CLI で次の形式を使用します。

gcloud compute security-policies rules create PRIORITY \
  --security-policy SECURITY_POLICY \
  {--expression EXPRESSION | --src-ip-ranges SRC_IP_RANGE} \
  --action redirect \
  --redirect-type google-recaptcha

次のように置き換えます。

  • PRIORITY: ルールを作成する優先度。
  • SECURITY_POLICY: セキュリティ ポリシーの名前
  • EXPRESSION: reCAPTCHA 評価を適用するトラフィックに一致するカスタムルール言語式
  • SRC_IP_RANGE: IP アドレス範囲。これを使用して、この範囲からのすべてのリクエストに対して reCAPTCHA 評価を適用します。

次の例では、reCAPTCHA Enterprise の手動チャレンジで /login.html に到達しようとするトラフィックをリダイレクトするルールを作成します。

gcloud compute security-policies rules create 1000 \
    --security-policy SECURITY_POLICY \
    --expression "request.path.matches(\"/login.html\")" \
    --action redirect \
    --redirect-type google-recaptcha

reCAPTCHA Enterprise のフリクションレス評価を適用する

先に進む前に、bot 管理の概要で、reCAPTCHA Enterprise のアクション トークンまたはセッション トークンを使用する際の前提条件を確認してください。

reCAPTCHA Enterprise アクション トークンから属性を抽出するには、token.recaptcha_action.ATTRIBUTE を使用します。ATTRIBUTE は、Google Cloud Armor のルール言語の有効なトークン属性に置き換えます。同様に、token.recaptcha_session.ATTRIBUTE を使用して reCAPTCHA Enterprise セッション トークンから属性を抽出します。利用可能な reCAPTCHA Enterprise トークン属性の構文の詳細については、ルール言語リファレンスをご覧ください。

アクション トークンはウェブ アプリケーション、iOS アプリケーション、または Android アプリケーションから生成できますが、セッション トークンはウェブ アプリケーションからのみ生成されます。プラットフォームごとに個別の reCAPTCHA キーが必要です。式 token.recaptcha_action.ATTRIBUTEtoken.recaptcha_session.ATTRIBUTE は、これらのプラットフォームからのトークンに適用されます。さまざまなプラットフォームからのトークンを区別して、トークンの盗難を防止するには、これらの式を使用するルールを構成するときに reCAPTCHA キーを関連付けることをおすすめします。

最初の例では、reCAPTCHA Enterprise アクション トークンのスコアが 0.8 以上の、/login.html をターゲットとするトラフィックを許可するルールを作成します。

gcloud compute security-policies rules create 1000 \
    --security-policy SECURITY_POLICY \
    --expression "request.path.matches(\"/login.html\") && token.recaptcha_action.score >= 0.8" \
    --action allow

2 つ目の例は最初の例と同じですが、example-site-key-1 または example-site-key-2 の reCAPTCHA キーを使用してアクション トークンを発行する必要があります。

gcloud compute security-policies rules create 1000 \
    --security-policy SECURITY_POLICY \
    --expression "request.path.matches(\"/login.html\") && token.recaptcha_action.score >= 0.8" \
    --recaptcha-action-site-keys "example-site-key-1,example-site-key-2" \
    --action allow

3 番目の例では、reCAPTCHA Enterprise セッション トークンを example-site-key-3 という reCAPTCHA キーで発行し、スコアが 0.8 以上の、/login.html をターゲットにしたトラフィックを許可するルールを作成します。

gcloud compute security-policies rules create 1000 \
    --security-policy SECURITY_POLICY \
    --expression "request.path.matches(\"/login.html\") && token.recaptcha_session.score >= 0.8" \
    --recaptcha-session-site-keys "example-site-key-3" \
    --action allow

リダイレクト(302 レスポンス)

ユーザーが構成した URL にトラフィックをリダイレクトするルールを作成するには、Google Cloud CLI で次の形式を使用します。

gcloud compute security-policies rules create PRIORITY \
    --security-policy SECURITY_POLICY \
    {--expression EXPRESSION | --src-ip-ranges SRC_IP_RANGE} \
    --action redirect \
    --redirect-type external-302 \
    --redirect-target REDIRECT_URL

次のように置き換えます。

  • PRIORITY: ルールを作成する優先度。
  • SECURITY_POLICY: セキュリティ ポリシーの名前
  • EXPRESSION: reCAPTCHA 評価を適用するトラフィックに一致するカスタムルール言語式
  • SRC_IP_RANGE: IP アドレス範囲。これを使用して、この範囲からのすべてのリクエストに対して reCAPTCHA 評価を適用します。
  • REDIRECT_URL: トラフィックをリダイレクトする URL

次の例では、10.10.10.0/24 からのトラフィックを https://www.example.com へリダイレクトするルールを作成します。

gcloud compute security-policies rules create 1000 \
   --security-policy SECURITY_POLICY \
   --src-ip-ranges "10.10.10.0/24" \
   --action redirect \
   --redirect-type external-302 \
   --redirect-target "https://www.example.com"

リクエストのデコレート

トラフィックを許可する一方で、保護されたバックエンドに送信する前にカスタム ヘッダーとユーザー定義の静的値を追加するルールを作成するには、gcloud CLI で次の形式を使用します。

gcloud compute security-policies rules create PRIORITY \
    --security-policy SECURITY_POLICY \
    {--expression EXPRESSION | --src-ip-ranges SRC_IP_RANGE} \
    --action allow \
    --request-headers-to-add HEADER_1=VALUE_1,HEADER_2=VALUE_2,...

次のように置き換えます。

  • PRIORITY: ルールを作成する優先度。
  • SECURITY_POLICY: セキュリティ ポリシーの名前
  • EXPRESSION: reCAPTCHA 評価を適用するトラフィックに一致するカスタムルール言語式
  • SRC_IP_RANGE: IP アドレス範囲。これを使用して、この範囲からのすべてのリクエストに対して reCAPTCHA 評価を適用します。
  • HEADER_#: リクエストを修飾するリクエスト ヘッダーの名前
  • VALUE_#: リクエストを修飾するリクエスト ヘッダーの値

次の例では、リクエストの reCAPTCHA Enterprise アクション トークンのスコアが 0.2 未満である限り、/login.html をターゲットとするトラフィックを許可するルールを作成します。

gcloud compute security-policies rules create 1000 \
    --security-policy SECURITY_POLICY \
    --expression "request.path.matches("/login.html") && token.recaptcha_action.score < 0.2" \
    --action allow \
    --request-headers-to-add "reCAPTCHA-Warning=high"

次のステップ