Chapters

Capstone 2: a payment, through Cloud Run to PayGate

The second walk takes the other kind of backend and the other direction of travel: a checkout request handled by Cloud Run, which writes to Cloud SQL and calls an outside payment provider through Cloud NAT. Chapter 18.1 explained the shared front half in detail, so this walk moves quickly there and slows down where Cloud Run and outgoing traffic are different. The chapter ends with Kadé's whole network on one page.

Running it · chapter 26 of 26 · 3 min read

The walk

The same three modes as chapter 18.1: request path, return path, and break it.

kade-vpc · sn-runShopper203.0.113.99Cloudflare edgeColomboGoogle LBfront end · ArmorCloud Runkade-apiVPC egresssn-run 10.10.3.17Cloud DNSprivate zoneCloud SQL10.10.32.3Cloud NAT34.87.200.7PayGateapi.paygate.lk
hop 1 of 8

hop 1 of 8 · To Cloudflare

What happens

DNS and the edge leg work as in chapter 18.1. Differences: a Cache Rule bypasses cache for api.kade.lk, and Cloudflare's own rate limit on checkout runs here, keyed on the real shopper.

Decided by

Orange record; Cache Rule bypass for the API; Cloudflare rate limiting (chapter 13)

Packet

203.0.113.99:51310 → 104.21.48.12:443 POST /v1/checkout · JSON body

Recorded in

Cloudflare analytics (CF-Ray 8c1b…-CMB)

What is different from the VM path

#VM path (18.1)Cloud Run path (this chapter)
1BackendInstance group, VMs in sn-appServerless NEG, instances in Google's network
2Health checksTwo: load balancer and autohealingNone: Cloud Run manages instances itself
3Who may reach the backendFirewall rule from Google's ranges to the service accountCloud Run's ingress setting
4Enters kade-vpcAlready insideOnly for outgoing traffic, through Direct VPC egress
5VPC Flow Logs see shopper trafficYes, the load balancer to VM legNo; only the outgoing calls from sn-run
6Outgoing to the internetCloud NAT on sn-appCloud NAT on sn-run, needs all-traffic
7Scaling limit to watchMax VMs in the groupMax instances, and NAT ports at that size

Kadé's whole network, on one page

Everything the course built, with the real names. Use it as a map when something breaks, or as a checklist when building a network like it:

OUTSIDE GCPShoppersphones, browsersCloudflareDNS for kade.lk · proxyWAF · cache · Full (strict)Kadé office172.16.0.0/16↔ HA VPN + BGPPayGateallows 34.87.200.7← calls via Cloud NATGOOGLE FRONT DOORGlobal external App LB34.120.88.10 · :443 + :80cert map · SSL policy kade-tlskade-url-mapapi.kade.lk → kade-apiwww → static · /media/* → mediaCloud Armor kade-edge-policyCloudflare + secret headerWAF · rate limit per visitorkade-api-backendserverless NEG→ Cloud Run kade-apikade-media-backendinstance group · RATE 80→ kade-media-mig (sn-app)kade-staticbucket · Cloud CDNCloud Run kade-apiingress: internal + LBegress: Direct VPC → sn-runkade-prod · kade-vpc · plan 10.10.0.0/16 · asia-southeast1sn-app 10.10.1.0/24kade-media-migregional · 2-8 VMskade-worker10.10.1.20 · inventory APIsn-run 10.10.3.0/24Cloud Run egress addressessn-data 10.10.2.0/24: emptyPSA 10.10.32.0/20 (peering)Cloud SQL kade-sql10.10.32.3 · TLS onlyFirewall (by service account)lb-to-media · IAP SSHwarehouseCloud NAT kade-nat34.87.200.7 · kade-routerHA VPN kade-havpn2 tunnels · kade-vpn-routerBGP 64512 ↔ 65010Cloud DNSprivate zone kade.internaldb · worker · fwd office.kade.lanPrivate Google Accesson all subnetsCloud Storage · Secret ManagerAdmin accessIAP · OS Loginno external IPs anywhereGOVERNANCE · org kade.lk / folder productionorg policies: no external IPs · no public Cloud SQLCloud Run ingress · no default network · OS Loginno service account keysfolder firewall policy: no 22/3389 from internetVPC-SC dry run · CI writesOBSERVABILITYLB logs 100% · Cloud Run JSON logs with CF-Rayflow logs sn-app, sn-run · NAT errors · dashboard (6 panels)8 alerts · uptime check via Cloudflaresaved Connectivity Tests · Ops Agent on VMs

Shopper → Cloudflare → load balancer → URL map → Cloud Armor → one of three backends. Everything a backend calls goes out through kade-vpc on the right.

Chapter 0's findings, closed

#Finding in chapter 0NowFixed in
1The default network still existsclosed Deleted; an organization policy stops new projects getting one2, 17
2kade-allow-ssh: port 22 open to everyoneclosed IAP only, from 35.235.240.0/20; folder policy blocks 22 from the internet; OS Login6.1, 6.2, 5.2
3kade-allow-web: 80, 443, 8080 open to everyoneclosed Deleted; only Google's front ends reach backends, by service account5.1
4kade-allow-internal: every port between all VMsclosed Deleted; the database is Cloud SQL on a private IP5.1, 9
5No way to reach the internetclosed Cloud NAT with 34.87.200.7 on PayGate's allow-list7, 10
6Hardcoded database IPclosed db.kade.internal in a private zone8
7Database VM patched and backed up by handclosed Cloud SQL, private IP only, encrypted connections, automatic backups9
8Nothing is loggedclosed Load balancer, flow, firewall and NAT logs; dashboard; eight alerts16.1, 16.2
9All VMs run as the default service accountclosed One service account per role; firewall rules target them5.1, 12.2

Self-check

Six questions about this path and the course as a whole:

  1. 1.PayGate rejects Kadé's calls after a deploy. The Cloud Run service shows egress private-ranges-only. Why does that matter?

  2. 2.Why do VPC Flow Logs never show the shopper's request reaching kade-api?

  3. 3.Some payments fail only at peak, and the NAT log shows OUT_OF_RESOURCES. What is the first fix to try?

  4. 4.What lets Cloud Run accept requests from the load balancer but not from its run.app address?

  5. 5.Which control stops a developer re-adding an external IP to a VM next month?

  6. 6.Cloud Armor rate-limits by source IP and many shoppers get 429. Why?

0 of 0 right · 6 left

Where to go from here

#Next stepWhy
1Apply the rollout plans in chapters 16.2 and 17 to a real projectThey are ordered by value for effort; Day 1 of each takes about an hour
2Write the network as code (Terraform)Turns this course's settings into something reviewed and repeatable (chapter 17 section 09)
3Multi-VPC design, if you grow into itChapter 14 section 06 lists the topics, in order
4The exam-angle boxes across the chaptersTogether they cover the networking questions in Google's associate and professional cloud exams

Spotted a mistake, or something unclear? Suggest an edit on GitHub