Home› Blog› Week 14 — Private Service Connect: What "Private" …
GCP Weekly Lab GCP Terraform

What "private" actually means

A VM with no external IP calls a Google API two different ways. Then one route is deleted, and only one of them survives.

Verified against current vendor documentation on 22 November 2026. Pricing, limits and API behaviour were checked against the official docs on that date. Cloud services change fast — if you are reading this much later, treat the specifics as a starting point and re-check the linked sources.
GCP Platform Engineering Lab · Week 14 of 58

Lab Overview

An auditor asks a team a simple question: can this machine reach the internet? The team says no — it has no public address. The auditor asks how it reads from Cloud Storage, then. It turns out the answer is "over the internet gateway, to Google's public addresses", and the two statements are both true at once.

The problem. "Private" is doing two different jobs in that sentence. Private Google Access means the virtual machine has no external IP of its own. It does not mean the traffic avoids Google's public address space, and it does not work without a route to the internet gateway. A Private Service Connect endpoint is a different thing entirely: an address inside your own network.

The objective. Build both on one VM, then delete the VPC's default route to the internet gateway and see which path survives.

Expected outcome. One call keeps working and one stops, with nothing else changed — not the machine, not the subnet setting, not the firewall. If both survive, something is carrying the traffic that shouldn't be, and the lab has proved nothing.

Deployment method. Terraform on HCP Terraform agents with no stored credentials; the workspace mints an OIDC token per run and exchanges it for a short-lived Google token. Built in Week 02.

What this gives app teams

CapabilityWho consumes itWhat it replacesWhat it costs them
Reach Google APIs from a workload with no external IP and no internet routeAny team under a no-egress ruleA ticket to networking, a NAT exception, or an argument with an auditorNothing to configure — the subnet and endpoint are platform-owned
A re-runnable answer to "prove it cannot reach the internet"Risk, audit, complianceAn assertion in a design documentOne command they can run themselves

Cloud Services and Concepts

ServicePurpose hereWhat it is
Private Service ConnectGives the VPC its own address for Google APIsA way to reach a service through an internal IP in your network instead of the service's public address. For Google APIs it is a global forwarding rule pointed at a bundle of APIs.
Private Google AccessThe thing being compared againstA per-subnet setting that lets a VM with no external IP reach Google's own public addresses, routed out through the VPC's default internet gateway.
VPC and subnetsThe network under testA private network and a regional range inside it. Custom mode means nothing exists until declared.
Cloud RoutesWhat the experiment deletesA VPC's routing table. The default route sends anything not local to the internet gateway, and Google creates it with the network.
Compute EngineOne probe VMThe client. An instrument rather than the subject — something has to make the call.
Identity-Aware ProxyShell access without a public addressTunnels SSH through Google's infrastructure, so the VM needs no external IP and no bastion.
Terraform & HCP TerraformDeclares it and applies it remotelyInfrastructure as code, run on hosted agents that authenticate per run through Workload Identity Federation, so no key is stored.

The difference that this week turns on

Google's own comparison of private access options puts it plainly. Private Google Access connects "to the standard external IP addresses or Private Google Access domains and VIPs for Google APIs and services through the VPC network's default internet gateway." Those domains have addresses you can look up: private.googleapis.com is 199.36.153.8/30, and restricted.googleapis.com is 199.36.153.4/30. They belong to Google.

The configuration guide states the dependency directly: "Your VPC network must have appropriate routes whose next hops are the default internet gateway." Private Google Access is a routing arrangement, not a private channel.

A Private Service Connect endpoint is an internal IP address in your own VPC. Traffic to it never needs a route off the network, because it never leaves. And the address must sit outside every subnet range — Google rejects one inside, because it "can't be within the range of subnets configured in the VPC network."

There is a second difference that usually matters more in practice than anything here: a PSC endpoint "can be accessed from supported connected on-premises hosts" over Cloud VPN or Interconnect, and Private Google Access cannot. Neither works through VPC Network Peering. This lab does not build the hybrid case, so that is documentation, not evidence.

Architecture and Workflow

A probe VM with no external IP inside a subnet, reaching Google APIs two ways. One goes to a Private Service Connect endpoint on an address reserved inside the VPC but deliberately outside any subnet range. The other goes up through the VPC's default internet gateway to Google's own public addresses, which is what Private Google Access does. Deleting the default route breaks the second path and leaves the first working.
Two lanes out of one machine. The bottom one stays inside the VPC; the top one leaves through the gateway.
  1. A VPC of its own is created, so deleting its default route cannot affect anything else.
  2. A subnet is created with private_ip_google_access = true. That flag is the whole of Private Google Access.
  3. A global internal address is reserved with purpose PRIVATE_SERVICE_CONNECT, deliberately outside the subnet range.
  4. A global forwarding rule targets all-apis at that address — the endpoint.
  5. One e2-micro is created with no external IP and no NAT anywhere on the network.
  6. The same API call runs twice from that VM: once on default DNS, once pinned to the endpoint.
  7. The default internet-gateway route is deleted, both calls repeat, and the route is restored.

Design decisions worth stating

Its own VPC, not the shared hub. The hub's subnets already have Private Google Access enabled, so reusing them would mean demonstrating something the week did not build. More importantly, the experiment deletes a default route, and doing that on a shared network would degrade every other workload on it.

--resolve rather than DNS. In production a private DNS zone maps storage.googleapis.com to the endpoint, so existing code uses it unmodified. Here both calls have to run side by side from one machine, and a curl flag is the honest way to hold everything else constant.

No Cloud NAT. This is asserted, not assumed. With a NAT on the network both paths would work regardless of mechanism, and the comparison would prove nothing.

Prerequisites

  • A project with Compute Engine enabled (Week 01).
  • Keyless CI through Workload Identity Federation (Week 02). No permissions were added this week; Week 13's grants were already enough.
  • IAP TCP forwarding, because the probe has no public address and no bastion exists.
  • Address space that does not overlap anything else — and a spare address outside every subnet for the endpoint itself.

Implementation

What was deployed

WhatHow manyIts job
VPC and subnet1 + 1Its own network; the subnet carries the Private Google Access flag
Global internal address1PRIVATE_SERVICE_CONNECT, outside every subnet range
Global forwarding rule1target = "all-apis" — the endpoint
Firewall rule1IAP range only, for SSH to a VM with no public address
Probe VM1e2-micro, no external IP

Six resources.

Step 1 — A subnet that allows Private Google Access

resource "google_compute_subnetwork" "psc" {
  name                     = "psc-lab-${var.region}"
  network                  = google_compute_network.psc.id
  ip_cidr_range            = var.subnet_cidr      # 10.40.0.0/24
  private_ip_google_access = true
}

One boolean. That is the entire feature.

Step 2 — An address of our own, outside the subnet

resource "google_compute_global_address" "psc" {
  purpose      = "PRIVATE_SERVICE_CONNECT"
  address_type = "INTERNAL"
  address      = var.endpoint_ip                  # 10.99.0.2
  network      = google_compute_network.psc.id
}

resource "google_compute_global_forwarding_rule" "psc" {
  name                  = "pscapis"
  target                = "all-apis"
  network               = google_compute_network.psc.id
  ip_address            = google_compute_global_address.psc.id
  load_balancing_scheme = ""
}

10.99.0.2 is deliberately far from 10.40.0.0/24. That is required: the endpoint address cannot sit inside a subnet range.

Step 3 — Deploy it

HCP Terraform workspace run list for gcp-week-14 showing four runs, two errored and two successful, with six resources under management and the current run applied
Six resources, applied. Two runs errored first: one on the forwarding-rule name, and one before the workspace had credentials at all — both in Troubleshooting.

Step 4 — What came up

Terminal output showing the reserved address 10.99.0.2 with purpose PRIVATE_SERVICE_CONNECT and type INTERNAL, the subnet psc-lab-us-central1 on 10.40.0.0/24 with Private Google Access True, and the forwarding rule pscapis targeting all-apis at 10.99.0.2
The address is ours and is not a Google VIP. Note it sits outside the subnet range, which Google requires.

Step 5 — Both paths, from a machine with no external IP

Terminal output showing the baseline measurement: Private Google Access returns 401 and the PSC endpoint returns 401, both from the same VM
401 on both. The call reached Google and was refused for lack of credentials — which is what proves the network path completed.

Validation: both report 401, not 000. A path that does not work never opens a connection at all.

Validation and Evidence

The experiment

Terminal output after deleting the default internet gateway route: Private Google Access returns 000 and the PSC endpoint still returns 401
One route deleted. Private Google Access has no path; the endpoint does not notice.
Terminal output after restoring the route: Private Google Access returns 401 again and the PSC endpoint returns 401
Restored. This is what shows the failure was caused by the route and nothing else.
TestExpected resultActual resultStatus
Endpoint address is ourspurpose PRIVATE_SERVICE_CONNECT10.99.0.2, PRIVATE_SERVICE_CONNECT, INTERNALPass
Endpoint sits outside every subnetNot inside 10.40.0.0/24Outside, asserted programmaticallyPass
Probe has no external IPemptyemptyPass
No NAT on the network0 routers0Pass
Both paths work at baseline401 and 401401 and 401Pass
Route deletedPGA fails, PSC survivesPGA 000, PSC 401Pass
Route restoredBoth work again401 and 401Pass

What the status codes prove. 401 means the request reached Google and was rejected for want of credentials: the network path completed. 000 is curl's code for a connection that never opened. The jump from 401 to 000 on one path, while the other is unchanged, is the finding. Twelve further assertions about the deployment itself ran from validate.sh and all passed — its output is committed, as is the raw measurement.

One honest limit. Every call returned 401, so this tested the network path and not authorisation. A workload with a service account would get a 200, and that would be a test of IAM rather than of routing.

Security and Cost

Security

  • The probe has no external address and there is no NAT. Shell access is through Identity-Aware Proxy, so no bastion exists and no port is open to the internet.
  • The firewall names the IAP range explicitly rather than allowing SSH from anywhere.
  • The VM carries enable-oslogin and block-project-ssh-keys, because the organization's policies refuse to create it otherwise.
  • No service account keys, as in every week of this lab.
  • This week removes a route, not a possibility. A workload with some other path out could still reach the internet. The control that makes exfiltration structurally impossible is a VPC Service Controls perimeter, which is a later week.

Cost

ItemRateThis run
Private Service Connect endpoint$0.01 / hour~1.2 hours
Data transfer to Google APIs over the endpointno charge$0
Probe VMe2-micro, us-central1, no external IPfree tier
VPC, subnet, routes, firewallno charge$0

Measured cost: not yet available. The charges had not posted when this was written, and the figure above is the rate, not the bill. This section will be updated with the observed number and the time it was read — a billing export is not final on the day it is queried, and the previous week's returned two different totals forty minutes apart.

Troubleshooting and Lessons

The forwarding rule name has its own rules

Problem: the apply failed with Invalid value for field 'resource.name': 'psc-apis'.
Root cause: a Private Service Connect rule for Google APIs accepts a 1–20 character name of lowercase letters and digits, starting with a letter. Hyphens are not allowed, and every other name in this lab uses them.
Resolution: pscapis.
Lesson: a naming convention that holds everywhere else is exactly the kind of thing that stops being checked. The error names the field, which is more than many do.

A filter the API rejects, inside a script that hides the rejection

Problem: the validation script stopped silently after printing a section header.
Root cause: gcloud compute routes list rejects a three-term server-side filter with Invalid list filter expression. Inside a command substitution under set -e, that killed the script with no visible error.
Resolution: filter on the network only and select the route locally.
Lesson: a failure inside $(...) has nowhere to print. The symptom is output that simply stops.

Restoring a route you do not own blocks the teardown

Problem: terraform destroy failed on the network: already being used by routes/default-route-<hash>.
Root cause: Google creates that default route when the network is created, so Terraform never owned it. The experiment deletes it and recreates it — and the recreated route is now an object Terraform cannot remove.
Resolution: delete the route by hand, then destroy again. Nothing bills in the meantime; a route and a network are free.
Lesson: restoring a resource is not the same as returning the system to its prior state. The route came back with the same name and the same behaviour, and still broke something, because its ownership changed.

Cleanup and Key Takeaways

Cleanup

terraform destroy removes all six resources, after the manual route delete above. Verified afterwards by querying Cloud Asset Inventory across the organization for fifteen billable resource types and finding none — a sweep that fails loudly if it cannot see anything, rather than reporting good news when it is blind.

Key takeaways

  • "Private" in Private Google Access describes the VM, not the traffic. The machine has no external IP; the packets still go to Google's public addresses through the internet gateway.
  • A Private Service Connect endpoint is an address you own, inside your VPC, and it must sit outside every subnet range.
  • The difference is invisible until you remove the route — which is why it is worth removing one.
  • The real decision is usually reachability, not price. A PSC endpoint answers from on-premises over Cloud VPN; Private Google Access does not. Neither works through VPC peering.
  • Removing a route is not the same as removing a possibility. That takes a service perimeter, and it is a later week.

References

Comments

How was your experience?
Your feedback helps improve this site.
PoorExcellent