# Rotate a secret (/en/docs/deployment/after-launch/rotate-a-secret)

Replace an expiring or exposed secret. Where the provider permits overlap, create
the new value, update every consumer, check it, then revoke the old value.
Check the provider’s rotation instructions first; overlap is not always available. If a leaked key is actively being used, revoke it immediately and restore affected consumers with a new key.

**Give your agent this prompt:**

```text interactive=true
Plan rotation of <secret name> without printing its value.
Follow https://coremvp.com/en/docs/deployment/after-launch/rotate-a-secret.md and its prerequisites.
Finish planning with the consumers and checks identified; ask me before issuing, replacing or revoking credentials or deploying.
After approval, prove the affected deployment uses the replacement. For Stripe webhooks without receiver-side proof during overlap, check a fresh delivery after the old secret expires. For immediate revocation, restore consumers first and check recovery. Run ./coremvp prod e2e smoke https://<app-domain>.
Report what changed, the check results and anything you could not run.
```

| Secret                                         | Create the new one in                                                                                                | Save it in                                                                                                                                                     |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SUPABASE_SECRET_KEY`                          | [Supabase API keys](https://supabase.com/docs/guides/api/api-keys) (create a new secret key)                         | Your host                                                                                                                                                      |
| Database password                              | Supabase **Settings → Database → Reset password**                                                                    | `DATABASE_URL` in your host, and on Cloudflare [update Hyperdrive credentials](https://developers.cloudflare.com/hyperdrive/configuration/rotate-credentials/) |
| `STRIPE_SECRET_KEY` / `STRIPE_SECRET_KEY_LIVE` | Stripe **Developers → API keys → Rotate key** ([guide](https://docs.stripe.com/keys#rotate-an-api-key))              | Your host                                                                                                                                                      |
| `STRIPE_WEBHOOK_SECRET`                        | Stripe webhook destination **Roll secret** ([guide](https://docs.stripe.com/webhooks#roll-endpoint-secrets))         | Your host                                                                                                                                                      |
| `POLAR_ACCESS_TOKEN`                           | [Polar Organization Access Tokens](https://docs.polar.sh/documentation/integration-guides/authenticating-with-polar) | Your host                                                                                                                                                      |
| `POLAR_WEBHOOK_SECRET`                         | Polar webhook endpoint settings                                                                                      | Your host                                                                                                                                                      |
| `RESEND_API_KEY`                               | [Resend API Keys](https://resend.com/docs/dashboard/api-keys/introduction)                                           | Your host, and Supabase SMTP password                                                                                                                          |

In live mode, the Stripe client uses `STRIPE_SECRET_KEY_LIVE` when configured, otherwise `STRIPE_SECRET_KEY`. Update the value actually used.

A database password reset can interrupt connections. Plan a maintenance window
and update every consumer immediately; see [Supabase’s reset guidance](https://supabase.com/kb/troubleshooting/how-do-i-reset-my-supabase-database-password-oTs5sB).

### 1. Save the new value

**Vercel:**

```bash interactive=true
bunx vercel env update <NAME> production --sensitive
```

**Cloudflare:**

Update the value in `.env.cloudflare`.

### 2. Redeploy

On Vercel run `bunx vercel deploy --prod`; on Cloudflare run the build and
deploy from [Deploy to Cloudflare](/en/docs/deployment/cloudflare#deploy).

### 3. Revoke the old value

Once the deployment proves it uses the new value, revoke the old value
with the owner's approval. For a Stripe webhook rotation without that
proof during overlap, agree on the expiry time and recovery owner before
rotating, and keep the window open until the post-expiry check below passes.
If immediate revocation was required, proceed to the recovery check.

## Check it works

Run `./coremvp prod e2e smoke https://<app-domain>`. Exercise the affected
feature on the updated deployment as well.

For Stripe webhooks, Stripe signs with both secrets during overlap. A successful
delivery during that window can use either secret. If you cannot prove which
secret the deployed receiver used, check a fresh delivery on that Stripe
destination after the old secret expires. Check that the deployed endpoint
returns success and that the app records the expected result for that event.
If verification fails, immediately restore the new secret on the affected
deployment, redeploy, and retry the failed deliveries once verification works.
Keep the rotation open until this check passes. Use the endpoint's existing
billing mode and get approval before generating any real billing event.

If replacement revoked the old credential immediately, restore all consumers
with the new value and check the affected feature recovers. For a shared Resend
key, check both configured consumers: a Supabase Auth sign-up email and an
application purchase or onboarding email.
