配置 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

配置精细模型

通过精细模型功能,您可以将特定主机或路径配置为 是 Adaptive Protection 分析的精细单元。在以下示例中, 您可以为每个主机创建精细的流量单位、自定义精细的流量 单元,并将 Adaptive Protection 配置为在流量超过 基准每秒查询次数 (QPS)。如需详细了解 请参阅 Adaptive Protection 概览

配置精细的流量单位

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

标志 说明
--threshold-config-name 阈值配置的名称。
--traffic-granularity-configs 用于启用 Adaptive Protection 的配置选项 指定的服务粒度
--auto-deploy-impacted-baseline-threshold 自动调节式保护功能对 针对检测到的攻击建议的缓解规则的基准流量。 只有在未达到阈值时,系统才会应用自动防御。
--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 尚未启用,请使用以下命令 为您的政策启用 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_HOSTHOST 的流量单位 和 PATHHTTP_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 且仅当后端服务的负载超过其负载的 90% 时, 容量。

gcloud

  1. 创建名为 POLICY_NAME 的安全政策, 或使用现有的安全政策。
  2. 如果尚未启用 Adaptive Protection,请使用以下 命令为您的政策启用 Adaptive Protection:

    gcloud compute security-policies update POLICY_NAME \
      --enable-layer7-ddos-defense
    
  3. 将安全政策应用于后端服务。

  4. 使用以下命令配置 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
    

后续步骤