📋 In This Post
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
| Capability | Who consumes it | What it replaces | What it costs them |
|---|---|---|---|
| Reach Google APIs from a workload with no external IP and no internet route | Any team under a no-egress rule | A ticket to networking, a NAT exception, or an argument with an auditor | Nothing to configure — the subnet and endpoint are platform-owned |
| A re-runnable answer to "prove it cannot reach the internet" | Risk, audit, compliance | An assertion in a design document | One command they can run themselves |
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| Private Service Connect | Gives the VPC its own address for Google APIs | A 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 Access | The thing being compared against | A 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 subnets | The network under test | A private network and a regional range inside it. Custom mode means nothing exists until declared. |
| Cloud Routes | What the experiment deletes | A VPC's routing table. The default route sends anything not local to the internet gateway, and Google creates it with the network. |
| Compute Engine | One probe VM | The client. An instrument rather than the subject — something has to make the call. |
| Identity-Aware Proxy | Shell access without a public address | Tunnels SSH through Google's infrastructure, so the VM needs no external IP and no bastion. |
| Terraform & HCP Terraform | Declares it and applies it remotely | Infrastructure 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 VPC of its own is created, so deleting its default route cannot affect anything else.
- A subnet is created with
private_ip_google_access = true. That flag is the whole of Private Google Access. - A global internal address is reserved with purpose
PRIVATE_SERVICE_CONNECT, deliberately outside the subnet range. - A global forwarding rule targets
all-apisat that address — the endpoint. - One e2-micro is created with no external IP and no NAT anywhere on the network.
- The same API call runs twice from that VM: once on default DNS, once pinned to the endpoint.
- 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
| What | How many | Its job |
|---|---|---|
| VPC and subnet | 1 + 1 | Its own network; the subnet carries the Private Google Access flag |
| Global internal address | 1 | PRIVATE_SERVICE_CONNECT, outside every subnet range |
| Global forwarding rule | 1 | target = "all-apis" — the endpoint |
| Firewall rule | 1 | IAP range only, for SSH to a VM with no public address |
| Probe VM | 1 | e2-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
Step 4 — What came up
Step 5 — Both paths, from a machine with no external IP
Validation: both report 401, not
000. A path that does not work never opens a connection at all.
Validation and Evidence
The experiment
| Test | Expected result | Actual result | Status |
|---|---|---|---|
| Endpoint address is ours | purpose PRIVATE_SERVICE_CONNECT | 10.99.0.2, PRIVATE_SERVICE_CONNECT, INTERNAL | Pass |
| Endpoint sits outside every subnet | Not inside 10.40.0.0/24 | Outside, asserted programmatically | Pass |
| Probe has no external IP | empty | empty | Pass |
| No NAT on the network | 0 routers | 0 | Pass |
| Both paths work at baseline | 401 and 401 | 401 and 401 | Pass |
| Route deleted | PGA fails, PSC survives | PGA 000, PSC 401 | Pass |
| Route restored | Both work again | 401 and 401 | Pass |
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-osloginandblock-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
| Item | Rate | This run |
|---|---|---|
| Private Service Connect endpoint | $0.01 / hour | ~1.2 hours |
| Data transfer to Google APIs over the endpoint | no charge | $0 |
| Probe VM | e2-micro, us-central1, no external IP | free tier |
| VPC, subnet, routes, firewall | no 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
- Private access options for services — what each mechanism actually connects to
- Configure Private Google Access — the default-route requirement and the VIP ranges
- About accessing global Google APIs through endpoints — the address rule, on-premises access, and peering
- Access global Google APIs through endpoints — purpose, bundles and the forwarding rule
- week-14-private-service-connect — Terraform, both scripts, the raw measurement and the lab guide
Comments