Google Cloud Armor-缺少默认规则

问题描述 投票:1回答: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。这个默认规则是隐藏的还是我遗漏了什么?enter image description here

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

google-cloud-platform google-cloud-armor
1个回答
0
投票

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

在您的情况下,该策略是使用Terraform创建的。 Terraform将有效地创建策略,就像使用Cloud Shell中的gcloud命令一样。使用Terraform之类的命令或使用gcloud命令将允许创建Cloud Armor策略without指定的默认规则。

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

gcloud compute security-policies describe [POLICY_NAME]

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.