Skip to content
Rotate › Supabase

How to rotate Supabase API keys: secret keys, service_role and the JWT secret

Supabase now has two key systems running side by side. The new secret keys (sb_secret_) can overlap, so rotating one is routine. The legacy service_role key is a JWT signed by your project's JWT secret, and that changes everything about how it rotates.

Keysquid team · Updated · Checked against Supabase's docs on November 30, 2026

Key formats
sb_publishable_ publishable key (safe in browsers), sb_secret_ secret key (backend only). Legacy anon and service_role keys are long-lived JWTs.
Where
Project Settings → API Keys. There is no separate Settings → API page any more.
Overlap
Yes for secret keys: you can hold several at once, named per backend component, so old and new work side by side.
Revoke
Delete the secret key in Settings → API Keys. Deleting a secret key can't be undone.
Browser guard
A secret key sent from a browser gets HTTP 401: Supabase checks the User-Agent header.
Legacy keys
Deprecated in early 2027. Rotating them means changing the JWT secret, which invalidates anon and service_role at once.
By API
POST /v1/projects/{ref}/api-keys to create, DELETE /v1/projects/{ref}/api-keys/{id} to delete, with a personal access token.
Keysquid
Automatic for sb_secret_ keys. The legacy JWT keys aren't rotated: move your server to a secret key first.

Which Supabase key do you have?

KeyLooks likePrivilegeHow it rotates
Publishablesb_publishable_…Low; Row Level Security appliesCreate a new one, ship it in the next client release, delete the old
Secretsb_secret_…Full access, bypasses Row Level SecurityCreate a second key, deploy, delete the old one
anon (legacy)A JWT (eyJ…)Same role as publishableOnly by changing the JWT secret
service_role (legacy)A JWT (eyJ…)Same role as secretOnly by changing the JWT secret, or by disabling legacy keys

Creating publishable and secret keys doesn't revoke the legacy keys. Both systems work at the same time until you disable the legacy ones.

If your backend still reads SUPABASE_SERVICE_ROLE_KEY, you are on the legacy system. That matters for a rotation: a legacy key can’t be replaced on its own, so the cleanest “rotation” is moving to a secret key and switching the legacy keys off.

Rotate a secret key with no downtime

  1. Create the new key in Project Settings → API Keys, under Publishable and secret API keys. Give it a name that says where it’s used (for example billing_worker); Supabase suggests a separate secret key for each backend component, which also makes the next leak smaller.
  2. Deploy it everywhere the old key is used: server environment variables, CI secrets, Edge Function secrets and database webhooks (see below).
  3. Confirm every component uses the new key. Supabase has no usage indicator for this, so check your deploys and logs rather than waiting for errors.
  4. Delete the old key. It stops working, and the deletion is permanent.

The same steps through the Management API, with a personal access token that has the API Keys permission at read-write (revealing values also needs read access to API Key Secrets):

API=https://api.supabase.com/v1/projects/$PROJECT_REF/api-keys
AUTH="Authorization: Bearer $SUPABASE_ACCESS_TOKEN"

# 1. Create a new secret key and print its value (run locally, not in CI logs)
curl -s --fail -X POST "$API?reveal=true" -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"type": "secret", "name": "billing_worker_2026_12"}' | jq -er '.api_key'

# 2. After deploying it: find the old key's id and delete it
curl -s --fail "$API" -H "$AUTH" | jq '.[] | {id, name, type}'
curl -s --fail -X DELETE "$API/$OLD_KEY_ID" -H "$AUTH"

The places a Supabase key hides

WhereWhat to change
Edge FunctionsSupabase injects SUPABASE_SECRET_KEYS as a JSON object keyed by name, with the default key under default. Code that reads ['default'] keeps using that key, so point it at the new key’s name. Set your own copies under Edge Functions → Secrets.
Edge Function authSecret keys go in the apikey header. Sent as Authorization: Bearer, they fail with “Invalid JWT”, and functions called with a secret key need verify_jwt = false.
Database webhooks and pg_netWebhooks that send the legacy service_role key as a Bearer token must send the new secret key in an apikey header instead. Supabase suggests keeping it in Vault.
Browser and mobile appsNever a secret key. If you are retiring a leaked service_role key, also replace anon with a publishable key in clients, because disabling legacy keys switches off both.
CI and hostingGitHub Actions secrets, Vercel or Railway variables, and anything that runs migrations or seeds data with full access.

If a key leaked

Fix whatever exposed it first, so the replacement doesn’t leak the same way. Then:

  1. A leaked secret key: create a new one, replace it everywhere, and delete the compromised key. If someone is actively using it, delete it straight away and accept the errors while you redeploy.
  2. A leaked legacy service_role key: move every server to a new secret key and every client to a publishable key, then disable the legacy keys in Settings → API Keys. Supabase warns not to re-enable them if you find a client you missed, because that restores the compromised key; move that client to a new key instead.
  3. Also revoke the legacy JWT secret once you are on JWT signing keys (next section). Until then, anyone holding it can mint new service_role tokens.

Why this is urgent: a secret or service_role key bypasses Row Level Security, so it reads and writes every table. Our first 10 minutes after a key leak checklist covers what to check after the rotation.

The legacy JWT secret and signing keys

The anon and service_role keys are JWTs signed with your project’s JWT secret. Changing that secret invalidates both keys immediately and severs every connection using them until you deploy the new values. Supabase’s own advice is to avoid that by moving to the new API keys, and projects that haven’t moved to JWT signing keys can no longer rotate the legacy secret at all.

JWT signing keys replace the single secret with a set of keys you can rotate in stages, under Project Settings → JWT Keys:

StepWhat happens
Migrate JWT secretImports the legacy secret and creates a new asymmetric key that starts as a standby key.
Rotate keysThe standby key starts signing new access tokens. Tokens that haven't expired are still accepted, so nobody is signed out.
RevokeStops trusting the previously used key. Wait until its tokens have expired: with a 1-hour expiry, Supabase says to wait at least 1 hour 15 minutes.
DeleteDestroys the key for good. Every other step can be undone.

Most signing-key changes are throttled for about 5 minutes. Revoking the legacy secret requires disabling the anon and service_role keys first.

Before you rotate, make sure nothing in your code verifies tokens against the legacy secret. Supabase recommends supabase.auth.getClaims(), which checks tokens against the project’s published keys at /auth/v1/.well-known/jwks.json.

By hand vs. with Keysquid

By hand

  1. Create a named secret key per component.
  2. Update servers, CI, Edge Function secrets and webhooks.
  3. Check nothing still uses the old key, then delete it.
  4. Repeat for each project, on a schedule you have to remember.

With Keysquid

  1. Keysquid creates a new secret key through the Management API.
  2. It writes the value to every platform you map it to and redeploys.
  3. It deletes the old key after the grace period.
  4. Webhooks stored inside the database are still yours to update.

How Keysquid handles Supabase keys

Automatic Keysquid creates, verifies, distributes and revokes Supabase keys on a schedule, with no one in the loop. New-style secret API keys (sb_secret_…) via the Management API.

Setup, as the app shows it:

  1. Create a personal access token (or a fine-grained one with API gateway keys write).
  2. The legacy anon/service_role JWT keys can't be rotated this way. Switch your server to a secret key first.
  • Writes to: Secret key (default variable SUPABASE_SECRET_KEY), in every platform and secret store you map it to.
  • Interval: from every 1 hour to every 4 weeks, subject to your plan’s minimum.

Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.

Keysquid rotates secret keys only, one project at a time, and labels each one “Managed by Keysquid” so you can tell them apart in the dashboard. It doesn’t touch publishable keys, the legacy JWT keys or JWT signing keys: those affect your users’ sessions and belong in a planned change, not a schedule.

Frequently asked questions

How do I rotate the Supabase service_role key?

You can't replace it on its own: it's a JWT signed with the project's JWT secret, so changing it changes anon too and breaks every client at once. Move your servers to a secret key (sb_secret_), clients to a publishable key, then disable the legacy keys in Project Settings → API Keys.

Can I have two Supabase secret keys at the same time?

Yes. Secret keys are named and you can create several, which is what makes a zero-downtime rotation possible: deploy the new key, confirm nothing uses the old one, then delete it.

Does deleting a Supabase secret key take effect straight away?

Deleting it retires the key so it no longer grants access, and it can't be undone. Make sure every component has the new key first, unless the key is being actively abused.

When are Supabase's legacy anon and service_role keys going away?

Supabase says it is deprecating them in early 2027. Both key systems work side by side until then, so you can migrate one component at a time.

Will rotating JWT signing keys log my users out?

No. Rotating changes which key signs new access tokens; tokens that haven't expired stay valid. Revoke the previous key only after they have expired. The legacy JWT secret is different: changing it signs everyone out.

Why does my secret key return 401 in the browser?

Supabase rejects secret keys sent from browsers, based on the User-Agent header. Use a publishable key in the browser and keep secret keys on the server.

Sources

  1. Supabase docs: Rotate a leaked or compromised API key
  2. Supabase docs: Understanding API keys
  3. Supabase docs: Migrating to publishable and secret API keys
  4. Supabase docs: JWT signing keys
  5. Supabase docs: Rotating anon, service and JWT secrets
Rotate a Supabase Secret or service_role Key