# Cut a user off now

> When an account is compromised or someone leaves in a hurry, stop their sign-in, sessions, tokens and agents in minutes, and know what still lags and for how long.

A laptop is stolen, a password turns up in a paste, or someone leaves on bad terms. You need everything they hold to
stop now: new sign-ins, the sessions they have open, the tokens apps hold for them, and the agents that act in their
name. No single switch does all of it, so this runbook takes four steps, in an order that closes each door before the
next. Done in order, it takes a few minutes.

**Before you start:**

- **Who can do it:** a realm administrator, in a group that holds `RealmOwner`
  ([Delegated administration](/platform/realms/delegated-administration/)).
- **Where:** today this is done through the API, with your session in `$CVYUH_SESSION`
  ([Call the API](/develop/api/)). Sign in once and keep the session for the whole runbook.
- **What you need:** the user's name, here `ben`, and their id (`GET https://foobar.cvyuh.com/api/v0/am/objects/v1/user/ben`
  answers it as `id`).

## Cut them off

<Steps>

1. **Deactivate the user.** From this moment they can't sign in, no app can get a new token for them, every refresh
   token they hold stops working, and introspection reports their tokens inactive:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/user/ben \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "status": "inactive" }'
   ```

   Deactivating also stops every agent whose chain leads up to `ben`: each agent's token request walks up its chain
   to the user at the top, and an inactive user stops it.

2. **End every session they hold.** Deactivating doesn't end sessions already open, so end them all. Each ending is a
   sign-out: apps that listen for back-channel logout end their own sessions, and tokens issued under the session are
   revoked:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/am/sessions/v1/end \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "qbe": { "filter": { "field": "user", "op": "=", "value": "<ben id>" } } }'
   ```

   The realm answers how many it ended: `{ "ended": 3 }`.

3. **Stop the agents they own.** An agent whose business owner is `ben` but whose chain leads up to someone else
   keeps running after step 1. List the agents he owns:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/am/objects/v1/user/ben/relationships/ownedAgents \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   and quarantine each one, which also stops every agent under it:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/agent/invoice-agent \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "status": "quarantined" }'
   ```

   Quarantine can be undone; kill an agent only when you're sure ([Stop an agent](../../agents/stop-an-agent/)).

4. **Rotate what they knew.** If they could read an app's client secret, rotate it, so a copy they kept stops
   working once the overlap you choose ends ([Rotating a secret with an overlap](../../../applications/client-security/client-authentication/#rotating-a-secret-with-an-overlap)).

</Steps>

<Aside type="note" title="Owners' agents and received signals">
  When a provider you [receive signals](../../../signals/receive-signals/) from reports the user's account disabled,
  the realm quarantines the agents they own by itself. Deactivating them here doesn't: that's step 3.
</Aside>

## How fast each kind of API stops

New sign-ins, new tokens and refreshes stop at once, everywhere, because only the realm issues them. A token already
issued stops as fast as the API that checks it learns of it:

| Where the token is checked | It stops working |
|---|---|
| The realm itself: userinfo, refresh, token exchange | At once |
| An API that introspects each token, or asks the realm for a decision | At once |
| An API behind the gateway | Within seconds, at the gateway's next revocation poll (10 seconds by default) |
| An API that checks signatures and reads status lists | Within a minute |
| An API that checks signatures only | When the token expires: five minutes by default |
| An app's own session, if the app ignores back-channel logout | When the app next needs a token, or its own session ends |

See [How fast revocation takes effect](/gateway/revocation/how-fast/) to make the slow rows faster.

## Check it worked

- **The user** reads `"status": "inactive"`, and `GET https://foobar.cvyuh.com/api/v0/am/sessions/v1` with a filter on
  their id lists no sessions.
- **Their agents** read `quarantined`.
- **On the audit trail** ([Read a user's or agent's trail](/audit-reports/audit-trail/read-a-trail/), or
  **Audit → Authentication** and **Audit → Config** in the dashboard):
  - the deactivation, as `PATCHED` with `status` before and after;
  - one `LOGOUT` for each session ended;
  - `AGENT_QUARANTINED` for each agent;
  - from then on, any attempt: `LOGIN_FAILED` with the reason `AUTH_USER_INACTIVE`, and `TOKEN_ISSUED` refused
    for any app or agent that asks for a token for them.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The user still reaches an app | The app checks tokens by signature only, or keeps its own session and ignores logout | Wait out the access token (5 minutes by default); put the API behind the gateway or have it introspect; have the app listen for back-channel logout |
| An agent still gets tokens | Its chain leads to another user, and it wasn't quarantined | Quarantine it (step 3), or the agent above it |
| Ending sessions answers `{ "ended": 0 }` | They had no live session, or the id is wrong | Check the id from the user's record |
| An app still uses a secret they knew | It wasn't rotated | Rotate it (step 4) |

## Undo it

Set `{ "status": "active" }` on the user, and set each agent back to `active` (released agents are recorded as
`AGENT_RELEASED`). Sessions don't come back: the user signs in again, and apps ask for new tokens.

## Related

- [End a user's sessions](../end-a-users-sessions/): sessions alone, when the account isn't at risk.
- [Turn access off and on](/directory/users/turn-access-off-and-on/): the user's `status` and `accountExpiry`.
- [Stop an agent](../../agents/stop-an-agent/): quarantine, kill and retire.
- [Session management](../../../authentication/session-management/): listing and ending sessions.
- [Look into a locked account](/audit-reports/guides/look-into-a-locked-account/): reading the trail.
