設定 IP 位址許可清單

如要將信任的 IP 位址從 reCAPTCHA 強制執行作業中排除,請為與網站相關聯的 reCAPTCHA 金鑰建立許可清單,並將 IP 位址和子網路新增至該許可清單。

您也可以從許可清單中移除 IP 位址和子網路,並列出已加入許可清單的 IP 位址和子網路。

事前準備

  • 收集要加入許可清單的所有 IP 位址和子網路。

  • 找出要從許可清單中移除的 IP 位址和子網路。

  • 確認您具備下列身分與存取權管理角色:reCAPTCHA Enterprise 管理員 (roles/recaptchaenterprise.admin)。

將 IP 位址或子網路加入許可清單

將 IP 位址或子網路新增至允許清單後,reCAPTCHA 會略過驗證,並一律將來自該 IP 位址或子網路的要求評為 0.9。許可清單最多可新增 1000 個 IP 位址和子網路。

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 使用下方的任何指令資料之前,請先替換以下項目:

    • KEY:與網站相關聯的 reCAPTCHA 金鑰。
    • IP_ADDRESS_OR_SUBNET:需要新增至許可清單的 IP 位址或子網路。

    執行下列指令:

    Linux、macOS 或 Cloud Shell

    gcloud recaptcha keys add-ip-override
    KEY \
    --ip=IP_ADDRESS_OR_SUBNET \
    --override=ALLOW

    Windows (PowerShell)

    gcloud recaptcha keys add-ip-override
    KEY `
    --ip=IP_ADDRESS_OR_SUBNET `
    --override=ALLOW

    Windows (cmd.exe)

    gcloud recaptcha keys add-ip-override
    KEY ^
    --ip=IP_ADDRESS_OR_SUBNET ^
    --override=ALLOW

REST

使用任何要求資料之前,請先替換以下項目:

  • KEY:與網站相關聯的 reCAPTCHA 金鑰。
  • IP_ADDRESS_OR_SUBNET:需要新增至許可清單的 IP 位址或子網路。
  • PROJECT_ID:您的 Google Cloud 專案 ID

HTTP 方法和網址:

POST https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/keys/KEY:addIpOverride

JSON 要求主體:


{
  "ip_override_data": {
    "ip": "IP_ADDRESS_OR_SUBNET",
    "override_type": "ALLOW"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/keys/KEY:addIpOverride"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/keys/KEY:addIpOverride" | Select-Object -Expand Content

您應該會收到執行成功的狀態碼 (2xx) 和空白回應。

將 IP 位址或子網路新增至許可清單後,變更會在幾分鐘內生效。

從許可清單中移除 IP 位址或子網路

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 使用下方的任何指令資料之前,請先替換以下項目:

    • KEY:與網站相關聯的 reCAPTCHA 金鑰。
    • IP_ADDRESS_OR_SUBNET:需要新增至許可清單的 IP 位址或子網路。

    執行下列指令:

    Linux、macOS 或 Cloud Shell

    gcloud recaptcha keys remove-ip-override
    KEY \
    --ip=IP_ADDRESS_OR_SUBNET \
    --override=ALLOW

    Windows (PowerShell)

    gcloud recaptcha keys remove-ip-override
    KEY `
    --ip=IP_ADDRESS_OR_SUBNET `
    --override=ALLOW

    Windows (cmd.exe)

    gcloud recaptcha keys remove-ip-override
    KEY ^
    --ip=IP_ADDRESS_OR_SUBNET ^
    --override=ALLOW

REST

使用任何要求資料之前,請先替換以下項目:

  • KEY:與網站相關聯的 reCAPTCHA 金鑰。
  • IP_ADDRESS_OR_SUBNET:需要新增至許可清單的 IP 位址或子網路。
  • PROJECT_ID:您的 Google Cloud 專案 ID

HTTP 方法和網址:

POST https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/keys/KEY:removeIpOverride

JSON 要求主體:


{
  "ip_override_data": {
    "ip": "IP_ADDRESS_OR_SUBNET",
    "override_type": "ALLOW"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/keys/KEY:removeIpOverride"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/keys/KEY:removeIpOverride" | Select-Object -Expand Content

您應該會收到執行成功的狀態碼 (2xx) 和空白回應。

從允許清單中移除 IP 位址或子網路後,變更會在幾分鐘內生效。

列出許可清單中的所有 IP 位址

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 使用下方的任何指令資料之前,請先替換以下項目:

    • KEY:與網站相關聯的 reCAPTCHA 金鑰。

    執行下列指令:

    Linux、macOS 或 Cloud Shell

    gcloud recaptcha keys list-ip-overrides KEY --format=json

    Windows (PowerShell)

    gcloud recaptcha keys list-ip-overrides KEY --format=json

    Windows (cmd.exe)

    gcloud recaptcha keys list-ip-overrides KEY --format=json

REST

使用任何要求資料之前,請先替換以下項目:

  • KEY:與網站相關聯的 reCAPTCHA 金鑰。
  • PROJECT_ID:您的 Google Cloud 專案 ID

HTTP 方法和網址:

GET https://recaptchaenterprise.googleapis.com/v1/projects//keys/:listIpOverrides

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://recaptchaenterprise.googleapis.com/v1/projects//keys/:listIpOverrides"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://recaptchaenterprise.googleapis.com/v1/projects//keys/:listIpOverrides" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:


{
  "ipOverrides": [
    {
      "ip": "1.2.3.4",
      "overrideType": "ALLOW"
    }
  ],
  "nextPageToken": ""
}


後續步驟