配置 Google Cloud Armor 安全政策

使用以下说明创建 Google Cloud Armor 安全政策,以过滤流向以下目的地的传入流量:

  • 全球外部应用负载均衡器
  • 传统应用负载均衡器
  • 区域级外部应用负载均衡器
  • 外部代理网络负载均衡器
  • 传统代理网络负载均衡器
  • 外部直通式网络负载均衡器
  • 协议转发
  • 具有公共 IP 地址的虚拟机

如需了解安全政策的概念信息,请参阅 Google Cloud Armor 安全政策概览

准备工作

在配置安全政策之前,请执行以下操作:

  • 确保您熟悉外部应用负载均衡器概念。

  • 检查现有后端服务以确定哪些服务尚未关联安全政策。这些后端服务及其关联的后端将不受 Google Cloud Armor 的保护。如需获取 Google Cloud Armor 提供的保护,请按照本文档中的说明将新创建的或现有的安全政策关联到这些后端服务。

为 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

创建安全政策

您可以使用 Google Cloud 控制台、Google Cloud CLI 或 REST API 配置 Google Cloud Armor 安全政策、规则和表达式。使用 gcloud CLI 创建安全政策时,请使用 --type 标志指定安全政策是后端安全政策还是边缘安全政策。

如果您不熟悉安全政策配置,我们建议您查看示例安全政策

示例表达式

下面是示例表达式。如需详细了解表达式,请参阅 Google Cloud Armor 自定义规则语言参考

如果您要配置使用 ISO 3166-1 alpha 2 国家或地区代码的规则或表达式,请注意 Google Cloud Armor 会独立处理每个代码。Google Cloud Armor 规则和表达式显式使用这些地区代码来允许或拒绝请求。

  • 以下表达式与来自 IP 地址 1.2.3.4 的请求匹配,并且在用户代理标头中包含字符串 example

    inIpRange(origin.ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')
    

    或者,您可以使用 origin.user_ip 属性来匹配自定义客户端 IP 地址标头的 IP 地址范围:

    inIpRange(origin.user_ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')
    
  • 以下表达式与具有特定值的 Cookie 的请求匹配:

    has(request.headers['cookie']) && request.headers['cookie'].contains('cookie_name=cookie_value')
    
  • 以下表达式与来自地区 AU 的请求匹配:

    origin.region_code == 'AU'
    
  • 以下表达式与来自区域 AU 且不在指定 IP 范围内的请求匹配:

    origin.region_code == "AU" && !inIpRange(origin.ip, '1.2.3.0/24')
    
  • 如果 URI 与正则表达式匹配,则以下表达式与具有特定文件的编号变量路径的请求匹配:

    request.path.matches('/path/[0-9]+/target_file.html')
    
  • 如果 user-id 标头的 Base64 解码值包含特定值,则以下表达式与请求匹配:

    has(request.headers['user-id']) && request.headers['user-id'].base64Decode().contains('myValue')
    
  • 以下表达式使用设置为与 SQLi 攻击匹配的预配置表达式:

    evaluatePreconfiguredExpr('sqli-stable')
    

管理安全政策

使用以下部分列出项目中的安全政策、更新安全政策、删除安全政策或测试安全政策。

列出安全政策

按照这些说明列出当前项目或您指定的项目中的所有 Google Cloud Armor 安全政策。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 如需查看特定政策,请在安全政策页面的政策列表中,点击其名称。

gcloud

gcloud compute security-policies list

例如:

gcloud compute security-policies list
NAME
my-policy

如需了解详情,请参阅 gcloud compute security-policies list

更新安全政策

使用以下说明更新 Google Cloud Armor 安全政策。例如,您可以修改政策的说明,修改默认规则的行为,更改目标后端服务,或添加新规则。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 如要更新特定政策,请在安全政策页面的政策列表中,点击您要更新的政策的 菜单

    • 如需更新默认规则操作的政策说明,请选择修改,进行所需的更改,然后点击更新
    • 如要添加规则,请选择添加规则,然后按照向安全政策添加规则中的说明操作。
    • 如要更改政策的目标后端服务,请选择将政策应用于目标,点击添加目标,然后选择一个目标,再点击添加

gcloud

如要更新安全政策,请使用以下 Google Cloud CLI 说明:

删除多项安全政策

使用以下说明删除 Google Cloud Armor 安全政策。必须先从政策中移除所有后端服务,然后才能删除政策。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,选中要删除的安全政策名称旁边的复选框。

  3. 点击页面右上角的删除

gcloud

使用 gcloud compute security-policies delete NAME。 将 NAME 替换为安全政策的名称:

gcloud compute security-policies delete NAME

测试安全政策

我们建议您在预览模式下部署所有新规则,然后检查请求日志,以验证政策和规则的行为符合预期。

管理安全政策规则

使用以下部分列出安全政策规则、添加规则、更新规则或删除规则。

列出安全政策中的规则

使用以下说明列出 Google Cloud Armor 安全政策中的规则。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。随即会显示政策详情页面,并且政策规则在页面中间的规则标签页中列出。

gcloud

使用以下 gcloud 命令列出单个安全政策中的所有规则以及该政策的说明:

gcloud compute security-policies describe NAME \

使用以下 gcloud 命令描述指定安全政策中指定的优先级的规则:

gcloud compute security-policies rules describe PRIORITY \
    --security-policy POLICY_NAME

例如,以下命令描述安全政策 my-policy 中优先级为 1000 的规则:

gcloud compute security-policies rules describe 1000 \
    --security-policy my-policy

输出:

action: deny(403)
description: block traffic from 192.0.2.0/24 and 198.51.100.0/24
kind: compute#securityPolicyRule
match:
  srcIpRanges:
  - '192.0.2.0/24'
  - '198.51.100.0/24'
preview: false
priority: 1000

将规则添加到安全政策

使用以下说明将规则添加到 Google Cloud Armor 安全政策。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。此时将显示政策详情页面。

  3. 在页面中间,点击规则标签页。

  4. 点击添加规则

  5. 可选:输入规则的说明。

  6. 选择模式:

    • 基本模式:根据 IP 地址或 IP 范围允许或拒绝流量。
    • 高级模式:根据规则表达式允许或拒绝流量。
  7. 匹配字段中,指定适用规则的条件。

    • 基本模式:输入一 (1) 到五 (5) 个要在规则中匹配的 IP 地址范围。
    • 高级模式:输入要根据传入请求进行评估的表达式或子表达式。如需了解如何编写表达式和如何读取以下示例,请参阅自定义规则语言参考

      • 以下表达式与来自 IP 地址 1.2.3.4 的请求匹配,并且在用户代理标头中包含字符串 example

        inIpRange(origin.ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')
        
      • 以下表达式与具有特定值的 Cookie 的请求匹配:

        has(request.headers['cookie']) && request.headers['cookie'].contains('cookie_name=cookie_value')
        
      • 以下表达式与来自地区 AU 的请求匹配:

        origin.region_code == 'AU'
        
      • 以下表达式与来自区域 AU 且不在指定 IP 范围内的请求匹配:

        origin.region_code == "AU" && !inIpRange(origin.ip, '1.2.3.0/24')
        
      • 如果 URI 与正则表达式匹配,则以下表达式与请求匹配:

        request.path.matches('/bad_path/')
        
      • 如果 user-id 标头的 Base64 解码值包含特定值,则以下表达式与请求匹配:

        has(request.headers['user-id']) && request.headers['user-id'].base64Decode().contains('myValue')
        
      • 以下表达式使用设置为与 SQLi 攻击匹配的预配置表达式:

        evaluatePreconfiguredExpr('sqli-stable')
        
  8. 对于操作,请选择允许拒绝

  9. 如果您要配置拒绝规则,请选择拒绝状态消息。

  10. 若要为规则启用预览模式,请选中启用复选框。

  11. 优先级字段中,输入一个正整数。

  12. 点击添加

gcloud

使用 gcloud compute security-policies rules create PRIORITY 命令。将 PRIORITY 替换为政策中规则的优先级:

gcloud compute security-policies rules create PRIORITY \
    --security-policy POLICY_NAME \
    --description DESCRIPTION \
    --src-ip-ranges IP_RANGES | --expression EXPRESSION \
    --action=[ allow | deny-403 | deny-404 | deny-502 ] \
    --preview

例如,以下命令会添加一个规则,以阻止来自 IP 地址范围 192.0.2.0/24 和 198.51.100.0/24 的流量。该规则的优先级为 1000,且是名为 my-policy 政策中的规则:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --description "block traffic from 192.0.2.0/24 and 198.51.100.0/24" \
    --src-ip-ranges "192.0.2.0/24","198.51.100.0/24" \
    --action "deny-403"

使用 --expression 标志在自定义规则语言参考中指定条件。以下命令将添加一条规则,以允许来自 IP 地址 1.2.3.4 的流量,并且在用户代理标头中包含字符串 example

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "inIpRange(origin.ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')" \
    --action allow \
    --description "Block User-Agent 'example'"

如果请求的 Cookie 包含特定值,以下命令将添加一条规则以阻止请求:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "has(request.headers['cookie']) && request.headers['cookie'].contains('80=BLAH')" \
    --action deny-403 \
    --description "Cookie Block"

以下命令将添加一条规则,以阻止来自地区 AU 的请求:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "origin.region_code == 'AU'" \
    --action deny-403 \
    --description "AU block"

以下命令会添加一条规则来阻止不在指定 IP 范围内的 AU 区域的请求:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "origin.region_code == "AU" && !inIpRange(origin.ip, '1.2.3.0/24')" \
    --action deny-403 \
    --description "country and IP block"

以下命令将添加一条规则,以阻止具有与正则表达式匹配的 URI 的请求:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "request.path.matches('/bad_path/')" \
    --action deny-502 \
    --description "regex block"

如果 user-id 标头的 Base64 解码值包含特定值,以下命令将添加一条规则来阻止请求:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "has(request.headers['user-id']) && request.headers['user-id'].base64Decode().contains('myValue')" \
    --action deny-403 \
    --description "country and IP block"

以下命令将添加一条规则,该规则使用预配置的表达式集来缓解 SQLi 攻击:

gcloud compute security-policies rules create 1000 \
    --security-policy my-policy \
    --expression "evaluatePreconfiguredExpr('sqli-stable')" \
    --action deny-403

更新安全政策中的单个规则

使用以下说明更新 Google Cloud Armor 安全政策中的单条规则。如需原子更新多个规则,请参阅以原子方式更新安全政策中的多个规则

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。此时将显示政策详情页面。

  3. 在页面中间,点击规则标签页。

  4. 在要更新的规则旁边,点击修改。随即会显示修改规则页面。

  5. 进行更改,然后点击更新

gcloud

使用此命令可在指定的安全策略中更新具有指定优先级的规则。使用此命令一次只能更新一个安全策略:

gcloud compute security-policies rules update PRIORITY [ \
    --security-policy POLICY_NAME  \
    --description DESCRIPTION  \
    --src-ip-ranges IP_RANGES  | --expression EXPRESSION \
    --action=[ allow | deny-403 | deny-404 | deny-502 ]  \
    --preview
  ]
  

例如,以下命令将更新优先级为 1111 的规则,以允许来自 IP 地址范围 192.0.2.0/24 的流量:

gcloud compute security-policies rules update 1111 \
    --security-policy my-policy \
    --description "allow traffic from 192.0.2.0/24" \
    --src-ip-ranges "192.0.2.0/24" \
    --action "allow"

如需详细了解此命令,请参阅 gcloud compute security-policies rules update

如需更新规则的优先级,必须使用 REST API。如需了解详情,请参阅 securityPolicies.patchRule

以原子方式更新安全政策中的多条规则

原子更新会将更改应用于单个更新中的多条规则。如果您要逐条更新规则,您可能会看到一些意外行为,因为新旧规则可能会在短时间内协同工作。

要以原子方式更新多个规则,请将当前安全政策导出到 JSON 或 YAML 文件中,然后对其进行修改。使用修改后的文件创建新的安全政策,然后切换相关后端服务的安全政策。

gcloud

  1. 导出政策以进行更新,如以下示例所示:

    gcloud compute security-policies export my-policy \
        --file-name my-file \
        --file-format yaml
    

    导出后的政策将类似于以下示例:

    description: my description
    fingerprint: PWfLGDWQDLY=
    id: '123'
    name: my-policy
    rules:
    - action: deny(404)
      description: my-rule-1
      match:
        expr:
          expression: evaluatePreconfiguredExpr('xss-stable')
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 1
    - action: allow
      description: my-rule-2
      match:
        config:
          srcIpRanges:
          - '1.2.3.4'
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 2
    - action: deny
      description: default rule
      kind: compute#securityPolicyRule
      match:
        config:
          srcIpRanges:
          - '*'
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 2147483647
    selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/my-policy
    
  2. 使用任何文本编辑器修改政策。例如,您可以修改现有规则的优先级并添加新规则:

    description: my description
    fingerprint: PWfLGDWQDLY=
    id: '123'
    name: my-policy
    rules:
    - action: deny(404)
      description: my-rule-1
      match:
        expr:
          expression: evaluatePreconfiguredExpr('xss-stable')
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 1
    - action: allow
      description: my-new-rule
      match:
        config:
          srcIpRanges:
          - '1.2.3.1'
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 10
    - action: allow
      description: my-rule-2
      match:
        config:
          srcIpRanges:
          - '1.2.3.4'
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 11
    - action: deny
      description: default rule
      kind: compute#securityPolicyRule
      match:
        config:
          srcIpRanges:
          - '*'
        versionedExpr: SRC_IPS_V1
      preview: false
      priority: 2147483647
    selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/my-policy
    
  3. 创建一个新的 Google Cloud Armor 安全政策并指定修改后的文件名和格式,如以下示例所示:

    gcloud compute security-policies create new-policy \
        --file-name modified-policy \
        --file-format yaml
    
  4. 从相关后端服务中移除旧安全政策,如以下示例所示:

    gcloud compute backend-services update my-backend \
        --security-policy ""
    
  5. 将新安全政策添加到后端服务,如以下示例所示:

    gcloud compute backend-services update my-backend \
        --security-policy new-policy
    
  6. 如果未使用旧政策,请将其删除:

    gcloud compute security-policies delete my-policy
    

从安全政策中删除规则

使用这些说明删除 Google Cloud Armor 安全政策中的规则。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 点击安全政策的名称。此时将显示政策详情页面。

  3. 在该页面中间的规则标签页上,选中要删除的规则旁边的复选框。

  4. 点击删除

gcloud

使用此命令从指定安全政策中移除具有指定优先级的规则。您一次只能修改一个安全政策,但可以一次删除多个规则:

gcloud compute security-policies rules delete PRIORITY [...] [
    --security-policy POLICY_NAME \
  ]

例如:

gcloud compute security-policies rules delete 1000 \
    --security-policy my-policy

添加和移除安全政策

请参阅以下部分,了解如何在后端服务和后端存储桶中添加和移除安全政策。

将安全政策附加到后端服务

使用以下说明将 Google Cloud Armor 安全政策附加到后端服务。一个安全政策可以附加到多个后端服务,但是一个后端服务只能附加每种类型中的一个安全政策。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。此时将显示政策详情页面。

  3. 在页面中间,点击目标标签页。

  4. 点击将政策应用于新目标

  5. 点击添加目标

  6. 目标列表中,选择一个目标,然后点击添加

gcloud

将后端安全政策附加到后端服务时,请使用 gcloud compute backend-services 命令和 --security-policy 标志:

gcloud compute backend-services update my-backend \
    --security-policy my-policy

将边缘安全政策附加到后端服务时,请使用 gcloud compute backend-services 命令和 --edge-security-policy 标志:

gcloud compute backend-services update my-backend \
    --edge-security-policy my-policy

从后端服务中移除安全政策

使用以下说明从后端服务中移除 Google Cloud Armor 后端安全政策或边缘安全政策。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。此时将显示政策详情页面。

  3. 在页面中间,点击目标标签页。

  4. 选择要从中移除政策的目标后端服务。

  5. 点击移除

  6. 移除目标消息中,点击移除

gcloud

移除后端安全政策时,请使用 gcloud compute backend-services 命令和 --security-policy 标志:

gcloud compute backend-services update my-backend \
    --security-policy ""

移除边缘安全政策时,请使用 gcloud compute backend-services 命令和 --edge-security-policy 标志:

gcloud compute backend-services update my-backend \
    --edge-security-policy ""

将安全政策附加到后端存储桶

使用以下说明将 Google Cloud Armor 边缘安全政策附加到后端存储桶。边缘安全政策可以附加到多个后端存储桶。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。此时将显示政策详情页面。

  3. 在页面中间,点击目标标签页。

  4. 点击将政策应用于新目标

  5. 点击添加目标

  6. 目标列表中,选择一个目标,然后点击添加

gcloud

将边缘安全政策附加到后端存储桶时,请使用 cloud compute backend-buckets 命令和 --edge-security-policy 标志:

gcloud compute backend-services update my-bucket \
    --edge-security-policy my-edge-policy

从后端存储桶中移除安全政策

使用以下说明从后端存储桶移除 Google Cloud Armor 边缘安全政策。

控制台

  1. 在 Google Cloud 控制台中,转到 Google Cloud Armor 政策页面。

    转到“Google Cloud Armor 政策”

  2. 安全政策页面上,点击安全政策的名称。此时将显示政策详情页面。

  3. 在页面中间,点击目标标签页。

  4. 选择要从中移除政策的目标后端服务。

  5. 点击移除

  6. 移除目标消息中,点击移除

gcloud

从后端存储桶移除边缘安全政策时,请使用 cloud compute backend-buckets 命令和 --edge-security-policy 标志:

gcloud compute backend-services update my-bucket \
    --edge-security-policy ""

导入和导出安全政策

使用以下部分将安全政策作为 YAML 或 JSON 文件予以导入和导出。

导入安全政策

您可以使用 Google Cloud CLI 从 YAML 或 JSON 文件导入 Google Cloud Armor 安全政策。您不能使用 import 命令更新现有政策的规则。相反,您必须使用更新安全政策中的单个规则过程逐个更新规则,或者使用以原子方式更新安全政策中的多个规则过程一次性更新所有规则。

gcloud

如需导入安全政策,请使用 gcloud compute security-policies import NAME 命令。将 NAME 替换为要导入的安全政策的名称。如果您未提供文件格式,将根据文件结构采用正确的格式。如果结构无效,您会看到错误。

gcloud compute security-policies import NAME \
    --file-name FILE_NAME  \
   [--file-format FILE_FORMAT]

例如,以下命令通过导入文件 my-file 来更新政策 my-policy

gcloud compute security-policies import my-policy \
    --file-name my-file \
    --file-format json

如果导入时该政策的指纹已过期,则 Google Cloud Armor 会显示错误。这意味着该政策在上次导出后已被修改。如需解决此问题,请对该政策使用 describe 命令以获取最新的指纹。合并描述的政策和您的政策之间的任何差异,然后用最新的指纹替换过时的指纹。

导出安全政策

您可以使用 Google Cloud CLI 将 Google Cloud Armor 安全政策导出为 YAML 或 JSON 文件。导出政策后,您可以检索其副本,并在源代码控制系统中执行修改或保存操作。

gcloud

  1. 在以下命令中,NAME 是安全政策的名称。有效文件格式为 YAML 和 JSON。如果您不提供文件格式,则 Google Cloud Armor 会使用默认的 YAML。

    gcloud compute security-policies export NAME \
        --file-name FILE_NAME  \
        --file-format FILE_FORMAT
    

    以下示例将 my-policy 安全政策以 YAML 格式导出到 my-file 文件:

    gcloud compute security-policies export my-policy \
        --file-name my-file \
        --file-format yaml
     

    以下示例显示了导出的安全政策:

    description: my description
    fingerprint: PWfLGDWQDLY=
    id: '123'
    name: my-policy
    rules:
    - action: allow
      description: default rule
      match:
          config:
            srcIpRanges:
            - '*'
          versionedExpr: SRC_IPS_V1
        preview: false
        priority: 2147483647
      selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/my-policy
      
  2. 您可以使用任何文本编辑器修改导出的文件,然后使用 import 命令将其import回 Google Cloud。

列出可用的预配置规则

列出预配置规则以查看预定义的应用保护规则和签名,例如 Google Cloud Armor 提供的 ModSecurity 核心规则集。这些预配置规则包含多个内置签名,Google Cloud Armor 使用这些签名对传入请求进行评估。您可以使用自定义规则语言参考将这些预配置的规则添加到新规则或现有规则中。

如需了解详情,请参阅预配置的规则

gcloud

  1. 运行 gcloud compute security-policies list-preconfigured-expression-sets 命令:

    gcloud compute security-policies list-preconfigured-expression-sets
    

    以下示例显示了命令输出的形式:

    EXPRESSION_SET
    expression-set-1
       RULE_ID                SENSITIVITY
       expression-set-1-id-1  sensitivity-value-1
       expression-set-1-id-2  sensitivity-value-2
    expression-set-2
       alias-1
       RULE_ID                SENSITIVITY
       expression-set-2-id-1  sensitivity-value-1
       expression-set-2-id-2  sensitivity-value-2
    

    以下示例包含命令的实际输出示例。请注意,实际输出将包含调整 Google Cloud Armor WAF 规则中列出的所有规则。

    gcloud compute security-policies list-preconfigured-expression-sets
    
    EXPRESSION_SET
    sqli-canary
        RULE_ID                          SENSITIVITY
        owasp-crs-v030001-id942110-sqli  2
        owasp-crs-v030001-id942120-sqli  2
        …
    xss-canary
        RULE_ID                         SENSITIVITY
        owasp-crs-v030001-id941110-xss  1
        owasp-crs-v030001-id941120-xss  1
    …
    sourceiplist-fastly
    sourceiplist-cloudflare
    sourceiplist-imperva
    

后续步骤