Add support for URL filtering profiles to FAST NGFW add-on (#3768)

* add support for URL filtering profiles to FAST NGFW add-on

* fix YAML linting, add yamllint to pre-commit
This commit is contained in:
Ludovico Magnocavallo
2026-02-26 11:54:44 +01:00
committed by GitHub
parent 99e27b988e
commit 0eb171b21e
6 changed files with 293 additions and 15 deletions

View File

@@ -198,6 +198,18 @@ security_profiles = {
}
}
}
url_filtering_profile = {
allow-example = {
action = "ALLOW"
priority = 100
urls = ["example.com"]
}
deny-all = {
action = "DENY"
priority = 200
# urls defaults to ["*"]
}
}
}
}
tls_inspection_policies = {
@@ -271,8 +283,8 @@ Security profiles group defined here are exported via output variable file, and
| [host_project_ids](variables-fast.tf#L48) | Networking stage host project id aliases. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> | <code>2-networking</code> |
| [names](variables.tf#L104) | Configuration for names used for output files. | <code title="object&#40;&#123;&#10; output_files_prefix &#61; optional&#40;string, &#34;2-networking-ngfw&#34;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>&#123;&#125;</code> | |
| [outputs_location](variables.tf#L128) | Path where providers and tfvars files for the following stages are written. Leave empty to disable. | <code>string</code> | | <code>null</code> | |
| [security_profiles](variables.tf#L140) | Security profile groups for Layer 7 inspection. Null environment list means all environments. | <code title="map&#40;object&#40;&#123;&#10; description &#61; optional&#40;string&#41;&#10; threat_prevention_profile &#61; optional&#40;object&#40;&#123;&#10; severity_overrides &#61; optional&#40;map&#40;object&#40;&#123;&#10; action &#61; string&#10; severity &#61; string&#10; &#125;&#41;&#41;&#41;&#10; threat_overrides &#61; optional&#40;map&#40;object&#40;&#123;&#10; action &#61; string&#10; threat_id &#61; string&#10; &#125;&#41;&#41;&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code title="&#123;&#10; ngfw-default &#61; &#123;&#125;&#10;&#125;">&#123;&#8230;&#125;</code> | |
| [tls_inspection_policies](variables.tf#L182) | TLS inspection policies configuration. CA pools, trust configs and host project ids support interpolation. | <code title="map&#40;object&#40;&#123;&#10; ca_pool_id &#61; string&#10; location &#61; string&#10; exclude_public_ca_set &#61; optional&#40;bool&#41;&#10; trust_config &#61; optional&#40;string&#41;&#10; tls &#61; optional&#40;object&#40;&#123;&#10; custom_features &#61; optional&#40;list&#40;string&#41;&#41;&#10; feature_profile &#61; optional&#40;string&#41;&#10; min_version &#61; optional&#40;string&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> | |
| [trust_configs](variables.tf#L224) | Certificate Manager trust configurations for TLS inspection policies. Project ids and region can reference keys in the relevant FAST variables. | <code title="map&#40;object&#40;&#123;&#10; location &#61; string&#10; description &#61; optional&#40;string&#41;&#10; allowlisted_certificates &#61; optional&#40;map&#40;string&#41;&#41;&#10; trust_stores &#61; optional&#40;map&#40;object&#40;&#123;&#10; intermediate_cas &#61; optional&#40;map&#40;string&#41;&#41;&#10; trust_anchors &#61; optional&#40;map&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code title="&#123;&#10;&#125;">&#123;&#8230;&#125;</code> | |
| [security_profiles](variables.tf#L140) | Security profile groups for Layer 7 inspection. Null environment list means all environments. | <code title="map&#40;object&#40;&#123;&#10; description &#61; optional&#40;string&#41;&#10; threat_prevention_profile &#61; optional&#40;object&#40;&#123;&#10; severity_overrides &#61; optional&#40;map&#40;object&#40;&#123;&#10; action &#61; string&#10; severity &#61; string&#10; &#125;&#41;&#41;&#41;&#10; threat_overrides &#61; optional&#40;map&#40;object&#40;&#123;&#10; action &#61; string&#10; threat_id &#61; string&#10; &#125;&#41;&#41;&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10; url_filtering_profile &#61; optional&#40;map&#40;object&#40;&#123;&#10; action &#61; string&#10; priority &#61; number&#10; urls &#61; optional&#40;list&#40;string&#41;, &#91;&#34;&#42;&#34;&#93;&#41;&#10; &#125;&#41;&#41;, &#123;&#125;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code title="&#123;&#10; ngfw-default &#61; &#123;&#125;&#10;&#125;">&#123;&#8230;&#125;</code> | |
| [tls_inspection_policies](variables.tf#L223) | TLS inspection policies configuration. CA pools, trust configs and host project ids support interpolation. | <code title="map&#40;object&#40;&#123;&#10; ca_pool_id &#61; string&#10; location &#61; string&#10; exclude_public_ca_set &#61; optional&#40;bool&#41;&#10; trust_config &#61; optional&#40;string&#41;&#10; tls &#61; optional&#40;object&#40;&#123;&#10; custom_features &#61; optional&#40;list&#40;string&#41;&#41;&#10; feature_profile &#61; optional&#40;string&#41;&#10; min_version &#61; optional&#40;string&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> | |
| [trust_configs](variables.tf#L265) | Certificate Manager trust configurations for TLS inspection policies. Project ids and region can reference keys in the relevant FAST variables. | <code title="map&#40;object&#40;&#123;&#10; location &#61; string&#10; description &#61; optional&#40;string&#41;&#10; allowlisted_certificates &#61; optional&#40;map&#40;string&#41;&#41;&#10; trust_stores &#61; optional&#40;map&#40;object&#40;&#123;&#10; intermediate_cas &#61; optional&#40;map&#40;string&#41;&#41;&#10; trust_anchors &#61; optional&#40;map&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code title="&#123;&#10;&#125;">&#123;&#8230;&#125;</code> | |
| [vpc_self_links](variables-fast.tf#L66) | VPC network self links. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> | <code>2-networking</code> |
<!-- END TFDOC -->

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,9 +25,14 @@ locals {
)
})
}
url_filtering_profiles = {
for k, v in var.security_profiles : k => v.url_filtering_profile
if v.url_filtering_profile != {}
}
}
resource "google_network_security_security_profile" "default" {
provider = google-beta
for_each = local.security_profiles
name = each.key
description = each.value.description
@@ -56,11 +61,41 @@ resource "google_network_security_security_profile" "default" {
}
}
resource "google_network_security_security_profile_group" "default" {
for_each = var.security_profiles
name = each.key
description = each.value.description
parent = "organizations/${var.organization.id}"
location = "global"
threat_prevention_profile = google_network_security_security_profile.default[each.key].id
resource "google_network_security_security_profile" "url_filtering" {
provider = google-beta
for_each = local.url_filtering_profiles
name = "url-${each.key}"
description = var.security_profiles[each.key].description
parent = "organizations/${var.organization.id}"
location = "global"
type = "URL_FILTERING"
dynamic "url_filtering_profile" {
for_each = length(each.value) > 0 ? [""] : []
content {
dynamic "url_filters" {
for_each = each.value
content {
filtering_action = url_filters.value.action
priority = url_filters.value.priority
urls = url_filters.value.urls
}
}
}
}
}
resource "google_network_security_security_profile_group" "default" {
provider = google-beta
for_each = var.security_profiles
name = each.key
description = each.value.description
parent = "organizations/${var.organization.id}"
location = "global"
threat_prevention_profile = (
google_network_security_security_profile.default[each.key].id
)
url_filtering_profile = try(
google_network_security_security_profile.url_filtering[each.key].id,
null
)
}

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2024 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -151,6 +151,11 @@ variable "security_profiles" {
threat_id = string
})))
}), {})
url_filtering_profile = optional(map(object({
action = string
priority = number
urls = optional(list(string), ["*"])
})), {})
}))
nullable = false
default = {
@@ -167,6 +172,16 @@ variable "security_profiles" {
]))
error_message = "Incorrect severity override token."
}
validation {
condition = alltrue(flatten([
for k, v in var.security_profiles : [
for lk, lv in coalesce(v.threat_prevention_profile.severity_overrides, {}) : (
contains(["ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"], lv.action)
)
]
]))
error_message = "Severity override action must be one of ALERT, ALLOW, DEFAULT_ACTION, DENY."
}
validation {
condition = alltrue(flatten([
for _, v in var.security_profiles : [
@@ -177,6 +192,32 @@ variable "security_profiles" {
]))
error_message = "Incorrect threat override token."
}
validation {
condition = alltrue(flatten([
for k, v in var.security_profiles : [
for lk, lv in coalesce(v.threat_prevention_profile.threat_overrides, {}) : (
contains(["ALERT", "ALLOW", "DEFAULT_ACTION", "DENY"], lv.action)
)
]
]))
error_message = "Threat override action must be one of ALERT, ALLOW, DEFAULT_ACTION, DENY."
}
validation {
condition = alltrue(flatten([
for k, v in var.security_profiles : [
for lk, lv in coalesce(v.url_filtering_profile, {}) : length(lv.urls) > 0
]
]))
error_message = "URL filtering rules must have at least one URL."
}
validation {
condition = alltrue(flatten([
for k, v in var.security_profiles : [
for lk, lv in coalesce(v.url_filtering_profile, {}) : contains(["ALLOW", "DENY"], lv.action)
]
]))
error_message = "URL filtering rule action must be ALLOW or DENY."
}
}
variable "tls_inspection_policies" {