# Device revocation

> Cut a device off at once, everywhere, and let it back in when it's found.

When a laptop is lost or stolen, revoke it. Every stream the device holds is closed at once, and every new one it
tries to open is refused. Its security sensor, its AI tools agent and its session all go quiet together, because they
all ride the device's one connection.

Revocation is reversible. When the device turns up, restore it and it reconnects with the certificate it already has.
A device that won't come back is removed instead; see [Device removal](../removal/).

## Before you begin

- **Privilege:** revoking and restoring need `MODIFY` on the realm's endpoint settings, which `RealmOwner` holds
  ([Who can call](../../api/#who-can-call)).
- **Where:** the API.
- **The device id**, the `id` on its [Device records](../../devices/device-records/) entry.

## How it works

The device's standing lives on its record (see [Device records](../../devices/device-records/)). Revocation takes
effect at once: the device's open connection closes and any new one is refused, even if part of the service was
restarting when you revoked it.

A revoke records who revoked the device (`revokedBy`), why (`reason`), and when (`statusChangedAt`). A restore
turns the record `active` again and clears them.

## Set it up

Revoke the device by its device id, with a reason you'll recognize later ([Call the API](../../../develop/api/)):

```sh
curl -X PUT https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/revocation \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{"reason": "Reported stolen, ticket 4411"}'
```

The realm answers `204`. To let the device back in, restore it:

```sh
curl -X DELETE https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/revocation \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

Both take an optional `If-Match` with the record's `ETag`, so a change made over someone else's is refused with
`412`.

## What the user sees

Nothing on the screen. The laptop keeps working and its data stays: revoking cuts the device off from the realm; it
doesn't lock or wipe it. The device client keeps trying to connect and is refused, so the device's security events
stop arriving and its AI tools agent can't reach the realm. Once restored, it reconnects on its own.

## If it fails

| Status | When | What to do |
|---|---|---|
| `400` | The device is being removed | Nothing to do: it's already refused, and its record is going |
| `403` | You lack `MODIFY` on the realm's endpoint settings | Ask a realm administrator to [grant it](../../api/#who-can-call) |
| `404` | No device with that id in this realm | List the realm's devices for its id |
| `412` | The record changed since the `ETag` you sent | Read the record again, check the change, and send its new `ETag` |

## Limits and defaults

| What | Value |
|---|---|
| Takes effect | At once |
| `reason` | Optional; your words, kept on the record while it's revoked |
| Devices per call | One |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A revoked device still shows `connected: true` | The read came in as it was being cut | Ask again; read the record's `status` |
| A restored device doesn't reconnect | Its certificate's year is up, or its client isn't running | Check the device client's [Troubleshooting](../../enrollment/device-client/#troubleshooting) |
| The user can still reach your apps from another machine | Revoking a device ends nothing the user holds elsewhere | Revoke their sessions and tokens too ([Revocation](../../../gateway/revocation/)) |

## Audit record

A revoke and a restore are each recorded on the realm's audit trail as a change to the device's record (`PATCHED`),
with who made it and the `status`, `revokedBy` and `reason` before and after. See
[What is recorded](../../../audit-reports/audit-trail/what-is-recorded/).

## Good to know

- **Everything stops at once.** The device's session, its sensor's events and its AI tools agent share one standing.
- **The user's own access is separate.** Revoking a device ends nothing the user holds elsewhere: their sessions and
  tokens on other machines stay until you revoke them; see the gateway's [Revocation](../../../gateway/revocation/).
  A revoked device refused by every part of the realm, with the tokens bound to it, is
  [planned](../../devices/whats-next/#device-refusal-everywhere).
- **Revoking again keeps the first time.** Revoking a device already revoked updates who and why, but
  `statusChangedAt` stays the time of the first revoke. Restoring a device that isn't revoked changes nothing.
- **Not while it's being removed.** A device being removed can't be revoked or restored; it's already refused.

## Related

- [Cut off a lost device](../../guides/cut-off-a-lost-device/): the task, start to finish.
- [Device removal](../removal/): when the device isn't coming back.
- [Device records](../../devices/device-records/): where the standing is kept.
