The tension, and three private paths
Builds on2. Private and public addresses
Google's own services do not live inside your VPC. Cloud Storage, Secret Manager and Logging run on Google's servers, and Cloud SQL runs in a network Google manages. A VM normally reaches them through public addresses, just as it would reach any website:
- With an external IP, a call to
storage.googleapis.comworks, because that name resolves to a public Google address and the VM can reach public addresses. - Without one (chapter 6.2), that path is gone. Removing external IPs makes the VM safer, but also cuts it off from the services it needs.
GCP gives back a private path in three different ways. People mix them up constantly, because their names are so alike. The drawing shows all three; the sections after it take one each:
Three different shapes, all inside Google's network: a setting that lets traffic reach Google's APIs, a peering that joins Google's service network to yours, and an endpoint address that forwards to a service.
| # | Mechanism | Reaches | What it is | Kadé's use |
|---|---|---|---|---|
| 1 | Private Google Access (PGA) | Google APIs: Cloud Storage, Secret Manager, Logging… | A setting on a subnet | kade-worker's backups to Cloud Storage |
| 2 | Private services access (PSA) | Managed services that run in Google's own network: Cloud SQL, Memorystore | A VPC peering to Google's network, using an IP range you hand over | Cloud SQL kade-sql at 10.10.32.3 |
| 3 | Private Service Connect (PSC) | Google APIs, Cloud SQL, or a service another company publishes | An endpoint: one internal IP in your VPC that forwards to the service | Not needed yet; 10.10.200.0/24 is kept for it |
Private Google Access
PGA is not something you create or run. It is a setting on a subnet (privateIpGoogleAccess, chapter 2). When it is on, a VM in that subnet with no external IP may send traffic to Google APIs. A VM with an external IP ignores the setting, because it already has a way out.
Where does that traffic go? The VM still sends it to Google's normal public addresses, through the route named default-internet-gateway. The name is misleading: for addresses that belong to Google's APIs, the "gateway" hands the packet straight to Google's front ends, and it never leaves Google's network. What PGA changes is permission: without it, Google drops traffic from a private address on the way to those public ones. With it, Google accepts it.
What decides the path is two things you already know: DNS (chapter 8), which picks the address, and routes (chapter 4), which pick the next hop. There are three ways to set those up. Each tab follows one call from kade-worker; the "what if" buttons break one piece at a time.
Works: Cloud Storage reached with no external IP
DNS is untouched: storage.googleapis.com resolves to a normal Google address. The default route sends it towards the internet gateway, and because the subnet has PGA on, Google accepts it from a VM with no external IP and keeps it on its own network.
Show as config
sn-app: privateIpGoogleAccess = true kade-vpc route: 0.0.0.0/0 → default-internet-gateway (priority 1000) DNS: unchanged kade-worker → storage.googleapis.com → Google address → default route → Google network → Cloud Storage
| # | Default domains | private.googleapis.com | restricted.googleapis.com | |
|---|---|---|---|---|
| 1 | Addresses | Google's normal public addresses | 199.36.153.8/30 | 199.36.153.4/30 |
| 2 | DNS change needed | None | Yes: private zone or response policy (chapter 8) | Yes, same |
| 3 | Route needed | The default route to the internet gateway | The default route, or a specific route for 199.36.153.8/30 | The default route, or a specific route for 199.36.153.4/30 |
| 4 | APIs reachable | All | Most Google APIs | Only APIs that support VPC Service Controls |
| 5 | Good for | Most setups. Kadé's choice | Networks with no default route | Projects inside a VPC Service Controls perimeter (chapter 17) |
Private services access
Cloud SQL, Memorystore and similar services do not run in your project. Google runs them on VMs in its own projects, inside a VPC that Google manages: the service network. You never see it, log in to it or pay for it separately. Your VPC and that network are separate worlds with no route between them (chapter 2 section 01). A public IP bridges the gap by putting the database on the internet, which is exactly what Kadé wants to avoid.
Private services access joins the two networks with VPC peering, the same feature you would use to join two of your own VPCs. Because the networks are joined, the database needs an address that clashes with nothing on your side, so you set aside a range and Google takes the database's IP from it. Two steps, done once per VPC:
| # | Step | What it creates | Kadé's value |
|---|---|---|---|
| 1 | Allocate a range | An internal address range with purpose VPC_PEERING. Google hands managed services their IPs from it | kade-psa-range = 10.10.32.0/20 (chapter 0 plan) |
| 2 | Create the private connection | A VPC peering named servicenetworking-googleapis-com, made through the Service Networking API | Between kade-vpc and Google's service network |
--network=kade-vpc still runs in Google's service network. It takes its IP from the range, and kade-vpc reaches it over the peering. No public IP, no authorized networks list.Because it is real VPC peering, it follows peering's rules. The tabs show who can and cannot reach kade-sql:
kade-worker and Cloud Run reach 10.10.32.3 over the peering
kade-vpc and Google's service network are joined by one VPC peering. Everything in kade-vpc that reaches 10.10.32.0/20 crosses it: kade-worker in sn-app and Cloud Run through sn-run. Nothing goes near the internet, and there is no authorized networks list to maintain.
Show as config
kade-psa-range: 10.10.32.0/20, purpose VPC_PEERING peering: kade-vpc ⇄ servicenetworking-googleapis-com kade-sql: private IP 10.10.32.3 kade-worker (10.10.1.20) → 10.10.32.3:5432 ✓ kade-api via sn-run → 10.10.32.3:5432 ✓
| # | Peering rule | Consequence |
|---|---|---|
| 1 | Not transitive | A VPC peered to kade-vpc (like kade-staging in chapter 14) cannot reach kade-sql through kade-vpc. No firewall rule fixes it; the routes simply do not pass along |
| 2 | No overlapping ranges | The allocated range must not overlap any subnet or any other network you connect. This is why it is in the chapter 0 plan |
| 3 | Size it once | Google asks for at least a /24; services in several regions take more. Adding a second range later is possible but needs the connection updated. Kadé's /20 leaves room |
| 4 | Custom routes are not shared by default | Google's network only learns your subnet routes. Routes to the office (VPN) must be exported on the peering explicitly (Tab C) |
- Run by Google
- Your VPC
- Allowed traffic and replies
Wide by design - scroll it sideways.
Private Service Connect
PSC turns the model around. Instead of flagging a subnet or peering two networks, you create an endpoint: one internal IP inside your own VPC that forwards to a service somewhere else. Under the hood it is a forwarding rule, the same kind of object as a load balancer's front (chapter 12.1), but with a private IP.
Two roles appear in every PSC setup:
- The consumer is you. You create the endpoint, pick its IP, and your VMs send traffic to it like any other internal address.
- The producer runs the service. It publishes the service through a service attachment, and Google carries traffic from your endpoint to it. For Google APIs and Cloud SQL, Google is the producer. For a vendor's service, the vendor is.
Nothing is peered, so there is no transitivity problem, and each endpoint is one IP with its own firewall rules and logs.
Your own private address for Google APIs, with its own firewall rules and logs
The endpoint kadeapis is a global internal IP that you pick, outside every subnet (10.10.200.2, from the reserve in chapter 0). It forwards to Google APIs. GCP also creates DNS names like storage-kadeapis.p.googleapis.com, or you point *.googleapis.com at it with a private zone. Because it is your own address, you can write firewall rules and read logs for exactly this traffic.
Show as config
gcloud compute addresses create kadeapis-ip --global --purpose=PRIVATE_SERVICE_CONNECT \ --addresses=10.10.200.2 --network=kade-vpc gcloud compute forwarding-rules create kadeapis --global --network=kade-vpc \ --address=kadeapis-ip --target-google-apis-bundle=all-apis
| # | Target | Endpoint address | What you get |
|---|---|---|---|
| 1 | Google APIs | A global internal IP outside your subnets, e.g. 10.10.200.2 | Your own address for Google APIs instead of PGA's shared ranges, with its own DNS names |
| 2 | A published service | An internal IP from a subnet, e.g. 10.10.1.50 | GCP's version of AWS PrivateLink: a vendor publishes a service, you consume it on an internal IP, and neither side is exposed to the internet |
| 3 | Cloud SQL | An internal IP from a subnet, in each VPC that needs it | Cloud SQL without the peering model, so several VPCs can each have their own endpoint |
Choosing between them
| # | PGA | PSA | PSC | |
|---|---|---|---|---|
| 1 | What you create | Nothing: a subnet setting | A range and one peering per VPC | One endpoint per service per VPC |
| 2 | Address the VM uses | Google's addresses | An IP from your allocated range | An IP you choose in your VPC |
| 3 | Other peered VPCs | Use their own PGA | cannot reach it | each gets its own endpoint |
| 4 | Office over VPN | Needs extra DNS and route setup | Needs route export and advertising | Reaches the endpoint IP like any VPC address |
| 5 | Separate firewall and logs per service | No | Per range | Yes, per endpoint |
| 6 | Cost | Free | No charge for the connection | Endpoints and data processed are billed; check pricing |
| # | You want to… | Use |
|---|---|---|
| 1 | Let a VM without an external IP call Google APIs | PGA |
| 2 | Give Cloud SQL or Memorystore a private IP in one VPC | PSA |
| 3 | Reach Google APIs on your own controllable address | PSC (Google APIs) |
| 4 | Use another company's service privately | PSC (published service) |
| 5 | Reach one Cloud SQL instance from many VPCs | PSC (Cloud SQL) |
Cloud SQL with private IP, in practice
A private IP removes the database from the internet. A few more settings decide whether it is actually locked down:
| # | Setting | Kadé's value | Why |
|---|---|---|---|
| 1 | Public IP | off | With it on, the instance is reachable from the internet by anything on the authorized networks list |
| 2 | Authorized networks | empty | Only applies to the public IP. Private IP connections ignore it |
| 3 | SSL mode | ENCRYPTED_ONLY | A private IP is not encryption. Without this, the database accepts unencrypted connections, and passwords cross the network in clear text |
| 4 | How apps connect | Cloud SQL connector or Auth Proxy | Handles TLS and can use IAM database login, so the app holds no long-lived password |
| 5 | Firewall | no new ingress rule | kade-sql lives in Google's network, so kade-vpc's ingress rules never see it. Your egress rules still apply to traffic towards 10.10.32.0/20 |
The move from kade-db to kade-sql
Each step can be checked before the next one starts, and nothing shopper-facing changes until step 6:
Before the day
- 1.Range + connectionAllocate kade-psa-range, create the private connection (command 7)check before moving oncommands 2-3 show the range
- 2.Create kade-sqlPrivate IP only, ENCRYPTED_ONLY, regional HA (command 8)check before moving oncommand 4: no public IP
- 3.Copy the dataDatabase Migration Service, or dump and restore in a quiet hourcheck before moving onrow counts match on both
- 4.Lower the TTLdb.kade.internal TTL 300 → 30, a day before (chapter 8)check before moving ondig shows TTL 30
Cutover
- 5.Short write freezeStop writes to kade-db, final sync to kade-sqlcheck before moving onno new rows on kade-db
- 6.Flip the namedb.kade.internal → 10.10.32.3, recycle app connection poolscheck before moving onnew connections reach kade-sql
After
- 7.WatchErrors, latency, Cloud SQL connections; kade-db kept stopped, not deletedcheck before moving ona few days with no issues
- 8.Clean upDelete kade-db, kade-db-ip, kade-api-to-db, kade-run-to-db; TTL back to 300check before moving onfirewall list has no db rules
Steps 1 to 4 change nothing for shoppers. The only moment of risk is steps 5 and 6, and the way back is to point the name at 10.10.2.5 again: kade-db is stopped, not deleted, until step 8.
Back to Kadé
Commands in this chapter
Commands 1 to 5 are read-only. Commands 6 to 9 change the project.
Check Private Google Access on each subnet
- What it shows: Whether PGA is on for every subnet in kade-vpc.
- What to look for:
Trueon every subnet with VMs that have no external IP.
gcloud compute networks subnets list --network=kade-vpc \ --format="table(name,region.basename(),ipCidrRange,privateIpGoogleAccess)"List the private services access connection
- What it shows: The peering to Google's service network and the ranges it uses.
- What to look for:
servicenetworking-googleapis-comwithkade-psa-rangeinreservedPeeringRanges.
gcloud services vpc-peerings list --network=kade-vpcList ranges allocated for peering
- What it shows: Internal ranges with purpose
VPC_PEERING, and their size. - What to look for: The same ranges as command 2. If they disagree, sort that out before creating anything.
gcloud compute addresses list --global --filter="purpose=VPC_PEERING" \ --format="table(name,address,prefixLength,network.basename())"See how a Cloud SQL instance is connected
- What it shows: Public IP on or off, the private network, authorized networks and SSL mode.
- What to look for:
ipv4Enabled: false,privateNetworkset to kade-vpc, no authorized networks,sslMode: ENCRYPTED_ONLY.
gcloud sql instances describe kade-sql --format="yaml(ipAddresses,settings.ipConfiguration)"Check the peering's route export settings
- What it shows: Whether kade-vpc shares its custom routes (such as VPN routes) with Google's service network.
- What to look for:
exportCustomRoutes: trueonce the office needs to reach kade-sql (chapter 15).
gcloud compute networks peerings list --network=kade-vpcTurn on Private Google Access for a subnet (changes the project)
- What it shows: The setting for a subnet that Cloud NAT does not cover.
- What to look for:
Truein command 1.
gcloud compute networks subnets update sn-data \ --region=asia-southeast1 --enable-private-ip-google-accessAllocate the range and create the connection (changes the project)
- What it shows: The two one-time steps of private services access.
- What to look for: Commands 2 and 3 both show
kade-psa-range. Needs the Service Networking API enabled.
gcloud compute addresses create kade-psa-range --global \ --purpose=VPC_PEERING --addresses=10.10.32.0 --prefix-length=20 --network=kade-vpcgcloud services vpc-peerings connect --service=servicenetworking.googleapis.com \ --ranges=kade-psa-range --network=kade-vpcCreate Cloud SQL with a private IP only (changes the project)
- What it shows: kade-sql on kade-vpc, from kade-psa-range, with no public IP and encrypted connections only.
- What to look for: Command 4 shows the private address and no public one. Pick a machine size that suits your load.
gcloud sql instances create kade-sql --database-version=POSTGRES_16 \ --region=asia-southeast1 --availability-type=REGIONAL --tier=db-custom-2-7680 \ --network=kade-vpc --allocated-ip-range-name=kade-psa-range \ --no-assign-ip --ssl-mode=ENCRYPTED_ONLYShare VPN routes with Google's service network (changes the project)
- What it shows: Half of what the office needs to reach kade-sql (psaex tab C). The other half is the Cloud Router advertising
10.10.32.0/20to the office (chapter 15). - What to look for:
exportCustomRoutes: truein command 5.
gcloud compute networks peerings update servicenetworking-googleapis-com \ --network=kade-vpc --export-custom-routes