Skip to content

fix(stages-aw): fix spoke host_project_ids, PSC project reference, and harden NGFW template - #378

Open
LeonxLJX wants to merge 2 commits into
google:mainfrom
LeonxLJX:fix/370-stages-aw-2-networking
Open

LeonxLJX wants to merge 2 commits into
google:mainfrom
LeonxLJX:fix/370-stages-aw-2-networking

Conversation

@LeonxLJX

Copy link
Copy Markdown

Fixes #370.

Summary

This PR addresses functional and security defects in fast/stages-aw/2-networking-a-fedramp and fast/stages-aw/2-networking-b-il5-ngfw.

Changes Made

Both networking stages

  • outputs.tf: Changed host_project_ids from module.env-spoke-vpc (the VPC module output, which does not provide project_id) to [for k, v in module.env-spoke-projects : v.project_id], producing a list of spoke project IDs that downstream Stage 3 VPC Service Controls configuration requires.

  • psc.tf: Fixed google_compute_global_address.project from module.env-spoke-vpc[each.key].project_id to module.env-spoke-projects[each.key].project_id. Added count condition (try(length(var.psa_ranges[each.key]), 0) == 0 ? 1 : 0) to skip duplicate peering allocation when psa_ranges are already configured on a spoke VPC.

NGFW stage only

  • ngfw.tf:

    • Changed region from hardcoded var.regions["primary"] to each.value so template mirrors the iteration region.
    • Changed serial-port-enable from true to false to disable serial console access.
    • Added block-project-ssh-keys = "true" metadata entry to prevent project-wide SSH keys on NGFW instances.
  • bootstrap.xml.tpl:

    • Replaced weak default IKE crypto profile (aes-128-cbc, 3des, sha1, group2) with AES-256-GCM, SHA-384, SHA-512, DH group 20.
    • Replaced weak default IPsec crypto profile (aes-128-cbc, 3des, sha1, group2) with AES-256-GCM + group20.
    • Added <log-start>yes</log-start> and <log-end>yes</log-end> to the Trust-to-Untrust security rule for session audit logging.

Security Impact

  • Prevents deployment failures from missing project_id on VPC module output
  • Avoids duplicate Service Networking peering allocations
  • Reduces NGFW attack surface by disabling serial port and blocking project SSH keys
  • Removes deprecated 3DES, AES-CBC, SHA-1, and DH group 2 from default VPN profiles
  • Enables session start/end logging for NGFW security policies

@google-cla

google-cla Bot commented Oct 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the Scope - Fast Related to Fabric FAST deployment stages in the fast directory label Oct 28, 2026
@LeonxLJX

Copy link
Copy Markdown
Author

刚 force push 了 erraform fmt 修复 Repository Lint(for_each map key 对齐)。CI 会重新跑。

@LeonxLJX

Copy link
Copy Markdown
Author

Hi, I just signed the Google Contributor License Agreement (CLA). Could someone please re-run the \cla/google\ check? Thanks!

@aghassemlouei aghassemlouei added Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - High Critical issues blocking development or users; urgent bugs or core features for release Security Something is insecure or can be secured labels Oct 29, 2026

@aghassemlouei aghassemlouei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for putting together the Stage 2 networking and NGFW crypto profile fixes for #370. Running terraform init and terraform validate across both Stage 2 networking directories surfaced two issues:

  1. fast/stages-aw/2-networking-b-il5-ngfw/psc.tf, which is also symlinked from fast/stages-aw/2-networking-a-fedramp/psc.tf, combines for_each and count on the same resource blocks and indexes var.psa_ranges without lower(k), failing HCL parsing during terraform init across both Stage 2 networking flavors.
  2. Please align metadata string formatting in ngfw.tf, keep <log-end>yes</log-end> without <log-start>yes</log-start> in bootstrap.xml.tpl unless session-start logging is explicitly desired, and populate the .github/pull_request_template.md sections.

Pushing a new commit with these fixes will also re-trigger the cla/google check against the signed Contributor License Agreement.

Comment on lines 15 to 33
resource "google_compute_global_address" "private_service_connect_ip" {
for_each = var.envs_folders

project = module.env-spoke-vpc[each.key].project_id
project = module.env-spoke-projects[each.key].project_id
name = "default-peering"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 22
network = module.env-spoke-vpc[each.key].self_link
count = try(length(var.psa_ranges[each.key]), 0) == 0 ? 1 : 0
}

resource "google_service_networking_connection" "default" {
for_each = var.envs_folders
network = module.env-spoke-vpc[each.key].self_link
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_service_connect_ip[each.key].name]
count = try(length(var.psa_ranges[each.key]), 0) == 0 ? 1 : 0
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combining for_each and count on the same resource block is invalid in Terraform and fails both 2-networking-b-il5-ngfw and 2-networking-a-fedramp via its psc.tf symlink with The "count" and "for_each" meta-arguments are mutually-exclusive, and each.key cannot be referenced inside count. In addition, var.psa_ranges in variables.tf uses lowercase dev and prod object attributes whereas var.envs_folders keys may be capitalized, matching lower(k) in variables.tf at line 341.

Filter the for_each map directly on both resources:

Suggested change
resource "google_compute_global_address" "private_service_connect_ip" {
for_each = var.envs_folders
project = module.env-spoke-vpc[each.key].project_id
project = module.env-spoke-projects[each.key].project_id
name = "default-peering"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 22
network = module.env-spoke-vpc[each.key].self_link
count = try(length(var.psa_ranges[each.key]), 0) == 0 ? 1 : 0
}
resource "google_service_networking_connection" "default" {
for_each = var.envs_folders
network = module.env-spoke-vpc[each.key].self_link
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_service_connect_ip[each.key].name]
count = try(length(var.psa_ranges[each.key]), 0) == 0 ? 1 : 0
}
resource "google_compute_global_address" "private_service_connect_ip" {
for_each = {
for k, v in var.envs_folders : k => v
if length(try(var.psa_ranges[lower(k)], [])) == 0
}
project = module.env-spoke-projects[each.key].project_id
name = "default-peering"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 22
network = module.env-spoke-vpc[each.key].self_link
}
resource "google_service_networking_connection" "default" {
for_each = {
for k, v in var.envs_folders : k => v
if length(try(var.psa_ranges[lower(k)], [])) == 0
}
network = module.env-spoke-vpc[each.key].self_link
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_service_connect_ip[each.key].name]
}

Comment on lines +268 to +270
serial-port-enable = false
serial-port-logging-enable = true
block-project-ssh-keys = "true"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCE instance metadata expects map(string), so use consistent string literals such as "false" and "true" across serial-port-enable, serial-port-logging-enable, and block-project-ssh-keys.

Comment on lines +489 to +490
<log-start>yes</log-start>
<log-end>yes</log-end>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PAN-OS best practice and item 4 of #370 require <log-end>yes</log-end>, which records complete session byte counts, NAT translations, and termination reason; enabling <log-start>yes</log-start> on a broad allow rule doubles firewall traffic log volume without adding audit fields beyond the session-end record.

@LeonxLJX

LeonxLJX commented Nov 4, 2026

Copy link
Copy Markdown
Author

Hi maintainers! @GoogleCloudPlatform/foundation-framework 👋 This PR is all green (no conflicts, CI passing) and has been rebased on latest. Could someone take a look when you have a moment? Thanks!

… NGFW

- outputs.tf: fix host_project_ids to reference env-spoke-projects instead of env-spoke-vpc
- psc.tf: use env-spoke-projects for project_id, add conditional count to skip duplicate peering when psa_ranges configured
- ngfw.tf: use each.value for region, disable serial port, add block-project-ssh-keys
- bootstrap.xml.tpl: replace weak default crypto profiles with AES-256-GCM/SHA-384/DH-group20, add session logging
@LeonxLJX
LeonxLJX force-pushed the fix/370-stages-aw-2-networking branch from 13c7654 to b5e7033 Compare November 12, 2026 03:31
@Calvin-Cheng1

Copy link
Copy Markdown
Collaborator

@LeonxLJX Hello, thank you for the contribution so far. Please let us know if you are able to reconcile all outstanding comments/conversations related to the submitted code for this PR. If you are not able to resolve them by Friday, we will close this PR as the review is becoming stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - High Critical issues blocking development or users; urgent bugs or core features for release Scope - Fast Related to Fabric FAST deployment stages in the fast directory Security Something is insecure or can be secured

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] fast/stages-aw/2-networking: fix spoke host_project_ids output, PSC project reference, and NGFW template settings

4 participants