Skip to content

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.

Do the steps in this order. Each step names what breaks when you skip it.

  1. Run authtempo users search <base url> --email <address>. Copy the user id from the ID column.
    • The ban takes a user id, not an address.
  2. 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.
  3. Run authtempo users get <base url> <user id>. Read the BAN column: no-end, or the end of the ban.
    • A - means that no ban holds. Read the stop text of step 2.
  4. 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.afterEnd hook fires for them.
  5. Tell each resource server that reads a session JWT to call POST /token/live, or api.jwt.sessionLive in process.
    • A server that checks the signature alone accepts the JWT until its exp.
  6. Tell each resource server that reads an OAuth access token to call the introspection route.
    • Introspection answers active: false for a token of a banned user. The signature alone does not show the ban.
  7. Run authtempo audit list <base url> --user <user id>. Find the row whose ID is the audit row id of step 2. It has the action ban.
    • 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.

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.

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.

  • A sign-in of a banned user answers account_banned only after the credential check. A wrong password answers invalid_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.
  • not_found: no user has the id, or the user tools are off.
  • unauthorized: the secret is wrong, or its hash is not in operator.secrets.
  • operator_required: the entry lacks the scope of the command: users for users, audit for audit list, or sessions for sessions 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.