本頁提供有關設定自適應防護的相關資訊。設定可調整的防護功能前,請先熟悉「可調整的防護功能總覽」和「可調整的防護功能應用實例」中的資訊。
事前準備
以下各節說明設定 Google Cloud Armor 安全性政策時,所需的所有 Identity and Access Management (IAM) 角色和權限。針對本文的用途,您只需要 compute.securityPolicies.update
權限。
為 Google Cloud Armor 安全性政策設定 IAM 權限
下列作業需要具備身分與存取權管理 (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 list
(僅限gcloud
)
具有安全性管理員角色 (roles/iam.securityAdmin
)和 Compute Network 管理員角色的使用者,可以使用 SecurityPolicies
API 方法 get
、list
和 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 |
啟用 Adaptive Protection
請按照下列步驟,為安全性政策啟用自適應防護功能。自動調整式防護機制會個別套用至每個安全性政策。
主控台
如要為安全性政策啟用 Adaptive Protection,請按照下列步驟操作:
前往 Google Cloud 控制台的「Network Security」頁面。
在「政策」頁面中,按一下安全政策的名稱。
按一下 [編輯]。
在「Adaptive Protection」下方,選取「Enable」。
按一下 [Update]。
如要停用安全性政策的 Adaptive Protection,請按照下列步驟操作:
前往 Google Cloud 控制台的「Network Security」頁面。
在「政策」頁面中,按一下安全政策的名稱。
按一下 [編輯]。
在「Adaptive Protection」下方,取消勾選「Enable」。
按一下 [Update]。
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 分析的精細單位。在以下範例中,您會為每個主機建立精細的流量單位、自訂精細的流量單位,並設定自適應防護功能,在流量超出每秒查詢次數 (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
- 建立名稱為
POLICY_NAME
的安全性政策,或使用現有的安全性政策。 - 如果尚未啟用 Adaptive Protection,請使用下列指令為政策啟用 Adaptive Protection:
gcloud compute security-policies update POLICY_NAME
--enable-layer7-ddos-defense - 將安全性政策套用至有多個主機的後端服務。
- 使用以下
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
- 如果尚未啟用 Adaptive Protection 自動部署功能,請建立預留位置規則。
- 下列指令會為精細流量單位自訂自動部署門檻,其中
HTTP_HEADER_HOST
為HOST
,HTTP_PATH
為PATH
。針對您要自訂的每個精細流量單位使用這個指令,並視需要替換每個主機和網址路徑的變數: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
- 建立名稱為
POLICY_NAME
的安全性政策,或使用現有的安全性政策。 如果尚未啟用 Adaptive Protection,請使用下列指令為政策啟用 Adaptive Protection:
gcloud compute security-policies update POLICY_NAME \ --enable-layer7-ddos-defense
將安全性政策套用至後端服務。
使用下列指令,設定自訂偵測門檻的 Adaptive Protection:
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