Rotate a stored secret #
On this page
Replace the value under its existing name, then check where that value is used. If your app reads it as a manifest setting, a new running copy needs to receive it. If it is an upstream API key, the gateway reads the stored key on its next call.
1. Replace the stored value #
Find the application, environment, and secret name with
tzcloud_list_secrets. Save the row'srotated_atand, if present,fingerprint. Checksettingsfor a manifest binding andconsumersfor a named upstream. If the key is at account scope, check that row separately and check whether the application has its own value under the same name. The gateway uses the application's value for that environment first.Get the replacement from the service that issued the key, or supply the new value your app is meant to use. Keep it in a local file or enter it in your own terminal. See Keep a secret value out of chat.
Call
tzcloud_store_secretwith the same name and scope and withreplace: true. For an application secret, name the application and its environment. Leave outvalueto get asecret rotatecommand. For file input, includevalue_fileas Store a value from a file describes. Run the returned command exactly as given. Arotated:line and exit status 0 confirm the write.If you lose the response, read the exact row before trying again. A changed
rotated_atdoes not prove your value landed: it also moves when the platform could not confirm the write, or when someone else rotates the name. Compare the row's fullfingerprintwith the one you saved only when both are present and share their first four characters. If they differ, the stored value changed. If you cannot confirm your write, ask for a fresh command withreplace: true.
If the app uses the secret both as a setting and as an upstream key, do both checks below. The steps here cover values you supply to the application. For a platform-issued development credential, see Rotate the local run’s credential.
2. Check a setting in the running app #
- On the stored secret's row, check
applied_settingsfor the setting your code reads. Follow the response'snextonly if it returns a restart for that environment. If there is nonext, read the environment and its applied settings before deciding whether a restart is needed. An account-scoped secret returns no restart. If you already have a successful write and need to start the restart separately, calltzcloud_restart_applicationfor the same environment. If the setting is newly bound and the running copy has never used the binding, deploy or promote the version that uses it. See Restart an environment. - Wait for the restart, deploy, or promote to finish. Follow its
nexttotzcloud_read_statusif it is still running. Readtzcloud_list_secretsagain for the same application and environment. - Check that the setting is in
applied_settingsand thatfingerprintandapplied_fingerprintmatch. These two values mark the stored secret and the secret the serving version received. Compare the full strings. If either isnullor the part before the dot differs, the two cannot be compared. If the prefixes match but the fingerprints differ, the running copy received a different value.
An empty rotated_since_read or restart_needed: false is insufficient on its own. Check settings_mismatch in status for details when the fingerprints differ or cannot be compared. For a functional check, use an existing action that requires the new value to succeed. A generic health response only tells you the app answered. Keep the secret out of the response and logs.
3. Check an upstream key #
- Read the secret's
rotated_atand storedfingerprintwithtzcloud_list_secretsand compare them with the row you read before rotation. On the matching upstream intzcloud_list_outbound_apis, check thatcredential_namenames the rotated secret. - Make one request from that environment through the upstream to a provider route that requires the key. The gateway reads the value for each forwarded request, so this check needs no restart.
- Read the upstream's
last_call.at,outcome, and providerstatus. Match the time to your request and check that the provider accepted it. The latest call can come from either environment, so test when you can distinguish your request from other traffic. If the stored fingerprints have the same key identifier and differ, the stored value changed.last_callshows the time, outcome, and provider status of the latest forwarded call, with no fingerprint or part of the key.
For this path, the app's running copy does not receive the key as a setting. An upstream-only secret can have applied_fingerprint: null after a successful rotation. See Rotate the key for the upstream details.
A key that was committed to a repository #
- Revoke the exposed key at the service that issued it. Removing it from Git does not revoke it. After revocation, calls using the old key fail until you switch them to the replacement. Only the key owner can decide to keep the old key working during the change, and anyone with a copy can use it until revocation. Revoke it at once if it appeared in a public repository or in client files your app served.
- List the places that use the key and the permissions each needs. Check each app and environment, account-level uses, local runs, and automation. For gateway calls, check
credential_nameintzcloud_list_outbound_apisas well as the secret's row. Give the replacement only the permissions its uses require. - Keep the replacement out of chat and source code. Use a private file, type it in your own terminal, or use the signed-in Secrets page. For an existing stored name, replace the value in the same scope.
- The gateway reads the replacement on its next forwarded call. For a secret the running app already reads as a setting, restart that environment. For a new binding, deploy or promote a version that uses it. See Check a setting in the running app.
- For each affected environment, follow the running app check for a setting and the upstream check for gateway calls. Make a safe request that needs the replacement to succeed. Keep both key values out of the output and logs.
- After revocation, remove the exposed value from source and check Git history, copies, and build logs. If you deployed files that contained the key, deploy a clean version and check any version you might roll back to.
Refusals #
| Refusal | Cause | Remedy |
|---|---|---|
secret_grant_expired |
The command ran after the grant expired. This run wrote nothing. | Ask for a fresh tzcloud_store_secret command with replace: true and run it before expires_at. |
secret_grant_spent |
The command used a grant that had already been used. This run wrote nothing. | Do not run the same command again. Read the exact secret row; a later rotated_at alone does not show whose write landed. If you cannot confirm your own write, ask for a fresh command with replace: true and run it. |
deploy_in_flight |
A version is already in progress in the environment you tried to restart. | Use tzcloud_read_status with wait_seconds until that version ends. Retry the restart. The stored replacement value is already in the vault. |
See the refusals reference for other errors.