【问题标题】:Google Cloud Armor - missing default ruleGoogle Cloud Armor - 缺少默认规则
【发布时间】:2020-06-09 11:21:40
【问题描述】:

我创建了一个云盔甲安全策略,但它没有默认规则。我很困惑,因为文档与此相矛盾。

https://cloud.google.com/compute/docs/reference/rest/beta/securityPolicies

属于此策略的规则列表。必须始终存在默认规则(优先级为 2147483647 并匹配“*”的规则)。如果在创建安全策略时没有提供任何规则,则会添加一个带有“允许”操作的默认规则。

$ gcloud beta compute security-policies describe healthcheck
---
creationTimestamp: ''
description: ''
fingerprint: ...
id: '.....'
kind: compute#securityPolicy
labelFingerprint: .....
name: healthcheck
rules:
- action: deny(404)
  description: Block requests to /health
  kind: compute#securityPolicyRule
  match:
    expr:
      expression: request.path.matches('/health')
  preview: false
  priority: 1000
selfLink: https://www.googleapis.com/compute/....

根据我的测试,默认行为似乎是Allow。这个默认规则是隐藏的还是我遗漏了什么?

规则是使用 Terraform 创建的,但我认为这并不重要。

【问题讨论】:

    标签: google-cloud-platform google-cloud-armor


    【解决方案1】:

    您的问题的答案在于创建 Cloud Armor 策略的方法有多种。例如,如果您通过 Cloud Console 创建策略,则需要在创建策略之前选择默认规则类型。

    在您的情况下,该策略是使用 Terraform 创建的。 Terraform 将以与使用 Cloud Shell 中的 gcloud 命令相同的方式有效地创建策略。使用 Terraform 之类的东西或使用 gcloud 命令将允许创建 Cloud Armor 策略无需指定默认规则。

    如果创建 Cloud Armor 策略时未指定规则(默认或其他),则会自动添加“允许”规则。这是您共享的 REST 资源 link 中记录的行为。需要注意的一件事是,可能需要几分钟才能看到默认的“允许”规则。在我的测试中,至少需要 2 分钟才能在控制台中看到并通过:

    gcloud compute security-policies describe [POLICY_NAME]
    

    通常在 Cloud Armor 策略创建期间,会指定默认规则以及所需的行为 (step # 2)。您共享的示例似乎尚未在控制台中完全更新,因此未显示默认的“允许”规则。但是,根据您为设置提供的描述,在 Terraform 创建策略期间将应用默认的“允许”规则。

    您始终可以使用以下命令将默认规则的行为从“允许”更改为“拒绝 404”(或“拒绝 502”):

    gcloud compute security-policies rules update 2147483647 --security-policy [POLICY_NAME]  --action "deny-404"
    

    (2147483647为默认规则优先级,max int32)

    【讨论】:

    • 感谢您的回答。这个默认规则似乎在那里,但对我来说是不可见的。几个小时过去了,我在 web ui 中看不到它,使用 gcloud 甚至 API 资源管理器 - cloud.google.com/compute/docs/reference/rest/beta/…
    • 另外,我认为文档不准确。 There must always be a default rule (rule with priority 2147483647 and match "*") 好吧,我看不到。也许它在那里,但 API 和 webui 并没有告诉我任何关于它的信息。这令人困惑。 If no rules are provided when creating a security policy, a default rule with action "allow" will be added. 再次令人困惑。我确实提供了一个规则。这不是优先级为 2147483647 的规则,但它仍然是规则。
    • 我完全理解文档的当前状态令人困惑。在您的情况下,默认规则将在那里。至于为什么不显示它可能是一个值得reporting 作为issue 的问题。 Terraform 创建 CA 策略的方式也可能导致此显示问题。 Point-in-context:我所做的测试是直接在控制台中完成的,我没有使用 Terraform。
    猜你喜欢
    • 2022-10-06
    • 2020-12-02
    • 2023-03-20
    • 1970-01-01
    • 2021-10-14
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多