Ban a user
For: an operator who must stop one user from using the app now.
What it does: this runbook bans the user, lists what ends at once, and makes each resource server refuse the tokens that live on.
Before you start
Section titled “Before you start”- An operator secret with the scopes
usersandaudit. The first operator makes the entry. - The scope
sessionstoo, for the step after a failed end of the OAuth families. authtempo sessions end gives the command. - A sweep that runs from a scheduler. Delete expired rows (the sweep) tells how.
Do the steps in this order. Each step names what breaks when you skip it.
- Run
authtempo users search <base url> --email <address>. Copy the user id from theIDcolumn.- The ban takes a user id, not an address.
- Run
authtempo users ban <base url> <user id> --reason "<reason>" --yes. Add--until <date>for a ban with an end.- The reason goes into the audit row. A later reader sees why you acted.
- The command prints
banned <user id>; audit row <id>on stdout. - Exit 1 with a
warning:line on stderr means that the end of the OAuth refresh families failed. Do the step of the warning below.
- Run
authtempo users get <base url> <user id>. Read theBANcolumn:no-end, or the end of the ban.- A
-means that no ban holds. Read the stop text of step 2.
- A
- Make sure that the sweep runs at least once an hour.
- The sweep ends the sessions that the call left, and sends the sign-out messages to OAuth clients.
- Skip it, and those rows stay. Each door refuses them, but no
session.afterEndhook fires for them.
- Tell each resource server that reads a session JWT to call
POST /token/live, orapi.jwt.sessionLivein process.- A server that checks the signature alone accepts the JWT until its
exp.
- A server that checks the signature alone accepts the JWT until its
- Tell each resource server that reads an OAuth access token to call the introspection route.
- Introspection answers
active: falsefor a token of a banned user. The signature alone does not show the ban.
- Introspection answers
- Run
authtempo audit list <base url> --user <user id>. Find the row whoseIDis the audit row id of step 2. It has the actionban.- The row is the record of the act. Without the check, you do not see a refused act.
- Find the row by its id, not by its place. The rows of one act share a millisecond, and rows that two isolates write in one millisecond have no defined order.
What ends at once
Section titled “What ends at once”The ban runs one transaction. It writes the ban fields, and ends these rows of the user:
- every second-factor challenge;
- every handoff code;
- every OAuth refresh token and OAuth code;
- the impersonation sessions that the user opened as an operator, as many as fit the call;
- the sessions of the user, as many as fit the call.
The whole call fits 50 storage calls, the limit of one D1 Free run. The sessions and the impersonation sessions that do not fit stay, with one pending-end row. The sweep ends them. Until then, every door refuses them: the session read, the session JWT mint, and api.jwt.sessionLive. That row also refuses a session or an OAuth refresh family that starts in the 5 seconds after the ban. The bound covers a server whose clock runs ahead. The ban gives the counts of a test on D1.
What lives to its exp
Section titled “What lives to its exp”| Token | Its life | The check of a resource server |
|---|---|---|
| A session JWT | jwtMint.ttlMinutes: 15 minutes by default, at most 60 |
POST /token/live, or api.jwt.sessionLive |
| An OAuth access token | oauth.accessTtlMinutes: jwtMint.ttlMinutes by default, at most 60 |
POST /oauth/introspect |
| An API token | Its own expiry. Core refuses it while the ban holds | Core’s own check of each request |
| An organization token that the user made | Its own expiry. The ban does not stop it: it belongs to the organization | Revoke it with POST /organizations/tokens/revoke, or remove the member with revokeTokens: true |
Core refuses each of them at its own doors: the session read, the JWT mint, the user info, and the introspection. A resource server that verifies a JWT alone cannot see the ban. ASVS 5.0.0 7.4.1 asks for a control of a self-contained token after the end of its session. api.jwt.sessionLive and the introspection are the controls that core gives.
How it behaves
Section titled “How it behaves”- A sign-in of a banned user answers
account_bannedonly after the credential check. A wrong password answersinvalid_credentials, as for any user. - The mail flows answer a banned user as any user. A magic link still goes out, and its use answers
account_banned. - An API token works again after an unban. A session does not come back.
- A refused call of an API token spends nothing: core checks the ban before the window and the quota of the token.
- The unban writes the end of the ban. A session or a token from before that end stays refused.
- A magic link is not a session. A link mailed before the ban signs in after the unban, within its life:
magicLink.ttlMinutes, 15 minutes by default. - A timed ban ends at
--until. The same rule then holds: no credential from before the end comes back. - A ban of a platform operator also ends the impersonation sessions that the operator opened. Until the sweep ends a left one, each door refuses it.
If it fails
Section titled “If it fails”not_found: no user has the id, or the user tools are off.unauthorized: the secret is wrong, or its hash is not inoperator.secrets.operator_required: the entry lacks the scope of the command:usersforusers,auditforaudit list, orsessionsforsessions end.rate_limited: the 600 calls of this hour from this IP, or of this secret, are spent.invalid_body: the reason or the date breaks its rule.conflict: another change of the user ran at the same time. Run the command again.hook_refused: a before hook of your app refused the ban.hook_failed: a before hook of your app threw another error.