# Revoke role sessions

See the temporary credentials a role's token exchanges issued, and end every one that is still live.

Each exchange of an OIDC token for a role creates a session with its own temporary access key,
live for at most one hour. Revoking ends them before they expire. Replace role-id with the
role's id.

## Prerequisites

- To see the sessions: `iam:GetRole` on the role.
- To revoke them: `iam:RevokeRoleSessions` on the role, and in the console also `iam:GetRole` to
  open the role's page. Without `iam:RevokeRoleSessions`, **Revoke all** is not shown.
- In the console, also `iam:ListRoles` to open **Roles** (without it the list says you do not have
  permission to list roles).

## See the sessions

**Console**
1. Open **Identity**, then choose **Roles**, and open the role.
2. Choose **Sessions**.

The heading says how many credentials are live. The list shows the 10 newest sessions, each with
the token's subject, the session name, its age, and **live** or **expired**.

**CLI**
```sh
dcloud iam roles list-sessions role-id --limit 50
```

**API**
```http
GET /iam/api/roles/role-id/sessions?limit=50
```

The API answers with the sessions, newest first (`limit` 1 to 200, default 50), and `active`, the
number of live credentials. Each new exchange removes the role's sessions that expired more than a
day ago.

## Revoke every live session

**Console**
1. On the role's **Sessions** tab, choose **Revoke all**.

The page says how many live credentials were revoked. **Revoke all** appears only while at least
one credential is live.

**CLI**
```sh
dcloud iam roles revoke-sessions role-id
```

**API**
```http
POST /iam/api/roles/role-id/sessions/revoke
```

## Result

Every live session key of the role is deactivated at once, and temporary S3 credentials those
sessions created are deleted. A request with a revoked key is refused with 401
`Invalid or inactive access key`. Revoking does not change the trust policy: a job that exchanges a
new token gets a new session. To stop that too, remove or change the trust policy (see
[Set a trust policy](set-a-trust-policy.md)).

## Related

- [Deploy from GitHub Actions without a stored key](deploy-from-github-actions.md)
- [Web identity federation](web-identity-federation.md)
- `iam.roles.revoke-sessions` · `dcloud iam roles revoke-sessions`
