Rotate a stored secret #

View this page as Markdown

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 #

  1. Find the application, environment, and secret name with tzcloud_list_secrets. Save the row's rotated_at and, if present, fingerprint. Check settings for a manifest binding and consumers for 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.

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

  3. Call tzcloud_store_secret with the same name and scope and with replace: true. For an application secret, name the application and its environment. Leave out value to get a secret rotate command. For file input, include value_file as Store a value from a file describes. Run the returned command exactly as given. A rotated: line and exit status 0 confirm the write.

    If you lose the response, read the exact row before trying again. A changed rotated_at does 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 full fingerprint with 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 with replace: 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 #

  1. On the stored secret's row, check applied_settings for the setting your code reads. Follow the response's next only if it returns a restart for that environment. If there is no next, 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, call tzcloud_restart_application for 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.
  2. Wait for the restart, deploy, or promote to finish. Follow its next to tzcloud_read_status if it is still running. Read tzcloud_list_secrets again for the same application and environment.
  3. Check that the setting is in applied_settings and that fingerprint and applied_fingerprint match. These two values mark the stored secret and the secret the serving version received. Compare the full strings. If either is null or 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 #

  1. Read the secret's rotated_at and stored fingerprint with tzcloud_list_secrets and compare them with the row you read before rotation. On the matching upstream in tzcloud_list_outbound_apis, check that credential_name names the rotated secret.
  2. 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.
  3. Read the upstream's last_call.at, outcome, and provider status. 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_call shows 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 #

  1. 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.
  2. 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_name in tzcloud_list_outbound_apis as well as the secret's row. Give the replacement only the permissions its uses require.
  3. 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.
  4. 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.
  5. 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.
  6. 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.