---
title: "Cloud SQL password failures after a deploy: the secret version or the password? | Proofline"
description: "When new Cloud Run instances get password authentication failed from Cloud SQL after a deploy or a scale-out, find out which value each side holds."
url: https://proofline.sh/learn/cloud-run-database-password-secret-version/
---

[Learning center](/learn/)

# Cloud SQL password failures after a deploy: the secret version or the password?

When new Cloud Run instances get password authentication failed from Cloud SQL after a deploy or a scale-out, find out which value each side holds. Compare the secret version each revision reads with the secret's version history, and the time of the database user's last password change with the time the failing instances started. A revision that reads a different version than the last good one points at the deploy; a password change that no secret version matches points at the credential.

Missing secrets The Proofline team November 23, 2026 6 min read

## How the symptom shows up

PostgreSQL rejects the login with a message such as `FATAL: password authentication failed for user "andym"`, SQLSTATE `28P01` (`invalid_password`). [Client authentication problems](https://www.postgresql.org/docs/current/client-authentication-problems.html) · [PostgreSQL error codes](https://www.postgresql.org/docs/current/errcodes-appendix.html) The server answered, so the path and IAM authorization worked; this is stage 3 of [the four stages](/learn/cloud-run-cloud-sql-connection-errors/#stage).

The failure often shows only on new instances. Connections opened before the change keep working until they close, so a deploy or a scale-out, which starts new instances, is when it surfaces. That makes the deploy look responsible whether it was or not.

## When a revision reads the secret

A revision references a Secret Manager secret either as an environment variable or as a mounted volume, by a pinned version number or by `latest`. [Use secrets](https://cloud.google.com/run/docs/configuring/services/secrets)

| Reference | When the value is read | What a new secret version does |
| --- | --- | --- |
| Environment variable, pinned version | Before each instance starts | Nothing, until a deploy changes the pin |
| Environment variable, `latest` | Before each instance starts | New instances get the new version; running instances keep the old value |
| Mounted volume, `latest` | Each time the code reads the file | Running instances see it at their next read of the file |
| Mounted volume, pinned version | Each time the code reads the file | Nothing, until a deploy changes the pin |

Environment variables are resolved at instance startup, and Google recommends pinning a version for them. A volume read always fetches the secret value from Secret Manager to use the latest version. If retrieving an environment variable's secret fails, the instance does not start. [Use secrets](https://cloud.google.com/run/docs/configuring/services/secrets#secret-checks)

## Check 1: which version does each revision read?

```
for r in PREVIOUS_REVISION NEW_REVISION; do
  gcloud run revisions describe "$r" --project PROJECT --region REGION \
    --format='yaml(metadata.name, spec.containers[0].env, spec.volumes)'
done

gcloud secrets versions list SECRET --project SECRET_PROJECT \
  --format='table(name, state, createTime)'
```

In the revision YAML, an environment variable secret appears under `valueFrom.secretKeyRef`, with the secret in `name` and the version in `key`. [Secrets in YAML](https://cloud.google.com/run/docs/configuring/services/secrets#yaml) Each version has a `state` of `ENABLED`, `DISABLED` or `DESTROYED`, and a `createTime`. [SecretVersion](https://cloud.google.com/secret-manager/docs/reference/rest/v1/projects.secrets.versions) · [`gcloud secrets versions list`](https://cloud.google.com/sdk/gcloud/reference/secrets/versions/list)

| The two revisions | Reading |
| --- | --- |
| Different pinned versions, or one pinned and one `latest` | The deploy changed what the revision reads. A fresh instance of the previous revision tests whether its value still works |
| Different secret names | The deploy points at another secret. Same reading |
| Same reference | The deploy did not change the credential the revision reads. Go to check 2 |

## Check 2: when did the database password change?

A password change on a Cloud SQL user is an operation on the instance. `UPDATE_USER` updates an existing user, and each operation records its start and end, and the email of who initiated it. [Operation resource](https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/operations)

```
gcloud sql operations list --instance INSTANCE \
  --project INSTANCE_PROJECT --limit 50 \
  --filter='operationType=UPDATE_USER'
```

[`gcloud sql operations list`](https://cloud.google.com/sdk/gcloud/reference/sql/operations/list) The operation names the instance; which database user changed is in the audit log entry for `cloudsql.users.update`, which is a Data Access audit log and is written only when Data Access logs are enabled for Cloud SQL. [Cloud SQL audit logging](https://cloud.google.com/sql/docs/postgres/audit-logging)

Then find when the secret last got a new version. `AddSecretVersion` is an Admin Activity audit event. [Secret Manager audit logging](https://cloud.google.com/secret-manager/docs/audit-logging)

```
gcloud logging read \
  'protoPayload.methodName="google.cloud.secretmanager.v1.SecretManagerService.AddSecretVersion"
   AND protoPayload.resourceName:"secrets/SECRET"
   AND timestamp>="START_TIME"' \
  --project SECRET_PROJECT --order=asc \
  --format='value(timestamp, protoPayload.authenticationInfo.principalEmail, protoPayload.resourceName)'
```

Put the three times in order: the password change, the newest secret version, and the start of the first failing instance.

| Order of events | Reading |
| --- | --- |
| Password changed; no secret version since | The database holds a password no secret version contains. Every new instance of every revision fails. Not the deploy |
| New secret version; no password change since | The secret holds a value the database does not accept. Revisions that read `latest` fail on new instances; pinned revisions do not |
| Password changed, then a new secret version | The rotation is complete, provided the version holds the new password. Revisions pinned to an older version fail |

## Check 3: does a fresh instance of the previous revision log in?

A fresh instance reads the secret now, under the previous revision's reference, and logs in now. [Test the previous revision with a tag](/learn/test-previous-cloud-run-revision-with-tag/)

| Fresh instance of the previous revision | Reading |
| --- | --- |
| Logs in | The new revision's reference is wrong. Route traffic back and fix the reference |
| Fails the same way | The credential pair is broken for everyone. Make the secret and the database agree; a rollback will not help |

## A worked fixture: same message, two causes

The fixture is illustrative. The fictional service `orders-api` logs in to `orders-db` as `orders_app` and reads its password from the secret `orders-db-password` as an environment variable. `orders-api-00018` takes all traffic at 09:12:30 UTC.

**Outcome A: the password changed.** Both revisions reference `orders-db-password` at `latest`. The newest version is 5, created on 2026-11-02, and the audit log has no `AddSecretVersion` since.

| Time (UTC) | Event |
| --- | --- |
| 08:58:02 | `UPDATE_USER` on `orders-db`, initiated by a database administrator |
| 09:12:52 | `orders-api-00018`: `FATAL: password authentication failed for user "orders_app"` |
| 09:13:10 | Fresh `orders-api-00017` instance via tag `prev`: same error |

The database user's password changed at 08:58 and the secret did not. Every new instance reads version 5 and fails. The deploy only started new instances. Adding the new password as a secret version is a change to the secret; new instances then pick it up through `latest`, and existing instances keep their old value until they are replaced.

Outcome B: the deploy pinned an old version.

| Revision | `orders-db-password` reference | Fresh instance logs in? |
| --- | --- | --- |
| `orders-api-00017` | `latest` (version 5) | Yes, 09:13:10 |
| `orders-api-00018` | `3` | No, from 09:12:52 |

`gcloud secrets versions list` shows version 3 `ENABLED`, created 2026-08-02, and version 5 created 2026-11-02, when the password was last rotated. No `UPDATE_USER` appears for the past week. `orders-api-00018` was deployed from a YAML file copied before November that pins version 3. The deploy caused it. Route traffic back to `orders-api-00017` and fix the pin.

## Where the checks mislead

`latest` does not tell you which version an instance read. An instance that started before a new version was added still holds the older value. Compare instance start times from the `varlog/system` entries with the versions' `createTime`.

The `UPDATE_USER` operation records that a user changed on the instance. When an instance has several users, it does not say which one unless Data Access logs were on.

A version that exists does not mean it holds the right value. Two versions created minutes apart during a rotation can hold the old and the new password in either order; test the version a fresh instance reads, not the version list.

## Questions

### Does Cloud Run pick up a new secret version without a deploy?

For an environment variable referencing `latest`, new instances do, at startup; running instances keep the value they started with. A volume mounted at `latest` reads the newest version each time the code reads the file. A pinned version changes only with a deploy.

### How do I know whether the database password changed?

List the instance's operations with `gcloud sql operations list --instance INSTANCE` and look for `UPDATE_USER`. Each operation records when it ran and who initiated it.

### Should I roll back when Cloud SQL password authentication fails after a deploy?

Only if a fresh instance of the previous revision logs in. If it fails the same way, the secret and the database disagree for every revision, and the fix is to make them agree.

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

-   ### [A secret rotated during the rollout breaks new instances of both revisions](/learn/secret-rotation-during-rollout/)
    
    Missing secrets The Proofline team November 20, 2026 8 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 9 min read
