---
title: "A Cloud SQL SSL mode change rejects a Cloud Run client that used to connect | Proofline"
description: "When one Cloud Run client is refused by Cloud SQL while others connect, read the instance's sslMode and when it last changed."
url: https://proofline.sh/learn/cloud-sql-ssl-mode-rejects-cloud-run/
---

[Learning center](/learn/)

# A Cloud SQL SSL mode change rejects a Cloud Run client that used to connect

When one Cloud Run client is refused by Cloud SQL while others connect, read the instance's sslMode and when it last changed. A stricter mode rejects direct TCP clients that send no TLS or no client certificate; connections through the Auth Proxy or a connector meet every mode.

Security incidents The Proofline team November 23, 2026 5 min read

## 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](https://cloud.google.com/sql/docs/postgres/configure-ssl-instance#enforcing-ssl) · [`SslMode`](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances#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](https://cloud.google.com/sql/docs/postgres/configure-ssl-instance#enforcing-ssl) · [Connect from Cloud Run](https://cloud.google.com/sql/docs/postgres/connect-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](https://www.postgresql.org/docs/current/libpq-ssl.html)

| 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](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances)

## 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](https://cloud.google.com/sql/docs/postgres/configure-ssl-instance#overview)

The refusal comes from the server after the client reached it, so on the hub's [stage table](/learn/cloud-run-cloud-sql-connection-errors/#stage) 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`](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances)

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](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/operations) · [Cloud SQL audit logging](https://cloud.google.com/sql/docs/postgres/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](https://cloud.google.com/logging/docs/audit/understanding-audit-logs)

## 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](https://cloud.google.com/run/docs/reference/rest/v1/RevisionTemplate)

```
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](https://www.postgresql.org/docs/current/monitoring-stats.html)

```
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](https://cloud.google.com/sql/docs/postgres/configure-ssl-instance#overview)

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](/learn/cloud-sql-server-ca-rotation-cloud-run/)

Client certificates expire, 10 years after creation by default. Under `TRUSTED_CLIENT_CERTIFICATE_REQUIRED`, an expired one fails like a missing one. [Client certificates](https://cloud.google.com/sql/docs/postgres/configure-ssl-instance#client-certs)

## 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.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Certificate verify failed from Cloud Run after a Cloud SQL server CA change](/learn/cloud-sql-server-ca-rotation-cloud-run/)
    
    Security incidents The Proofline team November 23, 2026 6 min read
    
-   ### [Cloud Run cannot reach Cloud SQL: revision, identity or connection?](/learn/cloud-run-cloud-sql-connection-errors/)
    
    Broken dependencies The Proofline team November 23, 2026 10 min read
