Rotating a Cloud Run credential while old revisions still exist
In brief
Keep both credentials valid while Cloud Run consumers move to a verified replacement.
- Pin the new secret version and test a revision before shifting traffic.
- Account for old revisions, jobs, and in-flight requests before revoking the old credential at its issuer.
We’d rotate an external API credential through the same controlled release path as application configuration.
Create the replacement and verify it. Deploy consumers that reference its exact Secret Manager version. Retire the old credential only after the remaining consumers have been accounted for.
This assumes the issuer can keep both credentials valid during the transition. If creating the replacement immediately invalidates the old credential, a gradual Cloud Run rollout can’t keep access for both revisions. Use the provider’s supported handover mechanism instead, or schedule an interruption with accepted work paused and recoverable.
The example is a document-processing application that calls a supplier API from a request service, an asynchronous worker, and a scheduled reconciliation job. The procedure also applies to other shared credentials. Database passwords, certificates, and signing keys have different issuer and session semantics, though, and need their own checks.
Know when each consumer resolves its value
Cloud Run resolves secret environment variables when an instance starts, and Google recommends pinning a numeric version for that mode. If retrieval fails, the instance doesn’t start. With a mounted secret, access failures surface when the application reads the file. Mount configuration can select a numeric version or latest, and a mount doesn’t necessarily follow new versions.
A library might read a mounted file once, construct a client, and keep that credential until the process exits. Another might reread it before every request. Check which one your code path does. Changing a mounted value won’t replace a credential already copied into a client object.
For this service, we’d bind a numeric version to the revision and read it at startup. Each deployment record then identifies both the image and the credential version. Binding versions to releases also makes restarts predictable and reuses the rollout controls you already have.
Don’t read latest as “latest working version.”
In the access API it means the most recently created version. Disabling a bad newest version doesn’t turn the alias into a health-aware fallback selector.
Inventory consumers before creating the replacement
List every workload that can present the old credential: service revisions receiving normal traffic, tagged revisions used by tests, worker configurations, scheduled jobs, and operators’ approved recovery tooling. Record whether each consumer reads at startup, rereads a file, or caches the value behind another client.
Keep a rotation record that identifies the versions and affected consumers:
{
"rotation_id": "supplier-api-2026-10-02",
"secret": "supplier-api-token",
"old_version": "17",
"new_version": "18",
"issuer_overlap_confirmed": true,
"consumers": ["document-api", "document-worker", "reconcile-job"],
"phase": "replacement-verified"
}Store version names and evidence references in the record, never credential bytes. Keep the issuer’s identifier for each credential too, if it provides one. With it, you can tell “we disabled version 17 in Secret Manager” apart from “we revoked the corresponding key at the supplier.”
Check the rollback path during the inventory. An old image referencing version 17 may become unusable after cleanup. A working rollback release might instead need the previous image with version 18 configured. Prepare that combination if the old code is compatible with the replacement. Otherwise, state when rollback stops being available and what recovery remains.
Also identify work already accepted. A message should ordinarily carry the operation input and identity, not a copy of the API credential. Confirm which worker configuration will handle a delayed delivery and whether any queued execution can still use the old value.
Verify the new credential before shifting callers
Create the replacement through the issuer’s authorized procedure while leaving the old credential valid. Give it the required permissions and resource scope. Store it as a new Secret Manager version and record the resulting numeric version instead of guessing the next number. Verify secret access with the runtime service identity in an isolated test revision. The deploying operator and the application’s identity are granted access separately.
Grant access to that secret only, and keep the broader authority to create or revoke supplier keys out of the ordinary request handler.
Choose the integration with leakage in mind. Secrets in environment variables can leak through process environment dumps, and mounted files through file-reading vulnerabilities. Pinning helps release control. A pinned value can still leak through application diagnostics like any other.
Then make a harmless supplier request that exercises the permission the workload needs. A generic health endpoint can succeed without touching the replacement’s tenant scope or API permissions. If no harmless operation covers that permission, use an approved synthetic resource with a known cleanup path. Record which operation was tested and its result, without recording authorization headers.
Keep the credential change separate from unrelated application changes where you can. If the canary starts failing, there are fewer plausible causes to investigate. Verify a fresh instance too, so that success can’t depend on a previously initialized client or an old in-memory credential.
Roll out consumers and account for unfinished calls
Deploy a revision referencing version 18, initially without normal service traffic. Send controlled requests to its tagged URL if that fits the service’s access policy. Tests on that URL can still perform real side effects, so use the synthetic operation selected earlier.
Move traffic according to observed request volume and failure tolerance. A low-volume internal service may get more evidence from a small planned test set than from hours at an arbitrary traffic percentage. Watch supplier authentication failures by revision alongside ordinary application failures. When initializing the client, log the configured version identifier, never the secret or a reversible encoding of it.
Update the worker and scheduled job as separate consumers. A clean request-service rollout tells you nothing about a job that next starts tomorrow.
Exercise the job’s credential-dependent path in a suitable test environment. Otherwise, keep cleanup pending until the scheduled consumer has run successfully with the new version.
Traffic changes don’t complete instantly, and requests already in progress continue during migration. Keep both credentials valid while old calls can still run. Remove unneeded old revision tags and callers pinned to old revisions as part of the inventory. Then verify that the replacement handles every entry path it’s meant to serve.
Before moving on, record which consumers have changed, which executions remain, and why the rollback route is still usable.
Disable retrieval, then revoke at the issuer
Disabling a Secret Manager version blocks later access to that version and can be reversed by enabling it again. It doesn’t erase a credential already loaded into a running process, and it doesn’t tell the supplier to reject it.
Account for propagation too. Secret Manager operations other than adding a version and accessing one by number are eventually consistent.
The disable call can return before every reader is blocked. Check what consumers can still read, and apply the same caution when changing IAM access.
Once the inventory shows that version 17 is no longer needed, disable its retrieval. Watch the consumers over a period chosen from their schedules and recovery paths.
Include a cold start or fresh job execution where feasible. A warm process with cached bytes can keep working while its next startup would fail.
Treat any access failure as evidence of a missed consumer. Restore retrieval if needed, identify that consumer, and finish its migration instead of creating another credential to make the symptom go away. Record which path still depended on the old version.
After that reversible observation phase, revoke the old credential at the issuer. Verify the documented revocation outcome, including whether the issuer treats existing sessions or derived tokens separately.
When the old credential stops working depends on the provider. No universal waiting period makes every external authentication scheme safe.
Destroy the stored version only once the agreed retention and recovery requirements allow it. Disable it before destroying it. Keep the rotation record afterward. An operator should still be able to explain which release changed the credential and how retirement was verified.
Rehearse the failure branches
In a nonproduction environment, give the replacement too little permission. Confirm the test stops before broad rollout. Try starting a consumer with access to the old version disabled. Exercise rollback while the old issuer credential remains valid, then separately rehearse the prepared previous-image/new-version release.
For an application that reloads credentials while running, add a malformed replacement and an unavailable secret read. Should the process keep its last valid client for a bounded period or fail the dependent operation? Settle that as defined incident behavior before you need it, especially if rotation might be responding to a suspected compromise.
In an emergency, if continuing to accept the old credential is unacceptable, revoke it and accept a controlled interruption while consumers recover.
The gradual procedure depends on an acceptable overlap window. Record that window as a condition of the rotation. The next operator can then see when the procedure must change.
More in this domain: Infrastructure
Browse allWhen a BigQuery service perimeter earns its operational cost
Adopt a service perimeter for a named prohibited data-transfer path, then prove that required queries still work and the prohibited transfer fails.
Give Cloud Run health probes a recovery policy
Match each Cloud Run health probe to a recovery action.
Detect stalled Cloud Run work behind a healthy endpoint
Detect stalled Cloud Run work from overdue operations and their last meaningful progress.
Cloud Tasks vs. Pub/Sub for Cloud Run: routing, retries, and rate limits
Use Cloud Tasks to schedule or throttle a specific operation. Use Pub/Sub to deliver one event to independent consumers.
Cloud Run scale to zero: cold starts and minimum instances
Let Cloud Run scale to zero when the first useful request after idle time meets the caller's deadline.
Related patterns
Direct VPC egress vs. Serverless VPC Access for Cloud Run
Start with Direct VPC egress for new Cloud Run connections to a VPC.
Internal-only Cloud Run: ingress, identity, and the caller's network path
Internal Cloud Run access requires both an allowed network path and an authorized caller.
How we decide between Cloud SQL connectors, Auth Proxy, and private IP
Choose the Cloud SQL network route and the connection helper separately. Either a language connector or the Auth Proxy can use private IP.
Safe scaling defaults for Cloud Run + Postgres
Set Cloud Run instance limits, request concurrency, and per-process pools together so the fleet fits within PostgreSQL's connection budget.