GCP VPC Network Security Audit
Cloud resource audit for Google Cloud Platform VPC Network architecture,
firewall posture, and connectivity. This skill evaluates provider-specific
GCP networking constructs — global VPC Network design, firewall rule
priority evaluation, hierarchical firewall policies, Cloud NAT egress
control, Cloud Interconnect VLAN attachments, Shared VPC host/service
project topology, and Cloud Router BGP sessions — not generic cloud
networking advice.
Scope: auto-mode versus custom-mode VPC Networks, subnet IP ranges,
firewall rules with target tags and service accounts, Cloud NAT port
allocation, Cloud Interconnect and Cloud VPN connectivity, Shared VPC
cross-project networking, Cloud Router dynamic routing. Out of scope:
Cloud CDN, Cloud Armor WAF, load balancer URL maps, Cloud DNS.
Reference references/cli-reference.md for read-only gcloud commands
and references/vpc-architecture.md for the GCP global VPC model and
firewall rule evaluation order.
When to Use
- - VPC Network architecture review — evaluating auto-mode versus custom-mode selection, subnet IP ranges, and Private Google Access configuration
- Post-migration audit — verifying firewall rules, Cloud NAT egress, and Cloud Router routes after workload migration
- Security assessment — identifying permissive firewall rules using target tags, missing hierarchical firewall policies, or disabled VPC Flow Logs
- Connectivity troubleshooting — diagnosing Cloud Interconnect VLAN attachment failures, Cloud VPN tunnel errors, or Shared VPC permission issues
- Compliance preparation — documenting VPC Network segmentation, firewall rule justification, and VPC Flow Log retention
- Cost optimization — identifying unused external IPs, over-provisioned Cloud NAT gateways, and idle Cloud Interconnect attachments
Prerequisites
- - gcloud CLI authenticated (
gcloud auth list shows active account) - IAM permissions — Viewer role on target project, or granular read:
compute.networks.get, compute.firewalls.list, compute.routers.get, compute.interconnects.get, compute.subnetworks.list, compute.addresses.list. Shared VPC: Viewer on host and service projects. Hierarchical firewall policies: compute.firewallPolicies.get at org/folder level - Target scope — project ID, organization ID (for hierarchical firewall policies), Shared VPC host project if applicable
- VPC Flow Logs — Step 1 checks subnet-level enablement. If no subnets have VPC Flow Logs, document as Critical
Procedure
Follow these six steps sequentially. Each builds on prior findings,
moving from inventory through security analysis to optimization.
Step 1: VPC Network Inventory and Design Assessment
Enumerate all VPC Networks in the target project and assess design.
CODEBLOCK0
For each VPC Network, evaluate:
- - Auto-mode vs custom-mode: Auto-mode VPC Networks create one subnet per region with predetermined /20 ranges from 10.128.0.0/9. Custom-mode requires explicit subnet creation. Production environments should use custom-mode. Auto-mode in production is a High finding.
- Global scope: GCP VPC Networks are global — subnets are regional but the network spans all regions. Unlike AWS/Azure, a single VPC Network hosts subnets in every region without peering. Verify subnet distribution matches workload regions.
- Subnet IP ranges: Primary ranges for VMs, secondary ranges for GKE Pod and Service CIDRs (alias IP ranges). Check for overlapping ranges and sufficient growth space.
- Private Google Access: Enables VMs without external IPs to reach Google APIs. Disabled Private Google Access on internal-only subnets is a Medium finding.
- VPC Flow Logs: Per-subnet enablement in GCP (not VPC-level like AWS). Subnets without VPC Flow Logs lack traffic visibility — flag as High for production.
Step 2: Firewall Rule Audit
Audit VPC Network firewall rules using GCP's priority-based evaluation and hierarchical firewall policies.
CODEBLOCK1 GCP firewall rules evaluate by priority (0–65535, lowest = highest priority). First match wins.
- - Implied rules: Every VPC Network has implied deny-all-ingress and allow-all-egress at priority 65535. Not visible in
gcloud compute firewall-rules list but active. Custom rules at 0–65534 override them. - Priority conflicts: An allow at priority 1000 overrides a deny at 2000. Verify deny rules have lower priority numbers than conflicting allows.
- Target tags vs service accounts: Target tags are mutable labels — any project editor can change VM tags to bypass firewall rules. Service account targets are IAM-controlled and more secure. Flag tag-based rules on sensitive workloads as Medium.
- Source ranges: Rules permitting ingress from
0.0.0.0/0. SSH/RDP from 0.0.0.0/0 is Critical. Verify broad ranges are justified. - Disabled rules: GCP firewall rules can be disabled without deletion. A disabled deny rule leaves a security gap.
- Default network rules: The
default VPC Network includes pre-created rules allowing ICMP, SSH, RDP, and internal traffic. Audit these permissive rules.
Hierarchical firewall policies:
CODEBLOCK2
Hierarchical firewall policies apply at organization or folder level and evaluate before VPC Network firewall rules. A deny in a hierarchical policy blocks traffic regardless of VPC-level allows. A goto_next action delegates to VPC-level rules. Verify hierarchical policies enforce org-wide baselines (e.g., block SSH from internet).
Step 3: Cloud NAT and Egress Analysis
Audit Cloud NAT gateways for egress capacity, port allocation, and logging.
CODEBLOCK3
Cloud NAT provides outbound internet access for VMs without external IPs, configured on a Cloud Router.
- - IP allocation method: Automatic (GCP assigns IPs) or manual (reserved IPs). Manual provides predictable egress IPs for third-party allowlisting.
- Port allocation: Default 64 minimum ports per VM. Port exhaustion drops connections. Check
minPortsPerVm/maxPortsPerVm. High-connection workloads need increased allocations. Enable Dynamic Port Allocation for bursty workloads. - Endpoint-Independent Mapping: When enabled, Cloud NAT uses consistent IP:port mappings, improving protocol compatibility. Disabled by default.
- Cloud NAT logging: Verify
logConfig.enable. Options: ERRORSONLY, TRANSLATIONSAND_ERRORS (recommended), ALL. Missing NAT logging reduces egress visibility. - Subnet coverage: Cloud NAT applies to all subnets or specific subnets. Verify production subnets are covered.
Step 4: Connectivity Analysis
Evaluate hybrid and cross-project connectivity via Cloud Interconnect, Cloud VPN, and Shared VPC.
Cloud Interconnect:
CODEBLOCK4
- - VLAN attachment state: Verify
state: ACTIVE and operationalStatus: OS_ACTIVE. UNPROVISIONED_ATTACHMENT means partner provisioning incomplete. OS_LACP_DOWN indicates link aggregation failure. - BGP session health: Each VLAN attachment peers with a Cloud Router via BGP.
UP is healthy, DOWN indicates ASN mismatch, authentication failure, or network issue. Verify primary and redundant sessions. - MED values: Multi-Exit Discriminator influences route preference across multiple Cloud Interconnect attachments. Lower MED preferred. Verify values match active/standby design.
- Redundancy: Production requires connections in two edge availability domains. Single-connection topology is a High finding.
Cloud VPN:
CODEBLOCK5
- - Tunnel status: Should show
status: ESTABLISHED. FIRST_HANDSHAKE indicates IKE negotiation in progress. NO_INCOMING_PACKETS suggests on-premises misconfiguration. - HA VPN: High Availability VPN provides two tunnels for 99.99% SLA. Use HA VPN for production (Classic VPN offers no redundancy SLA).
Shared VPC:
CODEBLOCK6
- - Host/service project model: Shared VPC lets a host project share VPC Network subnets with service projects. Verify host project designation and service project associations.
- Subnet-level IAM: Shared VPC permissions granted per subnet via
compute.networkUser role. Verify service accounts access only intended subnets. - Private Google Access inheritance: Service projects inherit settings from host project subnets. Verify enablement.
Step 5: Cloud Router and Routing Validation
Audit Cloud Router configuration for route advertisements, BGP settings, and dynamic routing mode.
CODEBLOCK7
- - Dynamic routing mode:
regional or global. Regional: Cloud Routers advertise/learn routes only within their region. Global: routes propagate across all regions. Multi-region workloads accessing on-premises via single-region Cloud Interconnect require global mode. - Custom route advertisements: Default: advertise all subnets. Custom mode overrides — verify no subnets are accidentally excluded from advertisements.
- Graceful restart: Preserves forwarding during Cloud Router updates. Enable for production routers.
- AS path analysis: Review
get-status learned routes and AS paths. Unexpected paths indicate route leaks or suboptimal selection. - Route priorities: Custom routes use priority 0–65535 (default 1000). Lower preferred. Verify priorities create intended active/standby or ECMP behavior.
- Learned route limits: Cloud Router has per-region learned route limits. Approaching limits causes drops — check
get-status for count versus limits.
Step 6: Report and Optimization
Compile findings and identify optimization opportunities.
CODEBLOCK8
- - Unused static IPs: Reserved external IPs not associated with resources incur charges. Release unused addresses.
- Disabled firewall rules: Create audit confusion. Delete or document justification.
- Over-permissive tag-based rules: Firewall rules targeting broad tags on high-privilege workloads should migrate to service account targets.
- IP address utilization: GCP reserves 4 addresses per subnet. Subnets with <10% available are exhaustion risks. Over-provisioned subnets waste space in Shared VPC.
- Cloud NAT consolidation: Multiple gateways per region unnecessary unless subnets need different configs.
Compile the findings report using the Report Template section.
Threshold Tables
Firewall Rule Severity
| Finding | Severity | Rationale |
|---|
| Firewall rule allows SSH (22) from 0.0.0.0/0 | Critical | Shell access from internet |
| Firewall rule allows RDP (3389) from 0.0.0.0/0 |
Critical | Remote desktop from internet |
| Firewall rule allows all ports from 0.0.0.0/0 | Critical | No port restriction on ingress |
| Target tag on sensitive workload instead of service account | High | Tags mutable by project editors |
| Hierarchical firewall policy missing at org level | High | No organization-wide baseline |
| VPC Flow Logs disabled on production subnet | High | No traffic visibility |
| Firewall rule with priority 0 | High | Audit for broad scope |
| Disabled firewall rule undocumented | Medium | Audit confusion risk |
| Auto-mode VPC Network in production | Medium | Uncontrolled IP allocation |
| Firewall rule with >20 source ranges | Medium | Excessive complexity |
Cloud Interconnect Health
| Metric | Severity | Action |
|---|
| VLAN attachment state not ACTIVE | Critical | No traffic flow — engage provider |
| BGP session DOWN |
High | Check ASN, authentication, link |
| Single edge availability domain | High | No redundancy — add second |
| Learned route count >80% limit | Medium | Approaching route capacity |
Cloud NAT Port Utilization
| Available Ports (%) | Severity | Action |
|---|
| <10% | Critical | Connection drops — increase allocation |
| 10–25% |
High | Enable Dynamic Port Allocation |
| 25–50% | Medium | Monitor trend |
| >50% | Low | Healthy |
Decision Trees
Is This Firewall Rule Overly Permissive?
CODEBLOCK9
Is This VPC Network Design Following GCP Best Practices?
CODEBLOCK10
Report Template
CODEBLOCK11
Troubleshooting
VPC Flow Logs Not Enabled on Subnets
VPC Flow Logs in GCP are subnet-level, not VPC-level. Each subnet must
be individually enabled. Enabling is non-disruptive. Missing VPC Flow
Logs on production subnets is a High finding.
Firewall Rule Not Applied to Expected VMs
Verify the target: if using a target tag, confirm the tag is on the VM
(tags are case-sensitive). If using a service account target, verify the
VM runs with that account. Firewall rules with no target apply to all
VMs in the VPC Network.
Cloud Interconnect VLAN Attachment Not Active
Check state and operationalStatus. UNPROVISIONED_ATTACHMENT means
partner provisioning incomplete. OS_LACP_DOWN indicates Layer 2
failure. Verify Cloud Router BGP session has correct ASN and IP pair.
Shared VPC Service Project Cannot Deploy to Subnet
Verify the deploying service account has compute.networkUser on the
specific subnet in the host project. Subnet-level IAM is required even
if the service project is associated with the host project.
Cloud Router BGP Session Flapping
Check Cloud Logging with resource.type="gce_router". Common causes:
on-premises router exceeding learned route limit, authentication key
mismatch, or MTU issues on the Cloud Interconnect link. Enable graceful
restart to preserve forwarding during brief flaps.
GCP VPC 网络安全审计
针对Google Cloud Platform VPC网络架构、防火墙策略和连接性的云资源审计。该技能评估特定于GCP的网络构建模块——全局VPC网络设计、防火墙规则优先级评估、分层防火墙策略、Cloud NAT出口控制、Cloud Interconnect VLAN连接、共享VPC主机/服务项目拓扑以及Cloud Router BGP会话——而非通用云网络建议。
范围:自动模式与自定义模式VPC网络、子网IP范围、带有目标标签和服务账户的防火墙规则、Cloud NAT端口分配、Cloud Interconnect和Cloud VPN连接、共享VPC跨项目网络、Cloud Router动态路由。范围外:Cloud CDN、Cloud Armor WAF、负载均衡器URL映射、Cloud DNS。参考references/cli-reference.md获取只读gcloud命令,参考references/vpc-architecture.md了解GCP全局VPC模型和防火墙规则评估顺序。
使用场景
- - VPC网络架构审查——评估自动模式与自定义模式的选择、子网IP范围和Private Google Access配置
- 迁移后审计——验证工作负载迁移后的防火墙规则、Cloud NAT出口和Cloud Router路由
- 安全评估——识别使用目标标签的宽松防火墙规则、缺失的分层防火墙策略或禁用的VPC Flow Logs
- 连接性故障排除——诊断Cloud Interconnect VLAN连接故障、Cloud VPN隧道错误或共享VPC权限问题
- 合规性准备——记录VPC网络分段、防火墙规则合理性说明和VPC Flow Log保留
- 成本优化——识别未使用的外部IP、过度配置的Cloud NAT网关和闲置的Cloud Interconnect连接
前提条件
- - gcloud CLI已认证(gcloud auth list显示活跃账户)
- IAM权限——目标项目的查看者角色,或细粒度读取权限:compute.networks.get、compute.firewalls.list、compute.routers.get、compute.interconnects.get、compute.subnetworks.list、compute.addresses.list。共享VPC:主机和服务项目的查看者。分层防火墙策略:组织/文件夹级别的compute.firewallPolicies.get
- 目标范围——项目ID、组织ID(用于分层防火墙策略)、共享VPC主机项目(如适用)
- VPC Flow Logs——步骤1检查子网级别的启用情况。如果没有子网启用VPC Flow Logs,记录为严重
操作步骤
按顺序执行以下六个步骤。每一步都基于之前的发现,从清单收集到安全分析再到优化。
步骤1:VPC网络清单和设计评估
枚举目标项目中的所有VPC网络并评估设计。
gcloud compute networks list --project <项目ID>
gcloud compute networks describe <网络名称> --project <项目ID>
gcloud compute networks subnets list --network <网络名称>
对于每个VPC网络,评估:
- - 自动模式与自定义模式:自动模式VPC网络在每个区域创建一个子网,使用10.128.0.0/9中预定的/20范围。自定义模式需要显式创建子网。生产环境应使用自定义模式。生产环境中使用自动模式属于高风险发现。
- 全局范围:GCP VPC网络是全局的——子网是区域性的,但网络跨越所有区域。与AWS/Azure不同,单个VPC网络可以在每个区域托管子网而无需对等连接。验证子网分布与工作负载区域匹配。
- 子网IP范围:虚拟机的主范围,GKE Pod和服务CIDR的辅助范围(别名IP范围)。检查重叠范围和足够的增长空间。
- Private Google Access:允许没有外部IP的虚拟机访问Google API。在仅内部子网上禁用Private Google Access属于中风险发现。
- VPC Flow Logs:GCP中按子网启用(不像AWS那样按VPC级别)。没有VPC Flow Logs的子网缺乏流量可见性——对生产环境标记为高风险。
步骤2:防火墙规则审计
使用GCP基于优先级的评估和分层防火墙策略审计VPC网络防火墙规则。
gcloud compute firewall-rules list --filter=network:<网络名称>
gcloud compute firewall-rules describe <规则名称>
GCP防火墙规则按优先级评估(0–65535,最低=最高优先级)。首次匹配生效。
- - 隐含规则:每个VPC网络都有优先级为65535的隐含拒绝所有入站和允许所有出站规则。在gcloud compute firewall-rules list中不可见但处于活动状态。优先级0–65534的自定义规则会覆盖它们。
- 优先级冲突:优先级1000的允许规则会覆盖优先级2000的拒绝规则。验证拒绝规则的优先级编号低于冲突的允许规则。
- 目标标签与服务账户:目标标签是可变的标签——任何项目编辑者都可以更改虚拟机标签以绕过防火墙规则。服务账户目标受IAM控制,更安全。对敏感工作负载标记基于标签的规则为中风险。
- 源范围:允许从0.0.0.0/0入站的规则。从0.0.0.0/0的SSH/RDP属于严重风险。验证宽泛范围是否合理。
- 禁用规则:GCP防火墙规则可以禁用而不删除。禁用的拒绝规则会留下安全漏洞。
- 默认网络规则:defaultVPC网络包含预创建的规则,允许ICMP、SSH、RDP和内部流量。审计这些宽松规则。
分层防火墙策略:
gcloud compute firewall-policies list --organization <组织ID>
gcloud compute firewall-policies describe <策略名称>
gcloud compute firewall-policies rules list --firewall-policy <策略名称>
分层防火墙策略应用于组织或文件夹级别,并在VPC网络防火墙规则之前评估。分层策略中的deny会阻止流量,无论VPC级别的允许规则如何。goto_next操作将决策委托给VPC级别规则。验证分层策略是否强制执行组织范围的基线(例如,阻止来自互联网的SSH)。
步骤3:Cloud NAT和出口分析
审计Cloud NAT网关的出口容量、端口分配和日志记录。
gcloud compute routers nats list --router <路由器名称> --region <区域>
gcloud compute routers nats describe --router <路由器名称> --region <区域>
Cloud NAT为没有外部IP的虚拟机提供出站互联网访问,配置在Cloud Router上。
- - IP分配方法:自动(GCP分配IP)或手动(预留IP)。手动提供可预测的出口IP,用于第三方白名单。
- 端口分配:每个虚拟机默认最少64个端口。端口耗尽会导致连接中断。检查minPortsPerVm/maxPortsPerVm。高连接工作负载需要增加分配。为突发工作负载启用动态端口分配。
- 端点独立映射:启用时,Cloud NAT使用一致的IP:端口映射,提高协议兼容性。默认禁用。
- Cloud NAT日志记录:验证logConfig.enable。选项:ERRORSONLY、TRANSLATIONSAND_ERRORS(推荐)、ALL。缺少NAT日志记录会降低出口可见性。
- 子网覆盖:Cloud NAT适用于所有子网或特定子网。验证生产子网是否被覆盖。
步骤4:连接性分析
通过Cloud Interconnect、Cloud VPN和共享VPC评估混合和跨项目连接性。
Cloud Interconnect:
gcloud compute interconnects list
gcloud compute interconnects describe <互联名称>
gcloud compute interconnects attachments list --region <区域>
gcloud compute interconnects attachments describe <连接名称> --region <区域>
- - VLAN连接状态:验证state: ACTIVE和operationalStatus: OSACTIVE。UNPROVISIONEDATTACHMENT表示合作伙伴配置未完成。OSLACPDOWN表示链路聚合故障。
- BGP会话健康:每个VLAN连接通过BGP与Cloud Router对等。UP表示健康,DOWN表示ASN不匹配、认证失败或网络问题。验证主会话和冗余会话。
- MED值:多出口鉴别器影响跨多个Cloud Interconnect连接的路由偏好。较低的MED更受青睐。验证值是否匹配主/备用设计。
- 冗余:生产环境需要在两个边缘可用性域中建立连接。单连接拓扑属于高风险发现。
Cloud VPN:
gcloud compute vpn-tunnels list
gcloud compute vpn-tunnels describe <隧道名称> --region <区域>
gcloud compute vpn-gateways list
- - 隧道状态:应显示status: ESTABLISHED。FIRSTHANDSHAKE表示IKE协商进行中。NOINCOMING_PACKETS表示本地配置错误。
- HA VPN:高可用性VPN提供两个隧道,SLA为99.99%。生产环境使用HA VPN(经典VPN不提供冗余SLA)。
共享VPC:
gcloud compute shared-vpc get-host-project <服务项目ID>
gcloud compute shared-vpc list-associated-resources <主机项目ID>
gcloud compute networks subnets get-iam-policy <子网> --region <区域> --project