feat(edge-security): client rules can name Cloud Armor address groups

Merged
MI
2d ago
+154-16

Stacked on #487 (base branch fix/edge-armor-quota). Review this diff on its own; it retargets to main when #487 merges.

Why

The live proof showed that one Cloud Armor policy holds at most 20 rules with an expression, and Google does not raise that limit (#487 makes the module refuse such a plan). A vendor's long published list, about 290 ranges, therefore cannot be written as CIDRs in client_ip_rules: it needs about 37 rules, and an exact merge of adjacent ranges only brings 289 down to 278.

A Cloud Armor address group is one subexpression in a rule whatever it holds, so the whole list costs one admitting rule and one deny.

What changes

  • client_ip_rules[*].address_groups: names of existing project-scoped address groups. Each becomes evaluateAddressGroup('<name>', origin.user_ip) in the rule, ahead of any inline cidrs. A rule needs at least one of cidrs or address_groups; cidrs is now optional.
  • Validation: at most 8 groups per rule, short names only (a full resource path is refused, with the reason).
  • rule_counts reflects it: the vendor rule in the test costs 2 advanced rules.
  • Docs: module README "Long vendor lists: address groups" and item 5 of docs/gcp-install/3-EDGE-HARDENING.md: the Enterprise enrollment command, the gcloud commands to create and fill a group, and how to update it when the vendor's list changes (no Terraform apply).

Why the module does not create the group

A Cloud Armor address group needs purpose = ["CLOUD_ARMOR"]. google_network_security_address_group only has that field from provider 8.x; this repository pins >= 7.0, < 8.0, and 7.46.2 rejects it (An argument named "purpose" is not expected here). Moving the repository to provider 8 is a separate decision. Until then the group is created with gcloud, which also suits how it is used: a vendor's list changes without the policy changing.

What it costs and requires

Address groups need the project enrolled in Cloud Armor Enterprise, which is billed and can take up to an hour to activate. The docs say so before the commands. Nothing in this PR enrolls anything.

Tests

terraform test (mock provider), 33 runs: the exact expression with two groups and an inline range; a group-only rule; a rule with no clients refused; a full path instead of a name refused; with 10 subexpressions and the 20-rule limit, vendors by address group plus a closing staff rule need 7 advanced rules. Local: terraform fmt/validate/test, tflint, terraform-docs and checkov pass. No chart change.

Not proven

Rendering only. Not yet applied to a project enrolled in Cloud Armor Enterprise: that evaluateAddressGroup accepts the short name with origin.user_ip in a backend policy rule (it is the form in Google's documentation), and the exact gcloud network-security address-groups flags. The proof project is on the Standard tier today.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.