Brains4Cloud
ESEN
Practice

Topic 9 of 11

D2 · Planning and implementing a cloud solution

VPC networks and Cloud NGFW

Section 2.3 of the exam guide starts with creating a VPC with subnets (custom mode, Shared VPC, VPC Network Peering) and continues with VPC firewall rules and Cloud Next Generation Firewall (Cloud NGFW) policies: action, source, destination, targets, protocols and ports, and the use of secure tags and service accounts.

A virtual version of a physical network, implemented inside Google's production network with Andromeda. VPC networks, along with their routes and firewall rules, are global resources; subnets are regional.

  • It provides connectivity for VMs (including GKE nodes), hosts internal load balancers, and connects to on-premises through Cloud VPN or Cloud Interconnect.
  • Resources in a VPC communicate over internal IPs, subject to firewall rules, which are enforced on the VMs themselves.
  • A project can have several VPCs. New projects start with the default network (auto mode with pre-populated firewall rules), unless the compute.skipDefaultNetworkCreation constraint prevents it.
  • They don't support broadcast or multicast.
  • A VM can use any subnet in the region of its zone.

Auto mode or custom mode

Auto mode

  • One subnet per region, created automatically within 10.128.0.0/9.
  • New regions get their subnet automatically.
  • No IPv6. Two auto mode networks can't be connected by peering or Cloud VPN.

Custom mode (recommended for production)

  • No subnets are created: you choose regions and ranges.
  • Avoids overlaps with on-premises and other networks.
  • Required for IPv6 and for connecting to other networks.

You can switch from auto mode to custom mode, but not back.

gcloud compute networks create prod-vpc --subnet-mode=custom
gcloud compute networks subnets create web-subnet \
  --network=prod-vpc --region=us-central1 --range=10.10.0.0/24

Subnets and IP ranges

  • Each subnet has a primary IPv4 range (VM internal IPs, internal load balancers, protocol forwarding) and, optionally, secondary ranges used only by alias IP ranges (for example, GKE Pods and Services).
  • Ranges don't need to be contiguous, but every primary or secondary range in the network must be a unique CIDR block.
  • Subnet purpose: regular (PRIVATE, the default) or reserved for Private NAT (PRIVATE_NAT). It generally can't be changed later.
Unusable addressExample in 10.1.2.0/24
Network address (first)10.1.2.0
Default gateway (second)10.1.2.1
Second-to-last, reserved by Google10.1.2.254
Broadcast (last)10.1.2.255

Google uses the first two and last two addresses of the primary range. All addresses in secondary ranges are usable. The gateway doesn't respond to ping. Expanding a subnet is covered in domain D3.

It connects resources from several projects in the same organization to a common network so they communicate over internal IPs. It centralizes control of subnets, routes, and firewalls while delegating instance management. In the API it is called "XPN".

Host project

Contains the Shared VPC networks. It can share all of its subnets or only some.

Service project

Attached to a single host and uses its subnets. Useful to separate budgets or cost centers.

  • A project can't be a host and a service project at the same time. There can be several hosts, but each service project attaches to only one.
  • Shared VPC Admin (roles/compute.xpnAdmin): enables the host and attaches service projects.
  • Service Project Admin: with roles/compute.networkUser on the host (on the whole project or specific subnets) can create resources in those subnets without being able to change the network.
gcloud compute shared-vpc enable HOST_PROJECT_ID
gcloud compute shared-vpc associated-projects add SERVICE_PROJECT_ID --host-project HOST_PROJECT_ID

It connects two VPC networks so their resources communicate over internal IPs, with the same latency and bandwidth as within one network. They can be in the same project, different projects, or different organizations.

  • It isn't transitive: if A is peered with B and B with C, A and C can't communicate.
  • The networks stay administratively separate; only routes are exchanged, according to each side's configuration.
  • It doesn't exchange firewall rules or policies: one network's network tags and service accounts don't select VMs in the other.
  • Two auto mode networks can't be peered; a custom one with an auto one can, if the custom one has no ranges within 10.128.0.0/9.

Cloud NGFW

Cloud Next Generation Firewall is a distributed firewall with stateful inspection and Layer 7 control, for north-south traffic (entering or leaving the VPC) and east-west traffic (within the VPC). It applies rules to VMs and to certain Envoy-based load balancers.

TierWhat it includes
EssentialsRules by IP, ports, and protocols. No cost
StandardFQDN objects and threat intelligence
EnterpriseLayer 7: intrusion detection and prevention, URL filtering, malware sandbox (preview)

VPC firewall rules

They belong to a VPC network. Each rule has these components:

ComponentValues
DirectionIngress or egress, from the target's point of view
Priority0 to 65,535, default 1000. The highest-priority (lowest number) matching rule applies
ActionAllow or deny
TargetAll instances in the network (default), those with a network tag, or those using a service account
Source or destinationIP ranges, network tags, or service accounts (source for ingress); IP ranges (destination for egress)
Protocols and portse.g. tcp:22, tcp:80,443, icmp
LogsLog matching connections (has a cost)
  • They are stateful: if a connection is allowed, the response is allowed too while tracking stays active (at least one packet every 10 minutes).
  • Implied actions: if no rule matches, ingress traffic to a VM is denied and egress traffic is allowed.
  • The default network includes default-allow-internal (from 10.128.0.0/9), default-allow-ssh (tcp:22), default-allow-rdp (tcp:3389), and default-allow-icmp, all with priority 65534 and editable.
  • Traffic to the metadata server (169.254.169.254) is always allowed.
  • A single rule can't combine network tags and service accounts.
gcloud compute firewall-rules create allow-web --network=prod-vpc \
  --direction=INGRESS --action=ALLOW --rules=tcp:80,tcp:443 \
  --source-ranges=0.0.0.0/0 --target-tags=web --priority=1000

Firewall policies

A policy groups several rules so you can update them at once and control who manages them with IAM.

TypeScope
HierarchicalAssociated with the organization or folders, affecting many VPCs across projects
Global networkEvery region of one or more VPCs
Regional networkOne region of a VPC
Regional systemManaged by Google when a service needs it; you can only toggle its logging. No cost
  • Policy rules have priorities from 0 to 2,147,483,547.
  • Actions: allow, deny, goto_next (continue evaluating at the next level), and apply_security_profile_group (send to Layer 7 inspection).

Evaluation order

With the default order (AFTER_CLASSIC_FIREWALL):

1

Hierarchical policies: First the organization's, then the folders', top down. Allow or deny stops evaluation; goto_next moves to the next level.

2

Regional system policies: Google's own.

3

VPC firewall rules: The "classic" ones.

4

Global network policies

5

Regional network policies

6

Implied actions: Deny ingress to VMs and allow egress.

With BEFORE_CLASSIC_FIREWALL, global and regional network policies are evaluated before VPC rules. You change it with gcloud compute networks update --network-firewall-policy-enforcement-order. Hierarchical and system policies always come first.

Secure tags, network tags, and service accounts

Secure tagsNetwork tagsService accounts
What they areResource Manager keys and values with the GCE_FIREWALL purposeText strings on the VM or templateThe VM's identity (only one per VM)
Where they are usedHierarchical, global, and regional policiesVPC firewall rules onlyVPC rules and policy rules
Access controlIAM: Tag Administrator creates; Tag User binds to VMs and uses in rulesNone: anyone who can edit the instance can change themService Account User is needed to assign it to a VM

That is why filtering by service account or secure tag is stricter than by network tag: an instance admin can add a network tag to a VM and change which rules apply to it. Secure tags enable identity-based micro-segmentation. A tag key supports up to 1,000 values and its purpose can't be changed later.

Exam scenarios

SituationAnswerWhy
A production network that will connect to on-premises over VPNCustom mode VPCFull control of ranges and no overlap with 10.128.0.0/9.
Several teams must use a network managed by the networking teamShared VPCHost project and service projects.
Connect two VPCs in different organizations with internal IPsVPC Network PeeringWorks across projects and organizations.
A peers with B and B with C; A must reach CCreate an A-C peeringPeering isn't transitive.
Block SSH from the internet across the whole organizationHierarchical firewall policy on the organizationEvaluated before everything else.
Apply rules to VMs without depending on IPs and without an instance admin changing themSecure tags in a firewall policyGoverned by IAM.
A rule must apply only to the VMs of a specific backendTarget by service account or tagInstead of every instance in the network.
Intrusion inspection and URL filteringCloud NGFW EnterpriseLayer 7 capabilities.

Common exam traps

❓ Are subnets global resources?

No. VPC networks are global; subnets are regional.

❓ Can you switch a VPC from custom mode to auto mode?

No. Only from auto mode to custom mode.

❓ What happens to ingress traffic if no rule matches?

It is denied by the implied action. Egress traffic is allowed.

❓ Does a rule with priority 100 beat one with priority 1000?

Yes. The lowest number is the highest priority.

❓ Does peering share firewall rules between networks?

No. It only exchanges routes; each network keeps its own firewall.

❓ Can network tags be used in hierarchical firewall policies?

No. Policies use secure tags; network tags only work in VPC rules.

❓ How many IPs in a primary range are unusable?

Four: the first two and the last two.

Did you get this topic?

Test what you just learned

The security team wants to block SSH from the internet to every VM in the organization, and no project administrator should be able to bypass it with their own rules. What should it configure?

Ready to test "VPC networks and Cloud NGFW"?

Original questions, each with a full explanation.

Start a mock exam