配置 Google Cloud Armor Adaptive Protection

本页面介绍了如何配置 Adaptive Protection。在配置 Adaptive Protection 之前,请确保您熟悉 Adaptive Protection 概览自适应保护应用场景

准备工作

以下部分介绍了配置 Google Cloud Armor 安全政策所需的所有 Identity and Access Management (IAM) 角色和权限。对于本文档中的应用场景,您只需拥有 compute.securityPolicies.update 权限。

为 Google Cloud Armor 安全政策设置 IAM 权限

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

  • 配置、修改、更新和删除 Google Cloud Armor 安全政策
  • 使用以下 API 方法:
    • SecurityPolicies insert
    • SecurityPolicies delete
    • SecurityPolicies patch
    • SecurityPolicies addRule
    • SecurityPolicies patchRule
    • SecurityPolicies removeRule

具有 Compute Network Admin 角色 (roles/compute.networkAdmin) 的用户可以执行以下操作:

  • 为后端服务设置 Google Cloud Armor 安全政策
  • 使用以下 API 方法:
    • BackendServices setSecurityPolicy
    • BackendServices list(仅限 gcloud

具有 Security Admin 角色 (roles/iam.securityAdmin) 并且 Compute Network Admin 角色可以使用 SecurityPolicies API 方法 getlistgetRule 查看 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。Adaptive Protection 会单独应用于每个安全政策。

控制台

如需为安全政策激活自动调节式保护,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往网络安全页面。

    前往“网络安全”

  2. 政策页面上,点击安全政策的名称。

  3. 点击修改

  4. 自动调节式保护下,选择启用

  5. 点击更新

如需为安全政策停用自动调节式保护,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往网络安全页面。

    前往“网络安全”

  2. 政策页面上,点击安全政策的名称。

  3. 点击修改

  4. Adaptive Protection 下,清除启用

  5. 点击更新

gcloud

如需为安全政策激活自动调节式保护,请执行以下操作:

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

如需为安全政策停用自动调节式保护,请执行以下操作:

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

配置精细模型

借助精细模型功能,您可以将特定主机或路径配置为自动调节式保护分析的精细单元。在以下示例中,您为每个主机创建了精细流量单元,自定义精细流量单元,并将自动调节式保护配置为流量超过基准每秒查询次数 (QPS) 时采取措施。如需详细了解精细模型,请参阅自动调节式保护概览

配置精细流量单元

本部分中的示例将 add-layer7-ddos-defense-threshold-config 命令与以下部分或全部标志结合使用:

标志 说明
--threshold-config-name 阈值配置的名称。
--traffic-granularity-configs 用于启用自动调节式保护以处理指定服务粒度上的配置选项。
--auto-deploy-impacted-baseline-threshold 针对自动调节式保护对检测到攻击的建议缓解规则的基准流量的预计影响的阈值只有在未超出阈值的情况下,系统才会应用自动防御。
--auto-deploy-expiration-sec 自动部署执行的操作(如果有)的时长。
--detection-load-threshold 基于后端服务的负载的检测阈值。
--detection-absolute-qps 基于绝对 QPS 的检测阈值。
--detection-relative-to-baseline-qps 基于相对于基准流量平均值的 QPS 的检测阈值。

在第一个示例中,您将自动调节式保护配置为检测后端服务后面的每个主机遭受的攻击,并建议独立的缓解措施,而无需替换任何默认阈值。

gcloud

  1. 创建一个名称为 POLICY_NAME 的安全政策,或使用现有安全政策。
  2. 如果尚未启用自动调节式保护,请使用以下命令为政策启用自动调节式保护:
    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. 如果尚未启用自动调节式保护自动部署,请创建占位符规则
  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

在以下示例中,您将自动调节式保护配置为仅在攻击量超过基准平均 QPS 50% 以上且后端服务的负载超过其容量的 90% 时检测攻击。

gcloud

  1. 创建一个名称为 POLICY_NAME 的安全政策,或使用现有安全政策。
  2. 如果尚未启用自动调节式保护,请使用以下命令为政策启用自动调节式保护:

    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
    

后续步骤