設定 Google Cloud Armor Adaptive Protection

這個頁面說明如何設定 Adaptive Protection。設定 Adaptive Protection 前,請務必先瞭解Adaptive Protection 總覽Adaptive Protection 應用實例中的資訊。

事前準備

以下各節說明設定 Cloud Armor 安全性政策時,所需的所有 Identity and Access Management (IAM) 角色和權限。如要使用本文中的用途,您只需要 compute.securityPolicies.update 權限。

設定 Cloud Armor 安全性政策的 IAM 權限

下列作業需要 Identity and Access Management (IAM) 的 Compute Security Admin 角色 (roles/compute.securityAdmin)

  • 設定、修改、更新及刪除 Cloud Armor 安全性政策
  • 使用下列 API 方法:
    • SecurityPolicies insert
    • SecurityPolicies delete
    • SecurityPolicies patch
    • SecurityPolicies addRule
    • SecurityPolicies patchRule
    • SecurityPolicies removeRule

具備 Compute 網路管理員角色 (roles/compute.networkAdmin) 的使用者可以執行下列作業:

  • 為後端服務設定 Cloud Armor 安全性政策
  • 使用下列 API 方法:
    • BackendServices setSecurityPolicy
    • BackendServices list (僅限 gcloud)

具備安全管理員角色 (roles/iam.securityAdmin) 和 Compute 網路管理員角色的使用者,可以透過 SecurityPolicies API 方法 getlistgetRule 查看 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

啟用 Adaptive Protection

請按照下列步驟,為安全防護政策啟用適應性防護功能。系統會個別對每項安全性政策套用 Adaptive Protection。

主控台

如要為安全性政策啟用 Adaptive Protection,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Network Security」(網路安全性) 頁面。

    前往「網路安全」

  2. 在「政策」頁面上,按一下安全性政策的名稱。

  3. 按一下 [編輯]

  4. 在「自動調整保護」下方,選取「啟用」。

  5. 按一下「更新」

如要停用安全性政策的 Adaptive Protection,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Network Security」(網路安全性) 頁面。

    前往「網路安全」

  2. 在「政策」頁面上,按一下安全性政策的名稱。

  3. 按一下 [編輯]

  4. 在「Adaptive Protection」(Adaptive Protection) 下方,取消勾選「Enable」(啟用)

  5. 按一下「更新」

gcloud

如要為安全性政策啟用 Adaptive Protection,請按照下列步驟操作:

gcloud compute security-policies update MY-SECURITY-POLICY \
    --enable-layer7-ddos-defense

如要停用安全性政策的 Adaptive Protection,請按照下列步驟操作:

gcloud compute security-policies update MY-SECURITY-POLICY \
    --no-enable-layer7-ddos-defense

設定細部模型

精細模型功能可讓您將特定主機或路徑設為精細單位,供 Adaptive Protection 分析。在下列範例中,您會為每個主機建立精細的流量單位、自訂精細的流量單位,並設定 Adaptive Protection,在流量超過每秒查詢次數 (QPS) 基準時採取行動。如要進一步瞭解精細模型,請參閱自動調整式防護機制總覽

設定精細的流量單位

本節的範例使用 add-layer7-ddos-defense-threshold-config 指令,並加上下列部分或全部旗標:

旗標 說明
--threshold-config-name 門檻設定的名稱。
--traffic-granularity-configs 設定選項,可啟用 Adaptive Protection,以指定服務精細度運作。
--auto-deploy-impacted-baseline-threshold Adaptive Protection 預估建議的緩解規則對偵測到的攻擊事件基準流量的影響。只有在未超出門檻的情況下,系統才會套用自動防禦措施。
--auto-deploy-expiration-sec 自動部署執行的動作 (如有) 持續時間。
--detection-load-threshold 偵測門檻取決於後端服務的負載。
--detection-absolute-qps 偵測門檻是根據絕對 QPS 設定。
--detection-relative-to-baseline-qps 偵測門檻是以 QPS 相對基準流量平均值為準。

在第一個範例中,您設定 Adaptive Protection,偵測後端服務後方每個主機的攻擊,並建議獨立的緩解措施,而不覆寫任何預設門檻。

gcloud

  1. 建立名為 POLICY_NAME 的安全性政策,或使用現有的安全性政策。
  2. 如果尚未啟用 Adaptive Protection,請使用下列指令為政策啟用這項功能:
    gcloud compute security-policies update POLICY_NAME 
    --enable-layer7-ddos-defense
  3. 將安全性政策套用至有多個主機的後端服務。
  4. 使用下列 add-layer7-ddos-defense-threshold-config 指令搭配 --traffic-granularity-configs 旗標,設定精細的流量單元:
    gcloud compute security-policies add-layer7-ddos-defense-threshold-config POLICY_NAME 
    --threshold-config-name=per-host-config
    --traffic-granularity-configs=type=HTTP_HEADER_HOST;enableEachUniqueValue=true

在第二個範例中,您會為第一個範例中設定的部分或所有細微流量單位,設定不同的自動部署和偵測門檻。

gcloud

  1. 如果尚未啟用 Adaptive Protection 自動部署功能,請建立預留位置規則
  2. 下列指令會自訂細微流量單位的自動部署門檻,HTTP_HEADER_HOSTHOSTHTTP_PATHPATH。針對要自訂的每個細部流量單位使用這個指令,並視需要為每個主機和網址路徑替換變數:
    gcloud compute security-policies add-layer7-ddos-defense-threshold-config POLICY_NAME 
    --threshold-config-name=my-host-config
    --auto-deploy-impacted-baseline-threshold=0.01
    --auto-deploy-expiration-sec=3600
    --traffic-granularity-configs=type=HTTP_HEADER_HOST;value=HOST,type=HTTP_PATH;value=PATH

偵測攻擊量何時超過基準平均 QPS

在下列範例中,您將 Adaptive Protection 設為只有在攻擊量超出基準平均 QPS 50% 以上,且後端服務的負載超過容量的 90% 時,才偵測攻擊。

gcloud

  1. 建立名為 POLICY_NAME 的安全性政策,或使用現有的安全性政策。
  2. 如果尚未啟用 Adaptive Protection,請使用下列指令為政策啟用 Adaptive Protection:

    gcloud compute security-policies update POLICY_NAME \
      --enable-layer7-ddos-defense
    
  3. 將安全性政策套用至後端服務。

  4. 使用下列指令,透過自訂偵測門檻設定適應性防護:

    gcloud compute security-policies add-layer7-ddos-defense-threshold-config POLICY_NAME \
       --threshold-config-name=my-customized-thresholds \
       --detection-load-threshold=0.9 \
       --detection-relative-to-baseline-qps=1.5
    

後續步驟