diff --git a/docs/gcp-install/3-EDGE-HARDENING.md b/docs/gcp-install/3-EDGE-HARDENING.md index c9055d05..696c65bf 100644 --- a/docs/gcp-install/3-EDGE-HARDENING.md +++ b/docs/gcp-install/3-EDGE-HARDENING.md @@ -293,9 +293,28 @@ Cloudflare can reach it. the secret header, the two WAF rules and the sign-in and staff rules, about 13 are left: roughly 100 vendor ranges. Terraform refuses a plan that needs more and says how many it counted (`rule_counts` in the `edge` - output shows the same). For a vendor that publishes more, merge adjacent - ranges where you accept the wider block, or enforce that vendor's list as - a Cloudflare WAF custom rule and keep only your own ranges here. + output shows the same). For a vendor that publishes more, there are two + ways: + + - **An address group** (needs Cloud Armor Enterprise, which is billed and + takes up to an hour to activate). The whole list then counts as one + entry in one rule: + + ```sh + gcloud compute project-info update --cloud-armor-tier CA_ENTERPRISE_PAYGO + gcloud network-security address-groups create agent-relay-vendor-a --location global \ + --type IPv4 --capacity 600 --purpose CLOUD_ARMOR + gcloud network-security address-groups add-items agent-relay-vendor-a --location global \ + --items ,,... + ``` + + and in the rule, add `address_groups = ["agent-relay-vendor-a"]` and + remove only that vendor's ranges from `cidrs`. Keep your own ranges + there (`cidrs = [""]`): the rule denies everyone it does not + list, so without them your users' uploads would get 403. When the vendor changes its list, update the + group with `add-items` and `remove-items`; Terraform is not involved. + - **A Cloudflare WAF custom rule** for that vendor's list, keeping only + your own ranges here. No extra Google cost. The project also has a limit of 20 such rules across all its policies (`SECURITY_POLICY_CEVAL_RULES`). That one can be raised, and a request was diff --git a/terraform/modules/gcp/edge-security/README.md b/terraform/modules/gcp/edge-security/README.md index 2fd03282..591a24b0 100644 --- a/terraform/modules/gcp/edge-security/README.md +++ b/terraform/modules/gcp/edge-security/README.md @@ -138,7 +138,47 @@ With the secret header, two WAF rules and sign-in and staff rules, about 13 rule - **merge ranges**: published lists often contain adjacent blocks that one wider CIDR covers; a wider block also admits the addresses in between, so this is your decision to make; - **enforce the long list at the fronting proxy** (a Cloudflare WAF custom rule sees the same client address and has no such limit) and keep only your own short ranges in `client_ip_rules`; -- Cloud Armor Enterprise address groups, which this module does not support. +- **address groups** (Cloud Armor Enterprise): a named list that counts as one subexpression whatever its size. See the next section. + +### Long vendor lists: address groups + +An address group is a project resource holding a list of ranges. A rule that names it spends one subexpression on the whole list, so a vendor's 300 published ranges cost one admitting rule and one deny, where plain `cidrs` would need more rules than a policy holds. + +**It needs Cloud Armor Enterprise**, which is billed per project and can take up to an hour to become active: + +```sh +gcloud compute project-info describe --format='value(cloudArmorTier)' # CA_STANDARD or CA_ENTERPRISE_PAYGO +gcloud compute project-info update --cloud-armor-tier CA_ENTERPRISE_PAYGO +``` + +Create the group with `gcloud` and name it in the rule. This module does not create it: the Google provider below 8.0, which this repository pins, cannot set the group's purpose to `CLOUD_ARMOR`. + +```sh +gcloud network-security address-groups create relay-vendor-a --location global \ + --type IPv4 --capacity 600 --purpose CLOUD_ARMOR --description "Vendor A published ranges" +gcloud network-security address-groups add-items relay-vendor-a --location global \ + --items 192.0.2.0/24,198.51.100.0/24 +``` + +```hcl +client_ip_rules = [{ + name = "vendors" + hosts = ["history.relay.example.com"] + path_prefixes = ["/v1/delivery", "/v1/turns", "/v1/auth/token/refresh"] + address_groups = ["relay-vendor-a"] # the group's name, not its full path + cidrs = ["203.0.113.0/24"] # your own ranges can stay inline + rate_limit = { count = 600, interval_sec = 60 } +}] +``` + +- `capacity` is fixed when the group is created: leave room for the vendor adding ranges. +- When the vendor's list changes, update the group with `add-items` and `remove-items`. No Terraform apply is needed, and the policy does not change. +- The group must exist before `terraform apply`, and must not be deleted while a rule names it. +- IPv4 and IPv6 ranges need separate groups. +- The rule is `evaluateAddressGroup('', origin.user_ip)`: the client address from the proxy's header, as for `cidrs`. +- With Enterprise you can also put the proxy's own ranges in a group and name it in `connecting_address_groups`, in place of `connecting_asns`. + +This path is tested by rendering only. It has not yet been applied to a project enrolled in Cloud Armor Enterprise. If the project quota (not the per-policy limit) is the one you hit, the apply fails part-way with: @@ -196,7 +236,7 @@ Regular expressions must not contain capture groups: Cloud Armor refuses `(a|b)` | max\_advanced\_rules | Rules with an expression that one Cloud Armor policy may hold. Google fixes this at 20 per policy (quota SECURITY\_POLICY\_ADVANCED\_RULES\_PER\_SECURITY\_POLICY, not adjustable), so a plan that needs more is refused here instead of failing half-way through the apply. Change it only if Google has given your project a different limit. | `number` | `20` | no | | max\_subexpressions | Subexpressions in one rule expression. Cloud Armor accepts 10 and refuses 11 (measured against the API; the rules language reference still says 5). A rule that matches a path (and host) and a list of client ranges uses one (two) for the match and the rest for ranges, so fewer means more rules for the same list. Lower it only if your project's API refuses a rule. | `number` | `10` | no | | origin\_secret\_header | Optional shared-secret request header a fronting proxy adds on every request (for Cloudflare: a request header transform rule). Requests without the exact value are denied 403 before any other rule, which proves the request came through the proxy and makes its client-address header trustworthy. values lists every accepted value (1 to 3), so a rotation has no outage: add the new value here and apply, switch the proxy to it, then remove the old value and apply. The values are stored in Terraform state and readable in the Cloud Armor policy by anyone with compute.securityPolicies.get: treat both as secret stores. | ```object({ name = string values = list(string) })``` | `null` | no | -| security\_policy | Cloud Armor backend security policy (chart value gkeIngress.securityPolicy), off unless create = true. - waf: preconfigured OWASP rules (deny 403) at the given sensitivity (1 = fewest false positives). preview = true (the default) only logs matches: session transcripts and messages carry code, SQL and shell text, so read the logs before enforcing. - rate\_limits: per-client throttle (429) on the listed path regexes; the default covers password sign-in, setup-key and login paths. - source\_ip\_allowlist: when non-empty (or cloudflare.enabled), the default rule becomes deny 403 and only these connecting addresses are admitted: a pure source-IP allowlist. - cloudflare: admit Cloudflare's published ranges as the connecting addresses (origin lockdown) and read the client address from CF-Connecting-IP. - client\_ip\_header: header an upstream proxy sets with the real client address (Cloud Armor origin.user\_ip). Only trustworthy when nothing but that proxy can reach the load balancer: combine with an allowlist of the proxy's ranges, or origin\_secret\_header. - client\_ip\_rules: per-client allowlists scoped to paths (and optionally hosts), evaluated in list order. The first rule whose path\_prefixes (and hosts, when given) match a request decides it: admitted if the client address (origin.user\_ip) is in cidrs, denied 403 otherwise. A last rule with path\_prefixes = ["/"] therefore closes every other path to everyone but its cidrs. Requires origin\_secret\_header. An admitted request meets no later rule, including rate\_limits, so every rule states its own limit: rate\_limit (requests per interval per client address), or unthrottled = true. With a rule for "/" set rate\_limits = [] and express sign-in limits as an earlier, narrower rule. - connecting\_asns, connecting\_address\_groups: where the fronting proxy connects from, as autonomous system numbers (Cloudflare: 13335) or names of existing Cloud Armor address groups holding its ranges (Cloud Armor Enterprise). A connection from anywhere else is denied 403 right after the secret-header check. client\_ip\_rules require one of them: a request those rules admit is not checked against the allowlist of connecting addresses, so otherwise a caller that holds the secret header could skip the proxy and choose its own client address. secret\_header\_only = true accepts that instead. - adaptive\_protection: Layer 7 DDoS detection (alerts; automatic deployment needs Cloud Armor Enterprise). | ```object({ create = optional(bool, false) waf = optional(object({ enabled = optional(bool, true) preview = optional(bool, true) sensitivity = optional(number, 1) rules = optional(list(string), [ "sqli-v33-stable", "xss-v33-stable", "lfi-v33-stable", "rfi-v33-stable", "rce-v33-stable", "scannerdetection-v33-stable", "protocolattack-v33-stable", "sessionfixation-v33-stable", "cve-canary", ]) }), {}) rate_limits = optional(list(object({ name = string path_regex = string count = number interval_sec = number ban_duration_sec = optional(number, 0) })), [{ name = "sign-in" path_regex = "^/(?:login|(?:cloud/)?api/v1/auth/)" count = 60 interval_sec = 60 }]) source_ip_allowlist = optional(list(string), []) cloudflare = optional(object({ enabled = optional(bool, false) include_ipv6 = optional(bool, false) # https://www.cloudflare.com/ips/ as read on 2026-11-18. Cloudflare # announces changes; compare the list with that page before each apply. ipv4_cidrs = optional(list(string), [ "173.245.48.0/20", "103.21.244.0/22", "103.22.200.0/22", "103.31.4.0/22", "141.101.64.0/18", "108.162.192.0/18", "190.93.240.0/20", "188.114.96.0/20", "197.234.240.0/22", "198.41.128.0/17", "162.158.0.0/15", "104.16.0.0/13", "104.24.0.0/14", "172.64.0.0/13", "131.0.72.0/22", ]) ipv6_cidrs = optional(list(string), [ "2400:cb00::/32", "2606:4700::/32", "2803:f800::/32", "2405:b500::/32", "2405:8100::/32", "2a06:98c0::/29", "2c0f:f248::/32", ]) }), {}) client_ip_header = optional(string) connecting_asns = optional(list(number), []) connecting_address_groups = optional(list(string), []) secret_header_only = optional(bool, false) client_ip_rules = optional(list(object({ name = string path_prefixes = list(string) hosts = optional(list(string), []) cidrs = list(string) rate_limit = optional(object({ count = number, interval_sec = number })) unthrottled = optional(bool, false) })), []) adaptive_protection = optional(bool, false) })``` | `{}` | no | +| security\_policy | Cloud Armor backend security policy (chart value gkeIngress.securityPolicy), off unless create = true. - waf: preconfigured OWASP rules (deny 403) at the given sensitivity (1 = fewest false positives). preview = true (the default) only logs matches: session transcripts and messages carry code, SQL and shell text, so read the logs before enforcing. - rate\_limits: per-client throttle (429) on the listed path regexes; the default covers password sign-in, setup-key and login paths. - source\_ip\_allowlist: when non-empty (or cloudflare.enabled), the default rule becomes deny 403 and only these connecting addresses are admitted: a pure source-IP allowlist. - cloudflare: admit Cloudflare's published ranges as the connecting addresses (origin lockdown) and read the client address from CF-Connecting-IP. - client\_ip\_header: header an upstream proxy sets with the real client address (Cloud Armor origin.user\_ip). Only trustworthy when nothing but that proxy can reach the load balancer: combine with an allowlist of the proxy's ranges, or origin\_secret\_header. - client\_ip\_rules: per-client allowlists scoped to paths (and optionally hosts), evaluated in list order. The first rule whose path\_prefixes (and hosts, when given) match a request decides it: admitted if the client address (origin.user\_ip) is in cidrs, denied 403 otherwise. A last rule with path\_prefixes = ["/"] therefore closes every other path to everyone but its cidrs. Requires origin\_secret\_header. A rule lists its clients as cidrs, as address\_groups, or both. address\_groups are names of existing project-scoped Cloud Armor address groups (purpose CLOUD\_ARMOR, created outside this module; needs Cloud Armor Enterprise): each is one subexpression whatever its size, so a vendor's long published list fits in one rule. An admitted request meets no later rule, including rate\_limits, so every rule states its own limit: rate\_limit (requests per interval per client address), or unthrottled = true. With a rule for "/" set rate\_limits = [] and express sign-in limits as an earlier, narrower rule. - connecting\_asns, connecting\_address\_groups: where the fronting proxy connects from, as autonomous system numbers (Cloudflare: 13335) or names of existing Cloud Armor address groups holding its ranges (Cloud Armor Enterprise). A connection from anywhere else is denied 403 right after the secret-header check. client\_ip\_rules require one of them: a request those rules admit is not checked against the allowlist of connecting addresses, so otherwise a caller that holds the secret header could skip the proxy and choose its own client address. secret\_header\_only = true accepts that instead. - adaptive\_protection: Layer 7 DDoS detection (alerts; automatic deployment needs Cloud Armor Enterprise). | ```object({ create = optional(bool, false) waf = optional(object({ enabled = optional(bool, true) preview = optional(bool, true) sensitivity = optional(number, 1) rules = optional(list(string), [ "sqli-v33-stable", "xss-v33-stable", "lfi-v33-stable", "rfi-v33-stable", "rce-v33-stable", "scannerdetection-v33-stable", "protocolattack-v33-stable", "sessionfixation-v33-stable", "cve-canary", ]) }), {}) rate_limits = optional(list(object({ name = string path_regex = string count = number interval_sec = number ban_duration_sec = optional(number, 0) })), [{ name = "sign-in" path_regex = "^/(?:login|(?:cloud/)?api/v1/auth/)" count = 60 interval_sec = 60 }]) source_ip_allowlist = optional(list(string), []) cloudflare = optional(object({ enabled = optional(bool, false) include_ipv6 = optional(bool, false) # https://www.cloudflare.com/ips/ as read on 2026-11-18. Cloudflare # announces changes; compare the list with that page before each apply. ipv4_cidrs = optional(list(string), [ "173.245.48.0/20", "103.21.244.0/22", "103.22.200.0/22", "103.31.4.0/22", "141.101.64.0/18", "108.162.192.0/18", "190.93.240.0/20", "188.114.96.0/20", "197.234.240.0/22", "198.41.128.0/17", "162.158.0.0/15", "104.16.0.0/13", "104.24.0.0/14", "172.64.0.0/13", "131.0.72.0/22", ]) ipv6_cidrs = optional(list(string), [ "2400:cb00::/32", "2606:4700::/32", "2803:f800::/32", "2405:b500::/32", "2405:8100::/32", "2a06:98c0::/29", "2c0f:f248::/32", ]) }), {}) client_ip_header = optional(string) connecting_asns = optional(list(number), []) connecting_address_groups = optional(list(string), []) secret_header_only = optional(bool, false) client_ip_rules = optional(list(object({ name = string path_prefixes = list(string) hosts = optional(list(string), []) cidrs = optional(list(string), []) address_groups = optional(list(string), []) rate_limit = optional(object({ count = number, interval_sec = number })) unthrottled = optional(bool, false) })), []) adaptive_protection = optional(bool, false) })``` | `{}` | no | | ssl\_policy | Compute SSL policy for the load balancer's HTTPS listener (chart value gkeIngress.sslPolicy). MODERN with TLS 1.2 serves current browsers, the desktop app and CLIs; RESTRICTED narrows the cipher list further (TLS 1.2 minimum is required by it). | ```object({ create = optional(bool, true) profile = optional(string, "MODERN") min_tls_version = optional(string, "TLS_1_2") })``` | `{}` | no | ### Outputs diff --git a/terraform/modules/gcp/edge-security/main.tf b/terraform/modules/gcp/edge-security/main.tf index 24d8e126..7917f4f6 100644 --- a/terraform/modules/gcp/edge-security/main.tf +++ b/terraform/modules/gcp/edge-security/main.tf @@ -42,14 +42,22 @@ locals { # and everyone else on those paths is denied. A Cloud Armor rule that admits # ends evaluation, so admitted requests meet no later rule: that is why each # rule states its own limit and why the secret header rule must come first. - client_groups = { for r in local.sp.client_ip_rules : r.name => chunklist(r.cidrs, var.max_subexpressions - (length(r.hosts) > 0 ? 2 : 1)) } + # A rule's clients are terms: one per address group (a single subexpression + # for the whole list) and one per CIDR. Address groups are existing project + # resources named here; the google provider below 8.0 cannot create one with + # purpose CLOUD_ARMOR, so they are made with gcloud (README). + client_terms = { for r in local.sp.client_ip_rules : r.name => concat( + [for g in r.address_groups : "evaluateAddressGroup('${g}', origin.user_ip)"], + [for c in r.cidrs : "inIpRange(origin.user_ip, '${c}')"], + ) } + client_groups = { for r in local.sp.client_ip_rules : r.name => chunklist(local.client_terms[r.name], var.max_subexpressions - (length(r.hosts) > 0 ? 2 : 1)) } client_rules = merge([for i, r in local.sp.client_ip_rules : merge({ for j, group in local.client_groups[r.name] : "${r.name}-allow-${j}" => { priority = 10000 + i * 1000 + j action = r.rate_limit == null ? "allow" : "throttle" rate = { count = try(r.rate_limit.count, 0), interval_sec = try(r.rate_limit.interval_sec, 0) } description = "${r.name}: listed client addresses on ${join(", ", concat(r.hosts, r.path_prefixes))}" - expression = "${local.path_match[r.name]} && (${join(" || ", [for c in group : "inIpRange(origin.user_ip, '${c}')"])})" + expression = "${local.path_match[r.name]} && (${join(" || ", group)})" } }, { "${r.name}-deny" = { priority = 10000 + i * 1000 + 999 diff --git a/terraform/modules/gcp/edge-security/tests/edge_security.tftest.hcl b/terraform/modules/gcp/edge-security/tests/edge_security.tftest.hcl index c1c16a8b..b49197bb 100644 --- a/terraform/modules/gcp/edge-security/tests/edge_security.tftest.hcl +++ b/terraform/modules/gcp/edge-security/tests/edge_security.tftest.hcl @@ -705,3 +705,73 @@ run "connecting_address_group_denies_other_sources_first" { error_message = "A connection whose address is outside the proxy's address group is denied before any client rule." } } + +# Address groups (Cloud Armor Enterprise): a vendor's whole list is one +# subexpression, so the rule needs one admitting rule and its deny. +run "address_group_keeps_a_long_vendor_list_in_one_rule" { + command = apply + variables { + max_subexpressions = 10 + max_advanced_rules = 20 + security_policy = { + create = true + cloudflare = { enabled = true } + connecting_address_groups = ["relay-cloudflare"] + rate_limits = [] + client_ip_rules = [ + { + name = "vendors" + hosts = ["history.relay.example.com"] + path_prefixes = ["/v1/delivery"] + address_groups = ["relay-vendor-a", "relay-vendor-b"] + cidrs = ["203.0.113.0/24"] + rate_limit = { count = 600, interval_sec = 60 } + }, + { name = "staff", path_prefixes = ["/"], cidrs = ["203.0.113.0/24"], unthrottled = true }, + ] + } + origin_secret_header = { name = "x-origin-auth", values = ["0123456789abcdef0123456789abcdef"] } + } + + assert { + condition = google_compute_security_policy_rule.client_ip["vendors-allow-0"].match[0].expr[0].expression == "request.headers['host'].lower().matches('^(?:history\\\\.relay\\\\.example\\\\.com)(?::[0-9]+)?$') && request.path.matches('^(?:/v1/delivery)(?:/|$)') && (evaluateAddressGroup('relay-vendor-a', origin.user_ip) || evaluateAddressGroup('relay-vendor-b', origin.user_ip) || inIpRange(origin.user_ip, '203.0.113.0/24'))" + error_message = "Each address group is one subexpression, evaluated against the client address, ahead of the plain ranges." + } + assert { + condition = length([for k, r in google_compute_security_policy_rule.client_ip : k if startswith(k, "vendors-")]) == 2 && output.rule_counts.advanced == 8 + error_message = "One admitting rule and one deny for the vendors, whatever the groups hold: 8 advanced rules in all (secret header, connecting check, two WAF, vendors 2, staff 2)." + } +} + +run "address_group_only_rule_is_valid" { + command = apply + variables { + security_policy = { + create = true + cloudflare = { enabled = true } + secret_header_only = true + client_ip_rules = [{ name = "vendors", path_prefixes = ["/v1/delivery"], address_groups = ["relay-vendor-a"], unthrottled = true }] + } + origin_secret_header = { name = "x-origin-auth", values = ["0123456789abcdef0123456789abcdef"] } + } + assert { + condition = google_compute_security_policy_rule.client_ip["vendors-allow-0"].match[0].expr[0].expression == "request.path.matches('^(?:/v1/delivery)(?:/|$)') && (evaluateAddressGroup('relay-vendor-a', origin.user_ip))" + error_message = "A rule may list only address groups." + } +} + +run "rule_without_clients_refused" { + command = plan + variables { + security_policy = { create = true, cloudflare = { enabled = true }, secret_header_only = true, client_ip_rules = [{ name = "vendors", path_prefixes = ["/v1/delivery"], unthrottled = true }] } + } + expect_failures = [var.security_policy] +} + +run "address_group_path_instead_of_name_refused" { + command = plan + variables { + security_policy = { create = true, cloudflare = { enabled = true }, secret_header_only = true, client_ip_rules = [{ name = "vendors", path_prefixes = ["/v1/delivery"], address_groups = ["projects/p/locations/global/addressGroups/relay-vendor-a"], unthrottled = true }] } + } + expect_failures = [var.security_policy] +} diff --git a/terraform/modules/gcp/edge-security/variables.tf b/terraform/modules/gcp/edge-security/variables.tf index a3417853..d55d9b09 100644 --- a/terraform/modules/gcp/edge-security/variables.tf +++ b/terraform/modules/gcp/edge-security/variables.tf @@ -45,7 +45,7 @@ variable "security_policy" { - source_ip_allowlist: when non-empty (or cloudflare.enabled), the default rule becomes deny 403 and only these connecting addresses are admitted: a pure source-IP allowlist. - cloudflare: admit Cloudflare's published ranges as the connecting addresses (origin lockdown) and read the client address from CF-Connecting-IP. - client_ip_header: header an upstream proxy sets with the real client address (Cloud Armor origin.user_ip). Only trustworthy when nothing but that proxy can reach the load balancer: combine with an allowlist of the proxy's ranges, or origin_secret_header. - - client_ip_rules: per-client allowlists scoped to paths (and optionally hosts), evaluated in list order. The first rule whose path_prefixes (and hosts, when given) match a request decides it: admitted if the client address (origin.user_ip) is in cidrs, denied 403 otherwise. A last rule with path_prefixes = ["/"] therefore closes every other path to everyone but its cidrs. Requires origin_secret_header. An admitted request meets no later rule, including rate_limits, so every rule states its own limit: rate_limit (requests per interval per client address), or unthrottled = true. With a rule for "/" set rate_limits = [] and express sign-in limits as an earlier, narrower rule. + - client_ip_rules: per-client allowlists scoped to paths (and optionally hosts), evaluated in list order. The first rule whose path_prefixes (and hosts, when given) match a request decides it: admitted if the client address (origin.user_ip) is in cidrs, denied 403 otherwise. A last rule with path_prefixes = ["/"] therefore closes every other path to everyone but its cidrs. Requires origin_secret_header. A rule lists its clients as cidrs, as address_groups, or both. address_groups are names of existing project-scoped Cloud Armor address groups (purpose CLOUD_ARMOR, created outside this module; needs Cloud Armor Enterprise): each is one subexpression whatever its size, so a vendor's long published list fits in one rule. An admitted request meets no later rule, including rate_limits, so every rule states its own limit: rate_limit (requests per interval per client address), or unthrottled = true. With a rule for "/" set rate_limits = [] and express sign-in limits as an earlier, narrower rule. - connecting_asns, connecting_address_groups: where the fronting proxy connects from, as autonomous system numbers (Cloudflare: 13335) or names of existing Cloud Armor address groups holding its ranges (Cloud Armor Enterprise). A connection from anywhere else is denied 403 right after the secret-header check. client_ip_rules require one of them: a request those rules admit is not checked against the allowlist of connecting addresses, so otherwise a caller that holds the secret header could skip the proxy and choose its own client address. secret_header_only = true accepts that instead. - adaptive_protection: Layer 7 DDoS detection (alerts; automatic deployment needs Cloud Armor Enterprise). EOT @@ -93,12 +93,13 @@ variable "security_policy" { connecting_address_groups = optional(list(string), []) secret_header_only = optional(bool, false) client_ip_rules = optional(list(object({ - name = string - path_prefixes = list(string) - hosts = optional(list(string), []) - cidrs = list(string) - rate_limit = optional(object({ count = number, interval_sec = number })) - unthrottled = optional(bool, false) + name = string + path_prefixes = list(string) + hosts = optional(list(string), []) + cidrs = optional(list(string), []) + address_groups = optional(list(string), []) + rate_limit = optional(object({ count = number, interval_sec = number })) + unthrottled = optional(bool, false) })), []) adaptive_protection = optional(bool, false) }) @@ -127,12 +128,12 @@ variable "security_policy" { } validation { condition = alltrue([for r in var.security_policy.client_ip_rules : - can(regex("^[a-z0-9]([-a-z0-9]{0,30}[a-z0-9])?$", r.name)) && length(r.cidrs) >= 1 && length(r.cidrs) <= 2500 && + can(regex("^[a-z0-9]([-a-z0-9]{0,30}[a-z0-9])?$", r.name)) && length(r.cidrs) + length(r.address_groups) >= 1 && length(r.cidrs) <= 2500 && length(r.address_groups) <= 8 && alltrue([for g in r.address_groups : can(regex("^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$", g))]) && length(r.path_prefixes) >= 1 && alltrue([for p in r.path_prefixes : can(regex("^/[A-Za-z0-9/._~-]*$", p))]) && alltrue([for h in r.hosts : can(regex("^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$", h))]) && (r.rate_limit == null ? true : r.rate_limit.count >= 1 && contains([10, 30, 60, 120, 180, 240, 300, 600, 900, 1200, 1800, 2700, 3600], r.rate_limit.interval_sec)) ]) && length(var.security_policy.client_ip_rules) <= 9 && length(distinct(var.security_policy.client_ip_rules[*].name)) == length(var.security_policy.client_ip_rules) - error_message = "At most 9 client_ip_rules with unique lowercase names, 1-2500 cidrs, path_prefixes that start with / and hold only unreserved URL characters, lowercase DNS hosts, and a rate_limit with count >= 1 and an interval_sec Cloud Armor accepts." + error_message = "At most 9 client_ip_rules with unique lowercase names, at least one of cidrs (up to 2500) or address_groups (up to 8 names, not full paths), path_prefixes that start with / and hold only unreserved URL characters, lowercase DNS hosts, and a rate_limit with count >= 1 and an interval_sec Cloud Armor accepts." } validation { condition = length(var.security_policy.connecting_asns) + length(var.security_policy.connecting_address_groups) <= 8 && alltrue([for a in var.security_policy.connecting_asns : a >= 1 && a <= 4294967295 && floor(a) == a]) && alltrue([for g in var.security_policy.connecting_address_groups : can(regex("^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$", g))])