Where the fundamentals course left off
Kadé is the small online grocery shop in Colombo. Customers use a mobile app and a website, and both call one backend at api.kade.lk. You are Kadé's backend engineer. From now on you are also the only person looking after its Google Cloud setup.
The fundamentals course used GCP as the place where Kadé's servers live, and looked at it mostly from the outside: packets arriving, a load balancer in front, a gateway at .1. By the end, this much was built:
| # | Piece | What it is | Built in |
|---|---|---|---|
| 1 | kade-vpc | Kadé's network in GCP, with subnets sn-app 10.10.1.0/24 and sn-data 10.10.2.0/24 | Fundamentals ch 3 |
| 2 | kade-api-1, kade-api-2 | Two VMs running the Node app, no external IPs | Fundamentals ch 33 |
| 3 | kade-db | One VM running PostgreSQL, 10.10.2.5:5432 | Fundamentals ch 4 |
| 4 | Load balancer | External Application Load Balancer at 34.120.88.10. api.kade.lk points here | Fundamentals ch 33 |
| 5 | Cloud DNS | Hosts the kade.lk zone | Fundamentals ch 22 |
| 6 | Two firewall rules | Ping from your home and office IPs; health checks from Google's load balancer ranges | Fundamentals ch 13, 33 |
Some things were only planned there, never built: Cloud NAT with a fixed IP for the payment provider (Fundamentals ch 10), a VPN to the office (Fundamentals ch 0), a rule that lets only kade-api reach the database (ch 0), and SSH through IAP instead of an open port 22 (ch 29).
These notes pick up at that point. Every chapter starts with a real problem in Kadé's project and ends with it fixed, and every new idea is tied back to the fundamentals course chapter it builds on.
One correction first: a VPC has no address range
Builds on3. Networks, hosts and CIDR5. The default gateway
The fundamentals course map said kade-vpc 10.10.0.0/16. That was a useful shortcut, but it is not how GCP works. In GCP, a VPC network has no address range of its own. Only subnets have ranges. A home router is set up with one LAN range; a VPC is not.
So 10.10.0.0/16 is Kadé's own plan: the block we promise to take every subnet range from. GCP does not know about it and does not enforce it. That has three results:
| # | What this means | Example | Chapter |
|---|---|---|---|
| 1 | A subnet can use any private range, even one far outside our plan | GCP would accept a new subnet 192.168.50.0/24 in kade-vpc | 2 |
| 2 | Two VPCs can use the same ranges, and nothing warns you until you try to connect them | A staging VPC that also uses 10.10.1.0/24 cannot be peered with kade-vpc | 14 |
| 3 | The plan must be written down somewhere, because GCP will not hold it for you | Section 06 of this page is that record | 0, 17 |
The project today
This is what you find the first time you open the project and look properly. Red numbers are problems; section 04 lists them.
- Run by Google
- Your VPC
- Allowed traffic and replies
Traffic from shoppers takes the right path: DNS, then the load balancer, then kade-api on port 8080. Everything around that path is either too open or missing. Solid lines work today; red dashed lines are problems.
Wide by design - scroll it sideways.
What is wrong today
Nothing here is unusual. This is what a project looks like when it was set up quickly with default settings, and it is close to what many real projects look like on their first audit.
| # | What we found | Why it is a problem | Fixed in |
|---|---|---|---|
| 1 | The default network still exists | GCP creates it with every new project. It has a subnet in every region and rules that open SSH, RDP and ping to the whole internet. No VM uses it today, but a VM created with default settings lands in it | Ch 2, 17 |
| 2 | kade-allow-ssh: port 22 from 0.0.0.0/0 to every VM | Any VM that gets an external IP can be reached by every SSH bot on the internet | Ch 6.1 |
| 3 | kade-allow-web: 80, 443, 8080 from 0.0.0.0/0 to every VM | Left over from when kade-api had its own external IP. It does nothing today, but the day any VM gets an external IP, the app is open without the load balancer in front | Ch 5.1 |
| 4 | kade-allow-internal: every port from 10.10.0.0/16 to every VM | Any VM in kade-vpc can reach kade-db on any port, not only kade-api on 5432 | Ch 5.1 |
| 5 | kade-api has no way to reach the internet | No external IP and no Cloud NAT, so apt update hangs and calls to PayGate fail. The workaround so far is to add a temporary external IP, which together with rules 2 and 3 opens the VM to the internet | Ch 7 |
| 6 | kade-api finds the database by a hardcoded IP, 10.10.2.5 | Moving or replacing the database means changing app config everywhere | Ch 8 |
| 7 | The database is a VM that you patch and back up by hand | Easy to forget, and it has to stay reachable for admin work | Ch 9 |
| 8 | Nothing is logged: no firewall rule logging, no VPC flow logs | When something is blocked or attacked, there is no record of it | Ch 16 |
| 9 | All VMs run as the default Compute Engine service account | Firewall rules cannot tell the VMs apart by identity (chapter 5). The IAM side of this is outside these notes | Ch 5.1 |
Where Kadé is going
This is the project after the last chapter. Each piece carries the chapter where it arrives. Dashed boxes belong to Google's side of the network, or to another project.
- Run by Google
- Your VPC
- Allowed traffic and replies
- Firewall and access rules
Shoppers now reach Kadé only through Cloudflare and the load balancer. Nothing in kade-vpc has an external IP. Admin access goes through IAP, outgoing calls through Cloud NAT, and the database is reachable only on a private IP. The default network is gone.
Wide by design - scroll it sideways.
The same change, piece by piece:
| # | Piece | Today | Target | Chapter |
|---|---|---|---|---|
| 1 | default network | Exists, with open rules | Deleted; an org policy stops new projects from getting one | 2, 17 |
| 2 | Firewall | Three broad rules for every VM | Rules aimed at service accounts, only the ports each one needs | 5 |
| 3 | Admin access | Temporary external IP, port 22 open to all | IAP; port 22 only from 35.235.240.0/20 | 6 |
| 4 | Outgoing calls | None, or a temporary external IP | Cloud NAT with a fixed IP, 34.87.200.7, on PayGate's allow list | 7 |
| 5 | Finding the database | Hardcoded 10.10.2.5 | db.kade.internal in a private DNS zone | 8 |
| 6 | Database | kade-db VM | Cloud SQL kade-sql, private IP only | 9 |
| 7 | The API | Two VMs | Cloud Run kade-api, reachable only through the load balancer | 10 |
| 8 | Background jobs | Inside the API VMs | One VM, kade-worker, no external IP | 10 |
| 9 | Front door | Load balancer only | Cloudflare, then the load balancer, which accepts only Cloudflare | 11-13 |
| 10 | Staging | None | Project kade-staging, 10.20.0.0/16 | 14 |
| 11 | Office | Over the public internet | HA VPN and Cloud Router (BGP) into kade-vpc | 15 |
| 12 | Logs | None | VPC flow logs, firewall rule logs, NAT logs | 16 |
The address plan
Builds on2. Private ranges3. CIDR
Because GCP will not hold the plan for us (section 02), this is the record. Every range Kadé uses is decided here once, and no two ranges overlap. Overlaps are cheap to avoid now and very hard to fix later, when networks need to be joined (chapters 14 and 15).
Solid teal: subnets that exist. Dashed teal: planned subnet. Dashed plum: handed to Google for managed services. Yellow: reserved. Grey: free.
Wide by design - scroll it sideways.
Every address used in these notes. Rows marked "Fundamentals" were already used there; the rest are new.
| # | Place | Thing | Address | First used |
|---|---|---|---|---|
| 1 | Home | Home LAN · your laptop | 192.168.1.0/24laptop 192.168.1.23 | Fundamentals |
| 2 | Home | Home router, public side | 203.0.113.45 | Fundamentals |
| 3 | Office | Office LAN (staff .1.0/24, warehouse .2.0/24) | 172.16.0.0/16 | Fundamentals |
| 4 | Office | Office router, public side | 198.51.100.20 | Fundamentals |
| 5 | GCP | Kadé's plan for kade-vpc (not a GCP setting) | 10.10.0.0/16 | Ch 0 |
| 6 | GCP | Subnet sn-app · gateway | 10.10.1.0/24gateway 10.10.1.1 | Fundamentals |
| 7 | GCP | kade-api-1, kade-api-2 (tag api) | 10.10.1.10 · 10.10.1.11 | Fundamentals |
| 8 | GCP | Subnet sn-data · kade-db | 10.10.2.0/24kade-db 10.10.2.5:5432, removed in ch 9 | Fundamentals |
| 9 | GCP | Load balancer front end | 34.120.88.10global, anycast | Fundamentals |
| 10 | GCP | Cloud NAT fixed outgoing IP (on PayGate's allow list) | 34.87.200.7 | Ch 7 |
| 11 | GCP | Private services range, for Cloud SQL | 10.10.32.0/20 | Ch 9 |
| 12 | GCP | Cloud SQL kade-sql, private IP | 10.10.32.3 | Ch 9 |
| 13 | GCP | Kept for Private Service Connect endpoints | 10.10.200.0/24 | Ch 9 |
| 14 | GCP | Subnet sn-run, for Cloud Run's outgoing traffic | 10.10.3.0/24 | Ch 10 |
| 15 | GCP | kade-worker VM | 10.10.1.20 | Ch 10 |
| 16 | GCP | kade-staging project's block | 10.20.0.0/16 | Ch 14 |
| 17 | VPN | BGP ASNs: Cloud Router · office router | 64512 · 65010 | Ch 15 |
Google's own addresses you will meet
These are real, fixed ranges that Google uses. They show up in firewall rules and logs, so it is worth knowing them on sight.
| # | Range | What it is | Where you meet it | Chapter |
|---|---|---|---|---|
| 1 | 169.254.169.254 | Metadata server, on every VM | DNS, time, VM details, service account tokens | 1, 8 |
| 2 | 10.128.0.0/9 | Ranges used by auto mode networks like default | default-allow-internal | 2 |
| 3 | 35.191.0.0/16 · 130.211.0.0/22 | Google front ends and health checkers | Source IPs on kade-api; kade-allow-lb | 11, 12 |
| 4 | 35.235.240.0/20 | IAP TCP forwarding | Source IP of SSH through IAP | 6 |
| 5 | 199.36.153.8/30 | private.googleapis.com | Reaching Google APIs without the internet | 9 |
| 6 | 199.36.153.4/30 | restricted.googleapis.com | The same, limited to services that support VPC Service Controls | 9, 17 |
Names used in every chapter
Resources get the same names in every diagram, command and table. Commands in these notes are written for these names, so you can read them as if the project were real.
| # | Kind | Name | First used |
|---|---|---|---|
| 1 | Project · region · zones | kade-prod · asia-southeast1 (Singapore) · -a, -b | Ch 0 |
| 1b | Organization · folder | kade.lk · production | Ch 5.2 |
| 2 | VPC network · subnets | kade-vpc · sn-app, sn-data, later sn-run | Ch 0, 10 |
| 3 | VMs | kade-api-1, kade-api-2, kade-db, later kade-worker | Ch 0, 10 |
| 4 | Service accounts (used as firewall targets) | sa-kade-api, sa-kade-db, sa-kade-worker | Ch 5.1 |
| 5 | Cloud Router · Cloud NAT · its IP | kade-router · kade-nat · kade-nat-ip | Ch 7 |
| 6 | DNS zones: public · private | kade-lk · kade-internal | Ch 8 |
| 7 | Private services range · Cloud SQL | kade-psa-range · kade-sql | Ch 9 |
| 8 | Cloud Run service | kade-api | Ch 10 |
| 9 | Load balancer parts | kade-lb-ip, kade-https-rule, kade-https-proxy, kade-url-map, kade-api-backend, kade-hc | Ch 11, 12 |
| 10 | Cloud Armor policy | kade-edge-policy | Ch 12, 13 |
| 11 | Staging project | kade-staging | Ch 14 |
| 12 | HA VPN · its Cloud Router · office side | kade-havpn · kade-vpn-router · kade-office-gw | Ch 15 |
Try it: where does this address belong?
Builds on12. Longest prefix match
Type any IPv4 address. The tool checks it against every range on this page and lists all the ranges it falls in, most specific first. This is the same longest-prefix idea that routing uses, and chapter 4 uses it again for GCP routes.
Best match: kade-api-1 (/32).
| Range | What it is | First used |
|---|---|---|
| 10.10.1.10/32 | kade-api-1VM in sn-app, zone a | Ch 0 |
| 10.10.1.0/24 | sn-appSubnet for app VMs | Ch 0 |
| 10.10.0.0/16 | Kadé plan for kade-vpcNot a GCP setting, only our plan | Ch 0 |
| 10.0.0.0/8 | Private rangeAny network may reuse it | Fundamentals ch 2 |
| 0.0.0.0/0 | The whole internetMatches every address: the default route | Fundamentals ch 5 |
5 ranges contain 10.10.1.10. The longest prefix, at the top, is the most specific answer.
How to read these notes
The layout is the same as the fundamentals course: numbered sections and diagrams, with a list of every command used at the end of each chapter. Colours mean something in every diagram:
| # | Colour | Means | Examples |
|---|---|---|---|
| 1 | Teal | Your VPC: subnets, internal IPs, routes, NAT | sn-app, kade-api-1, Cloud NAT |
| 2 | Plum | Run by Google, outside your VPC | Load balancer front ends, Cloud Run, Cloud SQL, IAP |
| 3 | Amber | Firewall and access rules | kade-allow-ssh, firewall policies |
| 4 | Ink | Networks outside GCP | Shoppers, home, office, Cloudflare, PayGate |
| 5 | Green | Allowed traffic and replies | A rule that matches and allows |
| 6 | Red | Problems and blocked traffic | Numbered findings, dropped packets |
The fundamentals course used colour for layers (TCP amber, IP green, and so on). Here the layers matter less than who owns a piece and whether traffic is allowed, so the colours change meaning. Where a chapter shows packet layers again, it says so in the caption.
Besides the boxes you know from the fundamentals course (definitions and notes), these notes add a few new ones:
Builds on10. NAT
A "Builds on" line sits under a heading and points to the fundamentals chapter the section builds on. If the idea feels new, read that chapter first.
The road ahead
Each chapter fixes one part of section 04 or adds one piece from section 05. The last column is what to re-read in the fundamentals course if it has faded.
| # | Chapter | Kadé's problem | Recall first (fundamentals course) |
|---|---|---|---|
| 0 | Kadé on GCP this page | Know the starting point | Scenario page |
| 1.1 | Regions, zones and Google's network | If zone b goes dark tonight, does the shop stay up? | Ch 12, 33 |
| 1.2 | The mental model: Andromeda and no layer 2 | Where did the router and the switch go? | Ch 5, 9, 18, 32 |
| 2 | VPC networks and subnets | The default network is still there | Ch 3 |
| 3 | IP addressing | An external IP changes after a restart | Ch 2, 3, 10 |
| 4 | Routing | A packet went a way nobody expected | Ch 5, 12 |
| 5.1 | Firewall 1: VPC firewall rules | Findings 3, 4 and 9 | Ch 16, 31 |
| 5.2 | Firewall 2: firewall policies | Keep the fixes from being undone; share rules across projects | None |
| 6.1 | Admin access 1: IAP TCP forwarding | Port 22 is open to everyone (finding 2) | Ch 29 |
| 6.2 | Admin access 2: OS Login and no external IPs | Old SSH keys still work on every VM | Ch 29 |
| 7 | Egress and Cloud NAT | No way out; PayGate needs one fixed IP | Ch 10 |
| 8 | DNS inside GCP | The database is a hardcoded IP | Ch 22, 23 |
| 9 | Private access to Google services | Move the database to Cloud SQL without a public IP | Ch 7, 10 |
| 10 | Serverless networking | Move the API to Cloud Run and keep the fixed IP | Ch 10, 33 |
| 11 | Load balancing 1: the family and how to choose | Which of the many load balancers is ours, and why | Ch 33 |
| 12.1 | Load balancing 2: inside the HTTPS load balancer | Health checks fail; the shopper's IP is lost | Ch 25, 33 |
| 12.2 | Load balancing 3: VMs behind the load balancer | A VM service that cannot scale, heal or update itself | Ch 33 |
| 13 | Cloudflare and GCP | Traffic can skip Cloudflare and hit the load balancer | Ch 22, 25, 33 |
| 14 | A second VPC, briefly | Kadé adds a staging project: connect it or not? | Ch 6 |
| 15 | Hybrid: VPN and Interconnect | The office needs a private path to GCP | Ch 12, 18 |
| 16.1 | Observability 1: what each log can tell you | Nobody can see what happened to a request | Ch 33 |
| 16.2 | Observability 2: monitoring, alerting and troubleshooting | Outages are reported by shoppers first | Ch 13 |
| 17 | Governance: keeping it fixed | Fixes keep drifting back; too many Owners | None |
| 18.1 | Capstone 1: a photo, through a VM to the database | Follow one request through everything, then break it | Ch 34 |
| 18.2 | Capstone 2: a payment, through Cloud Run to PayGate | The other backend and outgoing traffic; the whole network on one page | Ch 34 |
Commands in this chapter
All read-only. Replace kade-prod with your own project ID to run them on a real project.
Set the default project
- What it shows: Sets
kade-prodas the project for every later command. - What to look for: Nothing to check. It only saves typing
--projecteach time.
gcloud config set project kade-prodList the VPC networks
- What it shows: Every VPC network in the project, with its mode (auto or custom).
- What to look for: A
defaultnetwork that nobody meant to keep, and emptyIPV4_RANGEcolumns: a VPC has no range of its own.
gcloud compute networks listList the subnets of kade-vpc
- What it shows: Each subnet with its region and IP range.
- What to look for: Ranges that fit the address plan in section 06, and no overlaps.
gcloud compute networks subnets list --network=kade-vpcList firewall rules with sources and targets
- What it shows: Every firewall rule with where traffic may come from, which ports it opens, and which VMs it applies to.
- What to look for:
0.0.0.0/0next to admin ports like 22 or 3389, and rules with no target tags, which apply to every VM in the network.
gcloud compute firewall-rules list \ --format="table(name,network,sourceRanges.list(), allowed[].map().firewall_rule().list(),targetTags.list())"List the VMs
- What it shows: Every VM with its zone, internal IP and external IP.
- What to look for: Any external IP that should not be there. In Kadé's project today there are none.
gcloud compute instances listList reserved static IPs
- What it shows: IP addresses reserved in the project, internal and external.
- What to look for: The load balancer IP
34.120.88.10; from chapter 7, the NAT IP34.87.200.7.
gcloud compute addresses listList DNS records in the public zone
- What it shows: The records Cloud DNS serves for
kade.lk. - What to look for:
api.kade.lkpointing at34.120.88.10.
gcloud dns record-sets list --zone=kade-lk