This page helps you respond when something goes wrong in staging or production: a key or secret leaks, an administrator account is in the wrong hands, auth goes down, or mail stops going out. Each runbook says how you notice, what to do in order, and how to check that it's over.
Run every auth-service command below in the affected environment, with
piquelctl app exec -t sourceorigin auth --env production -- auth-service --operator <you> … (see
running auth-service commands).
-t gives the command a terminal: most commands below ask you to confirm what
they will change, and refuse without one. The
command line needs only the database, so it works while auth's pages and the
admin dashboard don't.
Warning: after rotating a secret, never restore a deployment made before the rotation: a restore, like an automatic rollback, brings back the secret versions it ran with. Watch the deployment that rotates it, and fix forward if it fails.
A signing key's private key opens only with both the database and the
key-encryption key (AUTH_KEY_ENCRYPTION_KEY). Treat every stored key as
compromised when both may have leaked: a copy of the database and the
key-encryption-key secret together, or a host that runs auth.
piqueld may also still store an environment's old signing-key secret, which
nothing mounts any more: piquelctl env secret sourceorigin --env <env> list
lists it. It holds the private key of primary, the key it was imported as,
in plaintext PEM. If that value leaks, primary is compromised on its own:
revoke it if keys list still lists it, then delete the secret with
piquelctl env secret sourceorigin --env <env> delete signing-key.
-
If whoever holds them may still read the database or the host, close that access first. The key-encryption key seals every key auth generates, including the one that replaces the revoked key, so someone who holds it and reads the database again can open the new key too. If it may have leaked, revoke now, then change it as a leaked key-encryption key describes, which ends with revoking again.
-
Find the key to revoke: the one in state
active, orprimarywhen only the storedsigning-keysecret leaked:auth-service keys list
-
Revoke it:
auth-service keys revoke <id> --reason "Compromised"
On the dashboard, select Revoke next to it on the Signing keys page. When the revoked key was
active, thenextandretiringkeys go with it, since their private keys were stored beside it, and a new key signs at once. Revoking any other key removes only that key. -
Wait 15 minutes after the revocation. Each replica serves its own copy of the key set and reloads it each minute, and one that can't reload stops serving within 15 minutes, so only then has every replica dropped the revoked keys.
https://auth.sourceorigin.dev/.well-known/jwks.jsonno longer listing them shows only that the replica that answered has. -
Then restart the first-party resource servers, which drops the keys they cached. Restarting sooner could cache the revoked keys again from a replica that still serves them. Other apps keep the revoked keys as long as their cache allows, which check that it's over bounds.
Every access and ID token the revoked keys signed stops working at auth,
including as an id_token_hint. Refresh tokens don't depend on signing keys, so
apps refresh and receive tokens signed by the new key.
-
auth-service keys listlists none of the revoked keys, and a newactivekey if you revoked the active one. -
https://auth.sourceorigin.dev/.well-known/jwks.jsonno longer lists their IDs. -
90 minutes after the revocation, every app verifying with the SDKs has dropped them. Until then, whoever holds a revoked key can mint tokens that those apps accept, with any
exp, so token lifetimes don't shorten this window. The 90 minutes add up two bounds:- The cache deadline. An SDK uses the keys it fetched until the key set's
max-age, an hour, has passed, then refreshes them. When refreshes fail, it keeps the stale keys for 15 more minutes, then stops verifying until a fetch succeeds. So an app drops a key at most 75 minutes after its last successful fetch, even if an attacker makes its fetches fail. - The replicas' delay. A replica that can't reload serves the revoked keys for up to 15 minutes after the revocation (step 4), and an app that fetches from it then starts a new hour.
Verifiers that don't use the SDKs bound this themselves. One that respects
Cache-Controldrops the keys 75 minutes after the revocation, unless it keeps stale keys while its fetches fail. One that ignoresCache-Controlmay accept them longer. - The cache deadline. An SDK uses the keys it fetched until the key set's
Signing keys explains revocation and reloads.
The key-encryption-key secret, AUTH_KEY_ENCRYPTION_KEY, appears outside the
environment: in a backup, a log, or on a compromised host.
On its own it opens no signing key: the keys it seals are in the database. With a copy of the database, made before or after the leak, it opens every signing key in that copy.
- If whoever holds it may still read the database or a host that runs auth, close that access first.
- If a copy of the database may be in the same hands, every signing key is compromised: revoke the active key now, as a compromised signing key describes. Its replacement is still sealed under the leaked key, so step 4 revokes again.
- Change the key-encryption key, as changing the key-encryption key describes. Take each step as soon as the one before has deployed: no step needs to wait.
- Replace the signing keys sealed under the leaked key. Every copy of the
database made before you rewrapped, backups included, still holds them.
- If a copy may be in the same hands, revoke the active key again, as
a compromised signing key describes. The
nextandretiringkeys go with it, and its replacement is sealed under the new key-encryption key. - Otherwise, rotate ahead of schedule, so the old keys stop signing within
a day. A
nextkey already waiting was sealed under the leaked key too: revoke it first withauth-service keys revoke <id> --reason "…". Then runauth-service keys rotate --reason "Key-encryption key leaked".
- If a copy may be in the same hands, revoke the active key again, as
a compromised signing key describes. The
auth-service keys listlists anactivekey created after you rewrapped, or anextkey that will sign within a day.- The dashboard's Events page, filtered by
signing_key_changed, lists Signing key rewrapped for every key that had a private key. piquelctl env secret sourceorigin --env <env> listno longer lists the oldkey-encryption-key.
A secret starting with socs_ appears where it shouldn't: in a repository, a
log, a ticket or a message. Secret scanners recognize the prefix. The app's
owner may report it too.
With the secret, someone can authenticate as the app at the token endpoint, with a code or a refresh token the app was given.
-
Find the client the secret belongs to, with the app's owner, or in
auth-service client list. -
Revoke every earlier secret at once, and get a new one:
auth-service client rotate-secret <client-id> --grace 0 --reason "Secret leaked"
On the dashboard, open the client, select Rotate the secret, choose Stop them now for Earlier secrets keep working, and select Rotate secret. For an account's client, its owner can do the same on its Secrets tab in the developer console.
The app can't sign anyone in until it has the new secret.
-
Give the app the new secret, printed once, and deploy it. For a client a deployment registers with
client apply, regenerate the deployment's secret instead: its nextclient applywould register the leaked value again. -
If more than the secret leaked, such as the app's server with the refresh tokens it holds, also stop the client until the server is clean:
auth-service client disable <client-id> --reason "…"stops it from authorizing and refreshing tokens at once. Deleting the client revokes its refresh tokens for good (see OIDC clients).
auth-service client show <client-id>lists the new secret without an end, and every earlier one ending at the rotation.- The app signs users in again.
The token-digest-key secret, AUTH_TOKEN_DIGEST_KEY, appears outside the
environment: in a backup, a log, or on a compromised host.
Auth stores refresh tokens, authorization codes and pending logins as HMAC digests under this key, and the links of its emails derive from it: email verification, recovery, invitation, unsubscribe and sign-out links. With the key and the ID of an address, a recovery, an invitation, an account or a notification, someone can rebuild the link auth sent for it. An unsubscribe link only turns that account's announcements' email off, but it never expires. A sign-out link only signs its account out everywhere.
The usual change takes two deployments and keeps the old key accepted for about 30 days (see changing the token digest key). For a leaked key, replace it at once instead:
-
Generate a new key:
piquelctl env secret sourceorigin --env production regenerate token-digest-key
-
Deploy production's own release again, as pick up a changed secret describes. For staging, run
piquelctl --timeout 30m env deploy sourceorigin staging.Every refresh token, code and login in progress under the old key ends, so apps sign their users in again. During the rollout, each release refuses what the other issued.
-
Deal with the recoveries started in the last day, which
auth-service audit list --kind recovery_startedlists. For each account, runauth-service user undo-recovery <user> --reason "…"without--yes: it prints the account's recent recoveries with where each stands, then asks to confirm what it will do.- If the recovery says link not used, and the prompt says it will cancel
its unused link, confirm. Start a new recovery with
auth-service user recoveronce the new key is deployed: the new link derives from it. - If the link was used since the leak, the passkey it enrolled may be the attacker's. Don't confirm: undoing removes that passkey and every session, which locks the account holder out if the passkey was theirs. Ask the holder, through a channel support already trusts, whether they used it, and undo it only if they didn't.
- If the recovery says link not used, and the prompt says it will cancel
its unused link, confirm. Start a new recovery with
-
Revoke, with
auth-service invite revoke, the invitations created before the new key was deployed, whichauth-service invite listlists, and create new ones: a link already sent keeps working against its stored digest until the invitation expires, 7 days by default and up to a year. Resend can't rebuild such a link once the old key is removed, so its delivery fails.
Links already sent are checked against the digest stored when they were made, so verification and recovery links keep working until they expire, within 24 hours. For that day, someone with the old key could confirm an address an account added but hasn't confirmed yet. Unsubscribe and sign-out links are checked by deriving them again, so those built from the old key stop working once the new key replaces it.
auth-service keys digest-usagecounts new digests undercurrent, and the old ones asunknownuntil cleanup deletes them.- 24 hours have passed since the deployment, so every verification and
recovery link derived from the old key has expired, and
invite listshows no open invitation created before it.
The database-password secret, the superuser sourceorigin's password, or
database-runtime-password, sourceorigin_auth's, appears outside the
environment: in a backup, a log, or on a compromised host.
PostgreSQL answers only on the application's private network, so the password alone doesn't open it. With a way onto that network too, the superuser's password reads and changes everything in the database, and the runtime role's reads and changes the accounts and sessions auth stores.
-
If whoever holds it may still reach the host or the application's network, close that access first.
-
A new password doesn't undo what someone who connected as the superuser left behind. A superuser can run commands as PostgreSQL's system user and change any file in its volume, so no check proves the database clean. If someone did connect, load a copy of the database made before the leak into a new volume: a dump or a volume backup, not
piquelctl env restore, which keeps the volume. If you have none, or can't tell whether anyone connected, check at least these before you rotate. Compare each with the same query on a fresh preview, whose database is new, run withpiquelctl preview exec sourceorigin <branch> postgres -- psql -U sourceorigin -d sourceorigin -c "…":-
The roles that can log in:
piquelctl app exec sourceorigin postgres --env <environment> -- psql -U sourceorigin -d sourceorigin -c "SELECT rolname FROM pg_roles WHERE rolcanlogin"
Only
sourceoriginandsourceorigin_authshould. Remove any other withREASSIGN OWNED BY <role> TO sourceoriginandDROP OWNED BY <role>in each database, thenDROP ROLE <role>. -
The authentication rules, from
SELECT * FROM pg_hba_file_rules, run the same way. Every column must match the preview's, masks included. -
The server settings, from
SELECT sourcefile, name, setting FROM pg_file_settings. One frompostgresql.auto.confcame fromALTER SYSTEM, which SourceOrigin never uses: runALTER SYSTEM RESET ALL. -
Settings stored on a database or role, from
SELECT * FROM pg_db_role_setting, and event triggers, fromSELECT evtname, evtevent FROM pg_event_trigger. Both are empty on a new database.
Anything else that differs from the preview's means a changed file or catalog: load a copy from before the leak instead.
-
-
Generate a new value for the secret that leaked:
piquelctl env secret sourceorigin --env <environment> regenerate database-password
For
database-runtime-password, regenerate that one instead. -
Deploy production's own release again, as pick up a changed secret describes. For staging, run
piquelctl --timeout 30m env deploy sourceorigin staging.For the superuser's password, PostgreSQL restarts with the new one before
migrateruns. For the runtime role's,migratesets the new one, and connections already open with the old one stay open until they close. See the database password and the database runtime password. -
If someone may have connected:
- Check that they didn't rewrite the history with
auth-service audit verify. - The superuser could also have changed any row, such as an administrator grant or a client's redirect URIs, without leaving an event. If you can't rule that out, load a copy from before the leak, as step 2 says.
- If they could also have read the
key-encryption-keysecret, follow a compromised signing key.
- Check that they didn't rewrite the history with
- The deployment succeeded: its
migratejob logged in with the new value. piquelctl env secret sourceorigin --env <environment> listshows the new version of the secret.- If someone may have connected, the database was loaded from a copy made before the leak, or its login roles, authentication rules, settings and event triggers match a fresh preview's.
- The Admin activity dashboard shows changes nobody you know made: rights granted, accounts disabled or viewed, refused sign-ins.
- An owner asks about a change "By a SourceOrigin administrator" in their security history that they never asked for.
- An administrator finds an entry in their own security history that isn't
theirs, and reports it, which signs out their other sessions.
auth-service audit list --kind compromise_reportedlists these reports. auth-service admin listlists an administrator nobody granted.- An alert says The audit chain is broken or The audit chain's checkpoints stopped: someone changed the history (see respond to an alert).
Act at the terminal: the dashboard never changes an administrator's account, while the command line may.
-
Revoke the account's rights, which ends its dashboard access on its next request:
auth-service admin revoke <handle> --reason "Account compromised"
If it holds the last rights, first grant them to an account you trust with
auth-service admin grant <handle> --reason "…". -
End its sessions, which ends its dashboard session with them:
auth-service account <handle> sessions revoke-all --reason "Account compromised"
-
If the account's passkey may be in someone else's hands, not just a session, stop it signing in while you find out:
auth-service user disable <handle> --reason "Compromised administrator account"
Then return the account to its owner, following the evidence policy: enable it, since a recovery needs an active account, and recover it with
--revoke(see recover an account someone else held). -
Find what it did: Actions by administrator and Administrative events on the Admin activity dashboard, the dashboard's Events page, and
auth-service audit list, such as--kind administrator_granted. -
Undo each change: revoke the rights it granted, enable the accounts it disabled, lift the suspensions it made, and undo the recoveries it started with
auth-service user undo-recovery. -
Verify that the history you relied on is intact, from a trusted build:
auth-service audit verify
A change made at the terminal records its operator's name (--operator,
AUTH_OPERATOR or $USER) and host name. One
that nobody made points at a compromised host: treat the secrets on it as
leaked, starting with the runbooks above.
auth-service admin listlists only the administrators you expect.auth-service account <handle> sessions listlists no session you don't recognize.- The Admin activity dashboard shows only work you know of.
auth-service audit verifyreports the chain intact.
- auth.sourceorigin.dev answers errors, or nothing, and users report it.
https://auth.sourceorigin.dev/health/readydoesn't answer204. It checks the database and that the replica's signing keys were reloaded recently.piquelctl env show sourceorigin productionreports a service unhealthy.- The Auth overview dashboard's Server errors rise. Grafana keeps working, since it never signs in through auth (see sign in to Grafana).
-
See what piqueld sees:
piquelctl env history sourceorigin production piquelctl env logs sourceorigin production --service auth --since-seconds 900 -
If a deployment caused it, return to the previous one. When its rollout failed, production already restored the last successful deployment on its own. Otherwise, restore it: see roll back production.
-
Read Grafana's Auth overview: Server errors, Database connections and Logs.
-
If the replicas aren't ready because of the database, read
piquelctl env logs sourceorigin production --service postgres. -
If they aren't ready because of their signing keys, the logs say which key failed. A replica that can't reload its keys fails readiness after 5 minutes, and answers
503where it signs or verifies after 15. A key that won't open is removed withauth-service keys revoke <id> --reason "…", which works even when the active key can't be opened (see replace a key that doesn't open).
Meanwhile, every administrative operation runs at the terminal: the command
line is the break-glass path when the dashboard or auth's pages are
unreachable. piquelctl app exec needs a running auth container: if none
runs, restore a deployment first. Nothing auth runs on needs auth to sign in: piqueld, the servers, the
tailnet, PostgreSQL, DNS, the tunnel, Grafana and Resend (see
recovering auth).
piquelctl --timeout 10m env wait sourceorigin production --ready routesreturns: the deployment runs healthy, and every route answers. It waits for the deployment that was newest when it started, so if that one failed and production rolled back, checkpiquelctl env history sourceorigin productionandpiquelctl env url sourceorigin productioninstead.https://auth.sourceorigin.dev/health/readyanswers204.- Server errors on the Auth overview dashboard are back to their usual level.
- Users don't receive verification, recovery, notice, invitation or announcement emails.
- On the Auth overview dashboard's Deliveries row, a mail channel's Pending deliveries grow, its Oldest pending delivery gets older, and Delivery attempts show retries or failures.
-
List what is waiting and what failed:
auth-service deliveries list --channel email --status pending auth-service deliveries list --channel email --status failed
Run them again with
--channel invitationand--channel announcement, which send invitations and announcements. Each delivery's last error is the SMTP reply code. -
Fix the cause the code points at:
535,530or534: Resend rejected the key. Store a working one, as rotate a Resend key describes. Rejected logins retry for 24 hours, or 72 for invitations and announcements, so mail queued meanwhile goes out once auth runs with the new key.- Another
5xx: Resend refused the message for good, and the delivery failed. Check the sending domain's status and its DNS records in Resend's dashboard. - A timeout, or a connection or TLS failure: auth can't reach Resend. Check Resend's status, and auth's logs.
-
Once the cause is fixed, retry the failed deliveries still worth sending:
auth-service deliveries retry <id> --reason "Mail back up"
A retry makes the delivery due now, and gives it another 24 hours, or 72. On the dashboard's Deliveries page, select Retry.
Mail that arrives but lands in spam points at the DNS records, not the queue.
- The
emailchannel's Pending deliveries are back to their usual level. - New deliveries in
auth-service deliveries list --channel emailaresucceeded, and Resend's dashboard lists the messages as delivered.