What each mode accepts#
The instance's settings.ipConfiguration.sslMode decides which connections the server accepts. For PostgreSQL and MySQL there are three values: Configure SSL/TLS · SslMode
sslMode | Accepts |
|---|---|
ALLOW_UNENCRYPTED_AND_ENCRYPTED | Unencrypted and TLS connections; the client certificate is not verified. The default |
ENCRYPTED_ONLY | TLS connections only; the client certificate is not verified |
TRUSTED_CLIENT_CERTIFICATE_REQUIRED | TLS connections with a valid client certificate only. Clients using IAM database authentication must connect through the Auth Proxy or a connector |
Connections through the Cloud SQL Auth Proxy or a Cloud SQL connector are encrypted automatically, and the proxy and connectors verify client and server identity whatever the SSL mode. Cloud Run's built-in Cloud SQL connection, the Unix socket under /cloudsql/, runs through the Auth Proxy. So the mode can only reject clients that connect directly over TCP to the instance's IP: a private IP through Direct VPC egress or a Serverless VPC Access connector, or a public IP. Configure SSL/TLS · Connect from Cloud Run
What a direct client sends depends on its driver's SSL setting. In libpq, sslmode=disable never uses TLS; the default, prefer, uses TLS if the server supports it; require, verify-ca and verify-full insist on it. None of them sends a client certificate unless one is configured or present in libpq's default location. libpq SSL support
| Client path | ALLOW_UNENCRYPTED_AND_ENCRYPTED | ENCRYPTED_ONLY | TRUSTED_CLIENT_CERTIFICATE_REQUIRED |
|---|---|---|---|
| Built-in connection or a connector | Accepted | Accepted | Accepted |
Direct TCP, sslmode=disable | Accepted | Rejected | Rejected |
Direct TCP, prefer or stricter, no client certificate | Accepted | Accepted | Rejected |
| Direct TCP with a client certificate issued by the instance | Accepted | Accepted | Accepted |
A related setting does the same to every direct client at once. connectorEnforcement set to REQUIRED allows only connections that use Cloud SQL connectors, and it disables the instance's authorized networks. Instance settings
Why it looks like a deploy#
A change to the SSL mode applies only to new connections. Existing unencrypted connections stay connected and unencrypted until they close or the instance restarts, and enforcing SSL does not itself restart the instance. A service with a warm pool keeps working for hours after the change, and fails when it opens new connections: at the next deploy, scale-out or pool recycle. Configure SSL/TLS
The refusal comes from the server after the client reached it, so on the hub's stage table it sits at stage 3: the path worked, and the server declined the session before any password check. The exact message depends on the driver and the mode.
Check 1: read the mode and when it changed#
gcloud sql instances describe INSTANCE --project PROJECT \
--format='yaml(settings.ipConfiguration.sslMode, settings.ipConfiguration.requireSsl, settings.connectorEnforcement)'
requireSsl is the legacy flag; when both are set, sslMode takes priority for PostgreSQL and MySQL. sslMode
An SSL mode change is a settings update, so it appears as an UPDATE operation with the caller in user, and as a cloudsql.instances.update entry in the Admin Activity audit log. Operation types · Cloud SQL audit logging
gcloud sql operations list --instance INSTANCE --project PROJECT --limit=20 \
--format='table(operationType, status, startTime, endTime, user)'
gcloud logging read '
logName="projects/PROJECT/logs/cloudaudit.googleapis.com%2Factivity"
AND protoPayload.methodName="cloudsql.instances.update"
AND timestamp>="START_TIME"' \
--project PROJECT --order=asc --format=json
When the audit entry includes the request, it shows the ipConfiguration that was sent. Audit log entry structure
Check 2: which path does the failing client use?#
Read the failing revision's database host and SSL settings, and whether it has the run.googleapis.com/cloudsql-instances annotation, which marks the built-in connection. A host that is an IP address, or a DNS name for one, means direct TCP. Revision template annotations
gcloud run revisions describe REVISION --project PROJECT --region REGION \
--format='yaml(metadata.annotations, spec.containers[0].env)'
Then place it in the path table above. A client that the current mode rejects explains the failure. A client the mode accepts does not, and the cause is elsewhere.
A worked fixture: one setting, two services#
The fixture is illustrative. In project shop-prod, orders-api uses the built-in connection to orders-db. A second service, orders-worker, connects to the instance's private IP through Direct VPC egress with sslmode=require and no client certificate. Both run as orders-runtime@shop-prod.iam.gserviceaccount.com.
Morning A. The operations list shows an UPDATE from 08:40:12 to 08:40:31 UTC by sec-baseline@shop-prod.iam.gserviceaccount.com. The instance now reads sslMode: TRUSTED_CLIENT_CERTIFICATE_REQUIRED. Nothing fails at 08:40. At 10:05 a deploy of orders-worker-00031 starts new instances, and every connection they open is refused; orders-worker-00030 instances that connected at 07:00 keep working. orders-api deploys orders-api-00018 at 10:20 without a single database error.
orders-worker is direct TCP with no client certificate: rejected under the new mode. orders-api uses the built-in connection: accepted. The deploy only opened new connections. Either give orders-worker a client certificate, move it to a Cloud SQL connector, or agree a different mode with whoever owns the security baseline. Restarting old instances will not help; it only moves them to the same refusal.
Morning B. No UPDATE in the last week, sslMode is ENCRYPTED_ONLY, and has been since the instance was created. orders-worker-00031 fails, and its environment shows PGSSLMODE=disable, added in the deploy to work around a local test setup. ENCRYPTED_ONLY rejects unencrypted clients, so the deploy introduced the failure; remove the variable.
Where the checks mislead#
An instance that has run with ALLOW_UNENCRYPTED_AND_ENCRYPTED for a long time may have unencrypted clients nobody knows about. Before tightening the mode, list who connects and how: pg_stat_ssl has one row per connection with an ssl column, and joins to pg_stat_activity on pid for the user, application name and client address. pg_stat_ssl
SELECT a.usename, a.application_name, a.client_addr, s.ssl
FROM pg_stat_ssl s JOIN pg_stat_activity a USING (pid)
WHERE a.backend_type = 'client backend';
After tightening it, expect failures to appear only as each client opens new connections, which can take days for a quiet job. A restart closes unencrypted connections at once, which surfaces them all in one window. Configure SSL/TLS
A rejected TLS client is not always an SSL mode problem. A client that verifies the server can fail on the server's certificate instead, after a rotation or a CA mode change. Certificate verify failed after a CA change
Client certificates expire, 10 years after creation by default. Under TRUSTED_CLIENT_CERTIFICATE_REQUIRED, an expired one fails like a missing one. Client certificates
Questions#
Does Cloud SQL's SSL mode affect Cloud Run's built-in Cloud SQL connection?
No. The built-in connection goes through the Cloud SQL Auth Proxy, which encrypts the connection and verifies identities whatever the SSL mode.
Why did the Cloud SQL SSL change break my service hours later?
The SSL mode applies only to new connections. Connections opened before the change stay up until they close, so the failure appears when the service opens new ones, often at the next deploy or scale-out.
How do I find who changed the Cloud SQL SSL mode?
Look for an UPDATE operation in gcloud sql operations list and the matching cloudsql.instances.update entry in the Admin Activity audit log; both name the caller.