Learning center

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.

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 · PostgreSQL error codes The server answered, so the path and IAM authorization worked; this is stage 3 of the four stages.

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

ReferenceWhen the value is readWhat a new secret version does
Environment variable, pinned versionBefore each instance startsNothing, until a deploy changes the pin
Environment variable, latestBefore each instance startsNew instances get the new version; running instances keep the old value
Mounted volume, latestEach time the code reads the fileRunning instances see it at their next read of the file
Mounted volume, pinned versionEach time the code reads the fileNothing, 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

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 Each version has a state of ENABLED, DISABLED or DESTROYED, and a createTime. SecretVersion · gcloud secrets versions list

The two revisionsReading
Different pinned versions, or one pinned and one latestThe deploy changed what the revision reads. A fresh instance of the previous revision tests whether its value still works
Different secret namesThe deploy points at another secret. Same reading
Same referenceThe 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

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

gcloud 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

Then find when the secret last got a new version. AddSecretVersion is an Admin Activity audit event. Secret Manager 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 eventsReading
Password changed; no secret version sinceThe database holds a password no secret version contains. Every new instance of every revision fails. Not the deploy
New secret version; no password change sinceThe 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 versionThe 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

Fresh instance of the previous revisionReading
Logs inThe new revision's reference is wrong. Route traffic back and fix the reference
Fails the same wayThe 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:02UPDATE_USER on orders-db, initiated by a database administrator
09:12:52orders-api-00018: FATAL: password authentication failed for user "orders_app"
09:13:10Fresh 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.

Revisionorders-db-password referenceFresh instance logs in?
orders-api-00017latest (version 5)Yes, 09:13:10
orders-api-000183No, 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.

Start free with GitHub

Related reading