Why the path comes first#
The same timeout or refusal points to different owners on different paths. A missing Cloud SQL Client role breaks the socket and the connectors, and does nothing to a direct TCP connection to the private IP. A firewall rule in the VPC breaks the private IP path and does nothing to the socket. Reading the wrong path's settings sends the investigation to an owner who cannot fix it. The four stages apply to every path, but what sits at each stage differs.
Cloud SQL offers two connection types: a Cloud SQL connector (the Cloud SQL Auth Proxy or a language connector for Java, Python, Go or Node.js), or a direct connection to the instance's private or public IP address. Cloud Run embeds the Cloud SQL Auth Proxy for public IP connections. Connection options
The paths and what each one needs#
| Path | What the revision carries | What the code uses | Needs from IAM and APIs | Needs from the network |
|---|---|---|---|---|
| Built-in connection, Unix socket | run.googleapis.com/cloudsql-instances lists the instance | A socket path under /cloudsql/INSTANCE_CONNECTION_NAME | Cloud SQL Client on the revision's service account; Cloud SQL Admin API enabled | None in the VPC |
| Language connector, public IP | Nothing specific | A connector library and the connection name, IP type public | Cloud SQL Client; Admin API enabled | Egress on 443 to the Admin API and 3307 to the instance |
| Language connector, private IP or PSC | VPC egress: run.googleapis.com/network-interfaces or run.googleapis.com/vpc-access-connector | A connector with IP type private or PSC | Cloud SQL Client; Admin API enabled | A route to the instance's private address or PSC endpoint |
| Direct TCP, private IP | VPC egress as above | A host that is the instance's private IP, port 5432 | None for the path; the database login still applies | A route, firewall rules that allow it, and the right egress setting |
| Direct TCP, PSC endpoint | VPC egress as above | The endpoint's internal IP or DNS name | None for the path | A route to the endpoint in the consumer network |
| Direct TCP, public IP | Usually nothing | The instance's public IP | None for the path | Authorized networks that include the source address |
The sources for each row: the built-in connection mounts the socket and needs Cloud SQL Client and the Admin API Connect from Cloud Run. The Auth Proxy and the connectors call the Admin API on port 443 for an ephemeral certificate and connect to the instance on port 3307, and need a role with cloudsql.instances.connect About the Auth Proxy. The private IP path uses TCP to the instance on port 5432 without the Auth Proxy Connect with TCP. PSC endpoints are internal IP addresses in the consumer's VPC network, reached by address or DNS record Private Service Connect. A direct public IP connection needs authorized networks Connection options.
Check 1: read what the revision carries#
gcloud run revisions describe REVISION \
--project PROJECT --region REGION \
--format='yaml(metadata.annotations, spec.serviceAccountName, spec.containers[0].env)'
Look for four annotations. run.googleapis.com/cloudsql-instances sets the Cloud SQL connections; run.googleapis.com/vpc-access-connector sets a Serverless VPC Access connector; run.googleapis.com/vpc-access-egress sets all-traffic or private-ranges-only; and run.googleapis.com/network-interfaces holds the network and subnet for Direct VPC egress. Revision template annotations · Direct VPC egress YAML
A revision can carry several of these at once. The annotations say which routes exist; they do not say which one the code takes.
Check 2: read what the code connects to#
The connection setting decides the path. Read it from the revision's env and secrets, and from the code where the pool is built:
| The host or connection setting | Path |
|---|---|
A path that starts with /cloudsql/ | Built-in Unix socket |
A connection name project:region:instance passed to a connector library, such as cloud-sql-python-connector, the Java socket factory or cloudsqlconn in Go | Language connector; read its IP type next |
| An address in a private range, or a DNS name that resolves to one | Direct TCP over the VPC: the instance's private IP or a PSC endpoint |
| A public address | Direct TCP to the public IP |
For a connector, the IP type decides the network path. Google's samples select it from an environment variable: the Python sample uses IPTypes.PRIVATE when PRIVATE_IP is set and IPTypes.PUBLIC otherwise, and the Java sample sets ipTypes to PUBLIC,PRIVATE as a preference list. Connect with Cloud SQL connectors · Language connectors
To tell an instance's private IP from a PSC endpoint, read the instance:
gcloud sql instances describe INSTANCE --project INSTANCE_PROJECT \
--format='yaml(connectionName, ipAddresses, settings.ipConfiguration.ipv4Enabled, settings.ipConfiguration.privateNetwork, settings.ipConfiguration.pscConfig)'
ipAddresses lists the instance's addresses with a type: PRIMARY is the address clients are meant to connect to, and PRIVATE is the private IP used with network peering. privateNetwork names the VPC that reaches the private IP, and pscConfig holds PSC settings. Instance resource An address the code uses that appears in neither list is a PSC endpoint or something else in your network.
A worked fixture: same symptom, two paths#
The fixture is illustrative. The fictional service orders-api in europe-west1 reaches shop-prod:europe-west1:orders-db, which has a public and a private address. orders-api-00018 takes all traffic at 09:12:30 UTC, and requests that read the database time out.
Outcome A: the code changed paths. Both revisions carry the same annotations: cloudsql-instances: shop-prod:europe-west1:orders-db and no VPC egress. orders-api-00017 connects through /cloudsql/shop-prod:europe-west1:orders-db. orders-api-00018 switched to the Python connector, and its environment sets PRIVATE_IP=true.
| Revision | Annotations | Code setting | Path |
|---|---|---|---|
orders-api-00017 | cloudsql-instances | Socket under /cloudsql/ | Built-in socket |
orders-api-00018 | cloudsql-instances | Connector, IP type private | Connector to the private IP, with no VPC egress |
The new code asks for a path the revision cannot route. Remove PRIVATE_IP or add VPC egress; either way, the decision belongs to the release. IAM was never involved: the same service account worked on the socket path a minute earlier.
Outcome B: the path stayed, the network changed. Both revisions carry network-interfaces for network shop-vpc, subnet run-europe-west1, egress private-ranges-only, and both set DB_HOST=10.40.0.3, which matches the instance's PRIVATE address. orders-api-00017's new instance at 09:14 times out as well.
| Revision | Path | New instance connects? |
|---|---|---|
orders-api-00017 | Direct TCP, private IP | No (09:14:05) |
orders-api-00018 | Direct TCP, private IP | No (09:12:44) |
The path did not change and the old revision fails too. A Cloud SQL Client role or the Admin API cannot explain a timeout on this path, because no proxy or connector is in it. Read the VPC: firewall rules, the peering and the subnet. Private IP connections from Cloud Run time out
Where the checks mislead#
A connector configured with a preference list, such as Java's PUBLIC,PRIVATE, can take a different path when the instance's addresses change. Read the instance's ipAddresses for the window as well as the code.
The cloudsql-instances annotation can stay on revisions whose code no longer uses the socket. Its presence proves only that the socket is mounted.
A Java application can use the connector without the built-in connection, so a revision with no annotation can still depend on the Cloud SQL Client role and the Admin API. Console steps
Questions#
Does Cloud Run use the Cloud SQL Auth Proxy?
For the built-in Cloud SQL connection, yes: Cloud Run embeds the Auth Proxy for public IP connections and exposes it as a Unix socket under /cloudsql/. A direct TCP connection to the private IP does not use it.
Does a private IP connection from Cloud Run need the Cloud SQL Client role?
Not for the path itself when the code connects by TCP to the private address. If the code uses a language connector with the private IP type, the connector still authorizes through IAM and the Cloud SQL Admin API.
Can one revision use two paths?
Yes. A revision can carry the socket and VPC egress at the same time, and different parts of the code, such as a migration job and the request pool, can use different settings. Read every place a pool is built.