← All posts
gcp cloud-run networking learning

A Private Phone Line into Cloud Run

I finally sat down with Internal Load Balancers, serverless NEGs, and Private Service Connect — and mapped how they turn a public Cloud Run URL into a private path between GCP projects.

· 8 min read

I was reading a Terraform change that claimed to “publish a Cloud Run API behind a regional internal load balancer, a serverless NEG, and a Private Service Connect Service Attachment.”

I recognised every acronym. I did not actually understand how they fit together.

This post is the explanation I wish I had first: the problem, a restaurant analogy, then the real Google names, then one request walking through the private path. No product names. Just the shape of the thing.

The problem with a “private” Cloud Run URL

Cloud Run gives every service a URL. Callers need IAM (roles/run.invoker) and a Google identity token. That is authentication. It is not a private network.

The packets still leave on a public hostname. Anyone who can reach the internet can attempt the call. Google rejects them if they lack the token. The road is still public. The lock is on the door.

That is often fine. It is not fine when you want another GCP project to call the API the way it would call something on its own VPC: a private IP, no public hop, nothing published to the internet.

The blunt tool is VPC peering. Peering glues two whole networks together. Address ranges cannot overlap. At org scale, that gets messy fast. You do not want to expose a VPC. You want to expose one service.

That is what this stack is for.

A restaurant, not a diagram

Treat the Cloud Run service as a kitchen in a locked building (your GCP project / VPC).

The caller never learns the kitchen’s public address. They dial a number that looks local.

The three named pieces

1. Serverless NEG — naming the kitchen

A load balancer needs a list of backends. The classic list is VMs with IP addresses.

Cloud Run has no VM IP you own. Google scales it. A serverless NEG is the adapter: “the backend is this Cloud Run service, in this region.”

The load balancer never talks to instance IPs. It asks Google to send the request to that Cloud Run service. In Terraform this is usually a neg_configs block whose cloudrun.target_service is the Cloud Run name.

2. Internal load balancer — the private receptionist

This is a regional internal Application Load Balancer. HTTP(S). Private.

It lives in your VPC, on a normal subnet, and gets a private IP. No public IP. Traffic from the internet cannot hit it.

Inside your project the path is:

  1. Request arrives at the ILB private IP.
  2. Google’s proxies in the proxy-only subnet terminate HTTPS.
  3. The ILB sends the request to the backend group (the serverless NEG).
  4. The NEG points at Cloud Run.
  5. Cloud Run runs the app.

That already hides Cloud Run from the public internet as a load-balanced private IP. It does not yet let another GCP project use that IP. Private IPs are not visible across projects. That gap is what PSC fills.

3. Private Service Connect — the wall jack

PSC is a private plug between two VPCs, for one service, not for the whole network.

Two sides:

Producer (you, the API owner). You publish a Service Attachment on the ILB. That is the wall jack. It needs a PSC NAT subnet. After apply, you hand the attachment ID / URI and the ILB address to whoever owns the calling network.

Consumer (the other project). They create a PSC endpoint in their VPC. That endpoint gets a private IP in their subnet. The IP is a pointer at your Service Attachment.

An app in the consumer project calls https://<that-local-IP>/…. Google carries it privately to your ILB. No peering. No public internet. The consumer never sees your VPC.

automatic_connection = true on the attachment means an allowed consumer can connect without a manual accept on every attempt. Someone still has to create the consumer endpoint. Producer Terraform does not do that.

Why two extra subnets

The normal subnet is for normal private IPs. The ILB forwarding rule lives there.

ILB + PSC need two special-purpose subnets. You do not put applications in them. Google uses them. If they are missing, terraform apply for the ILB fails.

Proxy-only subnet — purpose REGIONAL_MANAGED_PROXY. An internal HTTP(S) load balancer is a fleet of Google-managed proxies. Google requires a dedicated subnet in that region to park them. Regional, not global, because this ILB is regional. One per region per VPC. The ILB YAML often does not even name this subnet. Google just requires that one exists.

PSC NAT subnet — purpose PRIVATE_SERVICE_CONNECT. When a consumer connects, Google must NAT that connection onto IPs inside the producer VPC so the ILB can see it. That NAT pool is this subnet. The Service Attachment’s nat_subnets points at it by name.

These usually live in the VPC / project-factory repo, not in the service’s Terraform. The service stack consumes them. It does not create them. Easy to miss when you read only the API repo.

One request, end to end

Caller is in another GCP project. The consumer PSC endpoint already exists.

Consumer VPC                      Google private fabric           Your VPC
─────────────────                 ─────────────────────          ─────────────────────────
app → PSC endpoint IP  ─────────►  PSC tunnel  ─────────►  Service Attachment
                                                           (NAT in the PSC subnet)
                                                                  │
                                                                  ▼
                                                           Internal LB
                                                           (proxies in proxy-only subnet)
                                                                  │
                                                                  ▼
                                                           serverless NEG
                                                                  │
                                                                  ▼
                                                           Cloud Run
  1. The app in the consumer VPC calls the local PSC IP. It looks like any private IP.
  2. Google matches that endpoint to your Service Attachment.
  3. The connection lands in the PSC NAT subnet. Google gives it an address there so the ILB can see it.
  4. The ILB receives it. Proxies run in the proxy-only subnet.
  5. The ILB looks up the backend serverless NEG.
  6. The NEG targets the Cloud Run service.
  7. Google’s Cloud Run service agent needs roles/run.invoker on the service, or the load balancer cannot invoke it. That is a separate IAM member from “humans / other apps may call this.”
  8. Cloud Run still checks the caller’s identity token. The private path does not skip IAM.
  9. The response walks back the same way.

Private network is not private auth

This is the mix-up that made the Terraform change click for me.

LayerWhat it doesWhat it does not do
ILB + NEG + PSCHide the path. No public internet. Other projects get a local IP.Prove who you are.
roles/run.invoker + identity tokenProve the caller is allowed.Keep packets off the public internet.

Both are required. PSC is the road. IAM is the lock on the kitchen door.

There is a third knob: Cloud Run ingress.

If current callers (another product, a Vertex agent, a laptop with gcloud) are not yet on the PSC path, flipping ingress to ILB-only cuts them off. A common rollout is:

  1. Build the ILB + NEG + Service Attachment.
  2. Leave ingress on ALL so existing callers keep working.
  3. Wait until the consumer PSC endpoint exists and callers have switched.
  4. Then flip ingress to INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER.

Until step 3, you have a private front door that nobody outside the VPC can use, and a public door that still works.

Who owns which half

Easy to treat “private Cloud Run” as one Terraform apply. It is not.

Service repo. ILB, serverless NEG, Service Attachment, the extra run.invoker for the Cloud Run service agent, Compute API enabled, outputs for the attachment ID and ILB IP.

VPC / project factory. The proxy-only subnet and the PSC NAT subnet. Sometimes the VPC itself, and IAM for whoever applies the ILB.

The network team / consumer project. The PSC endpoint. That is the other end of the plug. Without it, the ILB exists and nothing outside your VPC can dial it.

What I want to remember

A serverless NEG does not make Cloud Run private. It only tells a load balancer where the kitchen is.

An internal load balancer makes a private IP in your VPC. Other projects still cannot see that IP.

PSC is the piece that gives another project a local number which secretly rings your receptionist.

Two oddly named subnets are not optional decoration. One is the receptionist’s office. One is the switchboard. Apply fails without them.

And a private path does not replace IAM. It replaces the public road.

← Back to all posts