A Google Cloud VPC is global, software-defined and permissive in a few specific places. New projects get a default network whose firewall rules allow SSH, RDP and ICMP from anywhere, VMs receive external IPs unless someone says otherwise, and egress to the internet is allowed by an implied rule you cannot delete. The incident pattern is familiar: a test VM with a public IP and port 22 open to 0.0.0.0/0 gets brute-forced or exploited through an unpatched service, and from there the attacker uses the VM's service account and unrestricted egress to move on. This page covers the network baseline: removing the default and legacy networks, layered firewall policies, IAP instead of public SSH, private access to Google APIs, controlled egress through Cloud NAT, Cloud DNS and TLS settings, and the logs you need to investigate. API-level exfiltration controls live on the VPC Service Controls page.
Baseline controls
These controls apply to every project and Shared VPC host project in the organization. CIS IDs refer to the CIS GCP Foundations Benchmark v5.0.1.
| Control | Why | How to check | CIS / SCC |
|---|---|---|---|
| Delete the default network | Pre-opened SSH, RDP, ICMP rules | gcloud compute networks list | CIS 3.1, DEFAULT_NETWORK |
| Remove legacy networks | No subnets, no per-subnet controls | gcloud compute networks list (mode LEGACY) | CIS 3.2, LEGACY_NETWORK |
| Block SSH and RDP from the internet | Top brute-force and exploit target | gcloud compute firewall-rules list | CIS 3.6, CIS 3.7, OPEN_SSH_PORT, OPEN_RDP_PORT |
| Allow admin ports only from IAP | Identity-checked access, no public ports | Rules with source 35.235.240.0/20 | CIS 3.12 |
| Deny external IPs on VMs | Removes direct internet exposure | compute.vmExternalIpAccess policy | CIS 4.9, PUBLIC_IP_ADDRESS |
| Enable VPC Flow Logs on every subnet | Network forensics | gcloud compute networks subnets list | CIS 3.10, FLOW_LOGS_DISABLED |
| Log firewall rules that matter | Proof of allowed and denied traffic | Rule logConfig.enable | FIREWALL_RULE_LOGGING_DISABLED |
| Reach Google APIs privately | No public IPs needed for APIs | Private Google Access, PSC endpoint | CIS 3.9, PRIVATE_GOOGLE_ACCESS_DISABLED |
| Enable DNSSEC without RSASHA1 | Zone integrity, no weak algorithm | gcloud dns managed-zones describe | CIS 3.3, CIS 3.4, CIS 3.5, DNSSEC_DISABLED, RSASHA1_FOR_SIGNING |
| Enable Cloud DNS logging | DNS queries for detection | gcloud dns policies list | CIS 2.13, DNS_LOGGING_DISABLED |
| Use strong SSL policies on load balancers | No weak ciphers or old TLS | gcloud compute ssl-policies list | CIS 3.11, WEAK_SSL_POLICY |
| Alert on firewall, route and network changes | Catch rogue openings fast | Log-based metrics exist | CIS 2.8, CIS 2.9, CIS 2.10, FIREWALL_NOT_MONITORED, ROUTE_NOT_MONITORED, NETWORK_NOT_MONITORED |
Default and legacy networks
The default network is an auto mode VPC with a subnet in every region and four pre-populated firewall rules:
| Rule | Allows |
|---|---|
default-allow-internal | All protocols between instances in 10.128.0.0/9 |
default-allow-ssh | TCP 22 from 0.0.0.0/0 |
default-allow-rdp | TCP 3389 from 0.0.0.0/0 |
default-allow-icmp | ICMP from 0.0.0.0/0 |
Delete it in existing projects once VMs have moved to a custom mode VPC, and stop new projects from getting one:
gcloud compute firewall-rules list --project=PROJECT_ID \
--filter="network:default" --format="value(name)" \
| xargs -r gcloud compute firewall-rules delete --project=PROJECT_ID --quiet
gcloud compute networks delete default --project=PROJECT_ID --quiet
# skip-default-network.yaml
name: organizations/ORG_ID/policies/compute.skipDefaultNetworkCreation
spec:
rules:
- enforce: true
gcloud org-policies set-policy skip-default-network.yaml
Legacy networks predate subnets: one global IP range, no subnet-level flow logs or Private Google Access. They can only exist in old projects. gcloud compute networks list shows LEGACY in the subnet mode column. There is no in-place conversion, so migrate the workloads to a custom mode VPC and delete the legacy network.
Replace both with custom mode VPCs that contain only the subnets you need, preferably as Shared VPC host projects per environment (see Shared VPC below).
Console: VPC network > VPC networks.
Firewall policies and VPC firewall rules
Cloud NGFW has two layers of configuration:
- Firewall policies: hierarchical policies attached to the organization or folders, plus global and regional network firewall policies attached to a VPC.
- VPC firewall rules: the older per-network rules.
A packet is evaluated against the organization policy, then folder policies from top to bottom, then the network's VPC firewall rules and network firewall policies, then the implied rules. Within each policy, the lowest priority number wins. Hierarchical rules can allow, deny or goto_next (hand the decision to the next level), which lets the security team set rules project owners cannot override. Every VPC also has two implied rules at the lowest priority: deny all ingress and allow all egress.
Organization guardrail: block admin ports, let IAP through
gcloud compute firewall-policies create \
--organization=ORG_ID \
--short-name=org-baseline \
--description="Organization network guardrails"
gcloud compute firewall-policies rules create 900 \
--firewall-policy=org-baseline --organization=ORG_ID \
--direction=INGRESS --action=goto_next \
--src-ip-ranges=35.235.240.0/20 \
--layer4-configs=tcp:22,tcp:3389 \
--description="IAP TCP forwarding: let the VPC decide"
gcloud compute firewall-policies rules create 1000 \
--firewall-policy=org-baseline --organization=ORG_ID \
--direction=INGRESS --action=deny \
--src-ip-ranges=0.0.0.0/0 \
--layer4-configs=tcp:22,tcp:3389,tcp:3306,tcp:5432,tcp:1433 \
--description="No admin or database ports from the internet" \
--enable-logging
gcloud compute firewall-policies associations create \
--firewall-policy=org-baseline --organization=ORG_ID
Rule 900 runs first and passes IAP traffic down to the VPC, so each network still needs its own allow rule for 35.235.240.0/20, and nothing else reaches those ports. Avoid allow in hierarchical rules unless you mean to bypass every lower level. Load balancer health checks come from 35.191.0.0/16 and 130.211.0.0/22 and need their own allow rules where you use load balancing.
Write tight network rules
- Target by service account or secure tag, not network tag. Anyone with
compute.instances.setTagscan add a network tag and pick up a rule. Service accounts and IAM-governed secure tags (Resource Manager tags used in network firewall policies) require IAM rights to attach. - Name source ranges precisely.
0.0.0.0/0belongs on load balancer frontends only. - Put explicit denies at a higher priority than broad allows.
- Log the rules you would need in an incident.
gcloud compute firewall-rules create allow-app-to-db \
--network=vpc-prod --direction=INGRESS --action=allow \
--rules=tcp:5432 \
--source-service-accounts=app@prj-website-prod.iam.gserviceaccount.com \
--target-service-accounts=db@prj-website-prod.iam.gserviceaccount.com \
--priority=1000 \
--enable-logging --logging-metadata=include-all
Find rules open to the world:
gcloud compute firewall-rules list \
--filter="direction=INGRESS AND sourceRanges:0.0.0.0/0 AND disabled=false" \
--format="table(name,network,allowed[].map().firewall_rule().list(),targetTags.list(),logConfig.enable)"
Firewall Insights (Network Intelligence Center) flags shadowed rules, overly permissive rules and rules with no hits, which is the fastest way to clean up years of exceptions.
Restrict egress in sensitive networks
The implied allow-egress rule makes exfiltration and command-and-control easy. In production, add a low-priority deny and explicit allows:
gcloud compute firewall-rules create deny-all-egress \
--network=vpc-prod --direction=EGRESS --action=deny \
--rules=all --destination-ranges=0.0.0.0/0 --priority=65000
gcloud compute firewall-rules create allow-google-apis-egress \
--network=vpc-prod --direction=EGRESS --action=allow \
--rules=tcp:443 --destination-ranges=199.36.153.4/30 --priority=1000
When IP ranges are not enough, Cloud NGFW Enterprise (intrusion prevention, TLS inspection) and Secure Web Proxy add FQDN-based egress control.
Console: Network Security > Cloud NGFW > Firewall policies.
Administrative access through IAP
With no external IPs and no port 22 or 3389 open to the internet, administrators reach VMs through IAP TCP forwarding. IAP authenticates the user, checks IAM, and tunnels the connection from 35.235.240.0/20:
gcloud compute firewall-rules create allow-iap-admin \
--network=vpc-prod --direction=INGRESS --action=allow \
--rules=tcp:22,tcp:3389 --source-ranges=35.235.240.0/20 \
--target-service-accounts=app@prj-website-prod.iam.gserviceaccount.com
gcloud projects add-iam-policy-binding prj-website-prod \
--member="group:app-sre@example.com" \
--role="roles/iap.tunnelResourceAccessor"
gcloud compute ssh vm-1 --zone=europe-west1-b --tunnel-through-iap
Combine this with OS Login (see Compute Engine) so the SSH session itself is IAM-controlled, and add an IAM condition or access level on roles/iap.tunnelResourceAccessor if you want to require a managed device.
Deny external IPs
Enforce the managed constraint so VMs cannot get public IPv4 addresses. Exempt the rare exception (a self-managed NAT appliance, for example) with a tag condition:
# vm-external-ip.yaml
name: organizations/ORG_ID/policies/compute.managed.vmExternalIpAccess
spec:
rules:
- enforce: true
gcloud org-policies set-policy vm-external-ip.yaml
The legacy list constraint compute.vmExternalIpAccess (with denyAll: true) is still widely deployed and does the same job for existing policies. Neither touches IPv6 external addresses; for those, enforce compute.disableVpcExternalIpv6 (Disable VPC External IPv6 usage), which blocks subnets with external IPv6 access.
Private access to Google APIs
VMs without external IPs cannot reach Cloud Storage, Artifact Registry or Cloud Logging unless their subnet has Private Google Access, or the VPC has a Private Service Connect (PSC) endpoint for Google APIs.
gcloud compute networks subnets update snet-prod-ew1 \
--region=europe-west1 \
--enable-private-ip-google-access
gcloud compute networks subnets list \
--format="table(name,region,privateIpGoogleAccess)"
Private Service Connect for Google APIs
CIS 3.9 recommends a PSC endpoint: an internal IP in your VPC that fronts a bundle of Google APIs, routable from on-premises over Interconnect or VPN.
gcloud compute addresses create psc-googleapis \
--global --purpose=PRIVATE_SERVICE_CONNECT \
--addresses=10.255.255.254 --network=vpc-prod
gcloud compute forwarding-rules create pscgoogleapis \
--global --network=vpc-prod --address=psc-googleapis \
--target-google-apis-bundle=vpc-sc
The vpc-sc bundle only serves APIs supported by VPC Service Controls; all-apis serves most Google APIs. The endpoint name is limited to 20 lowercase letters and digits.
Restricted and private VIPs
Without PSC, point DNS at one of the special ranges:
| Domain | Range | Use |
|---|---|---|
private.googleapis.com | 199.36.153.8/30 | Most Google APIs |
restricted.googleapis.com | 199.36.153.4/30 | Only APIs supported by VPC Service Controls |
gcloud dns managed-zones create googleapis \
--dns-name=googleapis.com. --visibility=private \
--networks=vpc-prod --description="Route Google APIs to the restricted VIP"
gcloud dns record-sets create restricted.googleapis.com. --zone=googleapis \
--type=A --ttl=300 --rrdatas=199.36.153.4,199.36.153.5,199.36.153.6,199.36.153.7
gcloud dns record-sets create "*.googleapis.com." --zone=googleapis \
--type=CNAME --ttl=300 --rrdatas=restricted.googleapis.com.
If you removed the default internet route, add a route for 199.36.153.4/30 with --next-hop-gateway=default-internet-gateway.
Cloud NAT for controlled egress
Private VMs that need the internet (package mirrors, third-party APIs) go out through Cloud NAT, a managed service with no VM to patch:
gcloud compute routers create rtr-prod-ew1 \
--network=vpc-prod --region=europe-west1
gcloud compute routers nats create nat-prod-ew1 \
--router=rtr-prod-ew1 --region=europe-west1 \
--nat-custom-subnet-ip-ranges=snet-prod-ew1 \
--nat-external-ip-pool=nat-ip-1,nat-ip-2 \
--enable-logging --log-filter=ALL
Reserved static addresses give partners stable IPs to allowlist, and NAT logs record translations and dropped connections. NAT makes egress possible; firewall rules decide whether it is allowed. Limit which subnets can use NAT with the compute.restrictCloudNATUsage constraint.
Shared VPC and peering
Shared VPC lets a central network team own subnets, routes and firewall policies in a host project while application teams deploy into service projects without network admin rights.
gcloud compute shared-vpc enable prj-net-host-prod
gcloud compute shared-vpc associated-projects add prj-website-prod \
--host-project=prj-net-host-prod
gcloud compute networks subnets add-iam-policy-binding snet-prod-ew1 \
--project=prj-net-host-prod --region=europe-west1 \
--member="group:website-devs@example.com" \
--role="roles/compute.networkUser"
Grant roles/compute.networkUser per subnet, not on the host project. Org-wide, restrict which projects can be hosts and which subnets service projects can use with compute.restrictSharedVpcHostProjects and compute.restrictSharedVpcSubnetworks, protect host projects from accidental deletion with compute.restrictXpnProjectLienRemoval, and limit VPC peering targets with compute.restrictVpcPeering.
Cloud DNS and TLS settings
DNSSEC
Enable DNSSEC on public zones and keep RSASHA1 out of both key-signing and zone-signing keys:
gcloud dns managed-zones create example-com \
--dns-name=example.com. --description="Public zone" \
--dnssec-state=on \
--ksk-algorithm=rsasha256 --ksk-key-length=2048 \
--zsk-algorithm=rsasha256 --zsk-key-length=1024
gcloud dns managed-zones describe example-com --format="yaml(dnssecConfig)"
Publish the DS record at your registrar after enabling, or validating resolvers will treat the zone as broken. Algorithms can only be changed while DNSSEC is off, so plan a transition.
DNS logging
Cloud DNS logging records queries resolved for VMs in a network and is the basis for spotting lookups of known bad domains:
gcloud dns policies create dns-logging \
--networks=vpc-prod --enable-logging \
--description="Log all DNS queries"
gcloud dns policies list --format="table(name,enableLogging,networks[].networkUrl.basename())"
SSL policies
External HTTPS and SSL proxy load balancers use a permissive default SSL policy. Create a strict one and attach it:
gcloud compute ssl-policies create tls12-restricted \
--profile=RESTRICTED --min-tls-version=1.2
gcloud compute target-https-proxies update lb-website-proxy \
--ssl-policy=tls12-restricted
Use MODERN if you must support older clients, never COMPATIBLE with TLS 1.0. The compute.requireSslPolicy constraint makes an SSL policy mandatory on target proxies.
VPC Flow Logs and firewall logging
Flow logs sample network flows per subnet and are the main source for network forensics:
gcloud compute networks subnets update snet-prod-ew1 \
--region=europe-west1 \
--enable-flow-logs \
--logging-aggregation-interval=interval-5-sec \
--logging-flow-sampling=0.5 \
--logging-metadata=include-all
gcloud compute networks subnets list \
--format="table(name,region,logConfig.enable,logConfig.flowSampling)"
Full sampling on production subnets and lower sampling elsewhere is a reasonable cost balance. The compute.requireVpcFlowLogs constraint enforces flow logs on new subnets with a minimum sampling level (ESSENTIAL, LIGHT or COMPREHENSIVE). Enable logging on existing firewall rules with gcloud compute firewall-rules update RULE --enable-logging.
Route both to the central logging project described on the Cloud Logging page.
Console: VPC network > VPC networks > subnet > Edit > Flow logs.
Logging and detection
Firewall, route and network changes are Admin Activity events and always logged. Create log-based metrics and alerting policies for them (CIS 2.8 to 2.10):
resource.type="gce_firewall_rule"
AND (protoPayload.methodName:"compute.firewalls.insert"
OR protoPayload.methodName:"compute.firewalls.patch"
OR protoPayload.methodName:"compute.firewalls.delete")
gcloud logging metrics create vpc-firewall-changes \
--description="VPC firewall rule changes" \
--log-filter='resource.type="gce_firewall_rule" AND (protoPayload.methodName:"compute.firewalls.insert" OR protoPayload.methodName:"compute.firewalls.patch" OR protoPayload.methodName:"compute.firewalls.delete")'
Do the same for routes (resource.type="gce_route", methods compute.routes.insert and compute.routes.delete), networks (resource.type="gce_network", methods compute.networks.insert, compute.networks.patch, compute.networks.delete, compute.networks.addPeering, compute.networks.removePeering) and firewall policies (protoPayload.methodName:"compute.firewallPolicies.", "compute.networkFirewallPolicies." and "compute.regionNetworkFirewallPolicies.").
High-value detections:
- A new ingress rule whose
sourceRangescontains0.0.0.0/0, especially on ports 22, 3389 or database ports. - Denied flows from the hierarchical rule 1000 (
jsonPayload.rule_details.referencein firewall logs) spiking from a single source. - Flow logs showing VMs talking to unexpected external IPs on unusual ports.
- DNS logs resolving domains on your threat intelligence lists.
In Security Command Center, route OPEN_SSH_PORT, OPEN_RDP_PORT, OPEN_FIREWALL and PUBLIC_IP_ADDRESS findings to a notification channel; they are the network findings most often tied to real compromises.
Common mistakes
- Deleting the default network but not enforcing
compute.skipDefaultNetworkCreation. The next project brings it back with SSH and RDP open to the internet. - Targeting rules with network tags. Any developer who can edit a VM can add the tag that opens a port; use service accounts or secure tags.
- Allowing in hierarchical policies. An
allowat org level bypasses every network rule below it; usegoto_nextto delegate. - Leaving egress wide open in production. Cloud NAT without egress rules gives every private VM unrestricted internet access.
- Enabling DNSSEC without publishing the DS record, or keeping RSASHA1 keys. The first breaks nothing visibly but protects nothing; the second fails CIS 3.4 and 3.5.
- Granting
roles/compute.networkUseron the whole host project. Service project teams can then attach to any subnet, including ones meant for other environments. - Turning off flow logs to save money everywhere. Keep at least production and DMZ subnets logged; you cannot reconstruct traffic after the fact.
References
- Cloud NGFW firewall policies overview, Google Cloud documentation
- VPC firewall rules, Google Cloud documentation
- Using IAP for TCP forwarding, Google Cloud documentation
- Access Google APIs through Private Service Connect endpoints, Google Cloud documentation
- Cloud NAT overview, Google Cloud documentation
- VPC Flow Logs, Google Cloud documentation
- CIS Google Cloud Platform Foundation Benchmark, Center for Internet Security
- NIST SP 800-41 Rev. 1 Guidelines on Firewalls and Firewall Policy, NIST
- RFC 8624 Algorithm Implementation Requirements for DNSSEC, IETF
About the author
Florian AmetteSecurity engineer writing practical, benchmark-aligned guides to hardening Google Cloud organizations, projects and workloads.