Why policies exist
VPC firewall rules have two built-in weaknesses:
| # | Weakness of VPC rules | What it means | What policies add |
|---|---|---|---|
| 1 | They live inside one project | Anyone with firewall permission there can create, change or delete any rule. There is no way to say "this rule applies company-wide and no project owner may remove it" | A hierarchical policy on the organization or a folder applies to every project below it, and project owners cannot remove or override it |
| 2 | They belong to one VPC and cannot be shared | Several VPCs that need the same baseline get copies, kept in sync by hand | A policy is written once and attached to many VPCs |
The three kinds
| # | Kind | Attached to | Applies to | Who should own it |
|---|---|---|---|---|
| 1 | Hierarchical | The organization or a folder | Every VPC in every project below it | A central security or platform team |
| 2 | Global network | One or more VPCs | Those VPCs, in all regions | The project's network admin |
| 3 | Regional network | One or more VPCs, in one region | Those VPCs, in that region only | The project's network admin |
For the rest of the course, Kadé has an organization kade.lk with a folder production. kade-prod sits in it now, and kade-staging joins in chapter 14:
Hierarchical policies flow down to every project in their scope. Network policies and VPC rules stay inside the VPCs they are attached to.
Wide by design - scroll it sideways.
How policy rules differ from VPC rules
| # | VPC firewall rules | Firewall policy rules | |
|---|---|---|---|
| 1 | Targets | All instances, network tags, service accounts | All instances, service accounts, secure tags. no network tags |
| 2 | Actions | allow, deny | allow, deny, goto_next (pass the decision to the next layer), and inspection by Cloud NGFW Enterprise |
| 3 | Sources and destinations | IP ranges (plus tags and service accounts as sources) | IP ranges, secure tags, and matching objects: address groups, domain names, countries, threat lists (section 05) |
| 4 | Priority | Many rules may share a number | Each rule in a policy has its own unique number |
| 5 | Shared by | One VPC | Many VPCs, or a whole folder or organization |
The order of the layers
When a packet arrives, GCP walks the layers from the top. The first layer that makes a firm decision stops the walk. The first tab shows the order; the others follow one packet each.
A packet walks down the layers. allow or deny stops the walk; goto_next or "no rule matches" falls through to the next layer. Hierarchical policies are always first. Layers 3 to 5 keep this order unless the VPC's enforcement order is changed (Example F).
Show as config
1. Hierarchical policy - organization
2. Hierarchical policy - folders, outer to inner
3. VPC firewall rules ┐ this pair can be swapped
4. Global network policy │ by a VPC setting
5. Regional network policy ┘
6. Implied rules (allow egress / deny ingress at 65535)
At each layer: allow → stop, packet allowed
deny → stop, packet dropped
goto_next or
no rule matched → fall through to the next layerTry it: walk the layers
- 1.Hierarchical policy · organizationno rule matches
- 2.Hierarchical policy · folderno rule matches
- 3.VPC firewall rulesallow
- 4.Global network policydeny
- 5.Regional network policyno rule matches
Incoming packet is allowed by the vpc firewall rules.
- 1. Hierarchical policy · organization: no rule matches, falls through
- 2. Hierarchical policy · folder: no rule matches, falls through
- 3. VPC firewall rules: ALLOW, walk stops
- 4. Global network policy: not reached
- 5. Regional network policy: not reached
Matching objects: names instead of IP lists
Policy rules can match on things a VPC rule cannot express. They let a rule say what it means ("our trusted IPs", "PayGate's API") instead of holding a raw list of IPs that goes stale.
| # | Object | Matches on | Mainly for | Cloud NGFW tier |
|---|---|---|---|---|
| 1 | Address group | A named, reusable list of IP ranges | Shared allow-lists (office IPs, partners) | Essentials (free) |
| 2 | FQDN object | A domain name, resolved to IPs by GCP | Egress allow-lists | Standard (paid) |
| 3 | Geolocation object | The country an IP is registered to | Rough ingress filtering | Standard (paid) |
| 4 | Threat Intelligence list | Google-maintained lists of known-bad IPs | Cutting background noise | Standard (paid) |
Without a group, the same list lives inside every rule that needs it, and each copy must be edited by hand. With a group, rules point at one named list. Change the list once and every rule follows. Groups can be defined at the organization level and shared by many projects.
Show as config
Without: office and home IPs pasted into kade-allow-icmp
the same IPs pasted into a monitoring rule
a second office opens → edit both, by hand
With: address group "kade-trusted-ips" = [198.51.100.20/32, 203.0.113.45/32]
rule A → srcAddressGroups: [kade-trusted-ips]
rule B → srcAddressGroups: [kade-trusted-ips]
a second office opens → update the group onceCloud NGFW tiers
Google groups these firewall features into three tiers under the name Cloud Next Generation Firewall (Cloud NGFW):
| # | Tier | Adds | Cost |
|---|---|---|---|
| 1 | Essentials | VPC rules, hierarchical and network policies, secure tags, address groups | No charge |
| 2 | Standard | FQDN objects, geolocation objects, Threat Intelligence lists | Charged for traffic processed by rules that use them |
| 3 | Enterprise | Intrusion detection and prevention, TLS inspection, URL filtering | Charged for inspection endpoints and inspected traffic |
Seeing what really applies
With several layers, working out by hand which rules apply to a VM means collecting every policy and rule, sorting them by layer and priority, and simulating the walk. Do not do that. GCP computes it:
| # | Tool | Answers | Use when |
|---|---|---|---|
| 1 | get-effective-firewalls on a VM | "What can reach this VM, and what can it reach?" | The usual question |
| 2 | get-effective-firewalls on a network | "What applies to this VPC, including from above?" | Checking for policies from outside the project |
| 3 | Firewall Insights | "What is wrong with how my rules are written?" | Audits and cleanup |
Firewall Insights is different in kind. Instead of telling you what applies, it gives Google's analysis of your rules, based on the rules' logs:
- Shadowed rules: never reached, because a higher-priority rule always matches first.
- Unused rules: no hits for a long time; candidates for removal.
- Overly broad rules: allowing more than the traffic actually uses.
It is most useful once rules have had logging on for a while (chapter 16).
Policy or VPC rule?
| # | Need | Use |
|---|---|---|
| 1 | A rule that must apply to many projects, or that a project owner must not be able to remove | Hierarchical policy on the organization or a folder |
| 2 | One baseline for every region of a VPC, or shared by several VPCs, as one object | Global network policy |
| 3 | Address groups, FQDN, geolocation, threat lists, or secure tags | A policy; VPC rules cannot express them |
| 4 | A small, single-VPC project with a handful of rules | VPC rules are fine. Google offers a tool to migrate them into a network policy later |
Back to Kadé
Commands in this chapter
All read-only. Commands 3 and 5 need organization-level view permission.
See every rule that applies to one VM
- What it shows: The resolved, ordered rules for kade-db across all layers.
- What to look for: Where each rule comes from. An unexpected hierarchical policy rule explains "my VPC rule does nothing".
gcloud compute instances network-interfaces get-effective-firewalls kade-db \ --network-interface=nic0 --zone=asia-southeast1-bSee everything that applies to a network
- What it shows: VPC rules plus every policy attached to kade-vpc or above it.
- What to look for: Policies from outside the project.
gcloud compute networks get-effective-firewalls kade-vpcList hierarchical policies on a folder
- What it shows: The hierarchical policies attached to the production folder.
- What to look for: Which policy is associated, and its rules. Replace the ID with your folder's.
gcloud compute firewall-policies list --folder=123456789012Check the enforcement order of a VPC
- What it shows: Whether network policies are checked after VPC rules (the default) or before.
- What to look for:
AFTER_CLASSIC_FIREWALLor empty means the default order.
gcloud compute networks describe kade-vpc \ --format="value(networkFirewallPolicyEnforcementOrder)"List global network policies
- What it shows: Network firewall policies in the project and which VPCs they are attached to.
- What to look for: Empty for Kadé until chapter 13.
gcloud compute network-firewall-policies list --globalAsk Firewall Insights for problems
- What it shows: Google's findings on the rules: shadowed, unused, overly broad.
- What to look for: Any rule it flags. Needs the project named explicitly, and works best after logging has been on for a while.
gcloud recommender insights list \ --insight-type=google.compute.firewall.Insight \ --project=kade-prod --location=global