1

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

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 创建的,但我认为这并不重要。

4

1 回答 1

0

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

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

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

gcloud compute security-policies describe [POLICY_NAME]

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

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

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

(2147483647 是默认规则优先级,最大 int32)

于 2020-02-25T18:28:48.953 回答