Cian Johnston
4a3304fc38
feat(cli)!: expire tokens by default ( #21783 )
...
## Summary
> NOTE: Calling this out as a breaking change in case existing consumers
of the CLI depend on being able to see expired tokens OR being able to
delete tokens immediately.
Updates the `coder tokens rm` command to immediately expire a token by
ID, preserving the token record for audit trail purposes. Tokens can
still be deleted by passing `--delete`.
## Problem
During an incident on dev.coder.com, operators needed to urgently expire
an API key that was stuck in a hot loop. The only way to do this was via
direct database access:
```sql
UPDATE api_keys SET expires_at = NOW() WHERE id = '...';
```
This is not ideal for operators who may not have direct DB access or
want to avoid manual SQL.
## Solution
This PR adds:
- **API endpoint**: `PUT /api/v2/users/{user}/keys/{keyid}/expire` -
Sets the token's `expires_at` to now
- **SDK method**: `ExpireAPIKey(ctx, userID, keyID)`
- **Updates CLI**: `coder tokens rm <name|id|token>` now _expires_ by
default. You can still delete by passing the `--delete` flag. The `coder
tokens list` command now also hides expired tokens by default. You can
`--include-expired` if needed to include them.
- **Audit logging**: The expire action is logged with old and new key
states
## Test plan
- Tests cover: owner expiring own token, admin expiring other user's
token, non-admin cannot expire other's token, 404 for non-existent token
Closes #21782
🤖 Generated with [Claude Code](https://claude.com/claude-code )
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com >
2026-02-17 13:16:46 +00:00
..
2026-01-08 15:24:11 +04:00
2026-02-02 15:50:09 +02:00
2026-02-03 14:10:49 -06:00
2025-06-24 11:16:31 +02:00
2024-02-26 10:03:49 -06:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-12-15 09:40:59 -07:00
2023-09-04 21:42:45 +03:00
2026-02-17 13:16:46 +00:00
2025-06-20 13:16:55 -06:00
2025-11-05 14:22:24 +02:00
2026-02-05 12:32:07 -06:00
2025-10-27 17:07:25 +01:00
2025-06-20 13:16:55 -06:00
2025-09-22 17:14:07 +04:00
2024-08-22 15:40:53 +10:00
2025-09-29 17:01:54 +04:00
2025-06-06 16:44:25 +04:00
2025-07-03 11:28:00 -06:00
2025-06-06 16:44:25 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-02-03 14:10:49 -06:00
2026-02-03 14:10:49 -06:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2025-03-04 15:37:29 -07:00
2025-03-04 15:37:29 -07:00
2025-03-04 15:37:29 -07:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-03-26 01:56:39 -05:00
2025-06-30 12:12:20 -08:00
2025-09-22 17:14:07 +04:00
2026-01-29 14:40:02 +01:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2026-02-02 16:16:16 +02:00
2026-01-08 15:24:11 +04:00
2026-02-02 16:16:16 +02:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2024-03-17 09:45:26 -05:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-02-03 14:10:49 -06:00
2025-03-26 01:56:39 -05:00
2025-09-03 10:49:19 +04:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2025-09-03 10:38:42 +04:00
2025-09-03 10:49:19 +04:00
2026-01-28 14:01:07 +02:00
2025-09-03 10:49:19 +04:00
2025-03-26 01:56:39 -05:00
2023-09-08 18:21:33 +00:00
2025-12-15 09:40:59 -07:00
2025-09-25 16:54:44 -04:00
2025-12-03 11:32:59 +02:00
2026-01-29 16:06:17 +01:00
2026-01-29 16:06:17 +01:00
2025-05-12 11:45:24 -07:00
2025-10-30 17:41:08 -06:00
2026-01-08 15:24:11 +04:00
2026-02-03 09:45:23 +00:00
2024-06-13 10:19:36 +04:00
2025-09-22 17:14:07 +04:00
2025-09-11 15:08:57 +02:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-12-22 11:28:31 +00:00
2026-01-07 16:06:00 +00:00
2026-02-06 14:09:39 +11:00
2026-02-06 14:09:39 +11:00
2026-02-05 19:35:20 +11:00
2026-02-06 14:09:39 +11:00
2025-09-22 17:14:07 +04:00
2024-08-20 14:47:46 +10:00
2025-12-03 11:32:59 +02:00
2024-05-23 07:54:59 -10:00
2025-12-22 11:24:00 +11:00
2026-01-14 09:47:50 -08:00
2023-08-09 13:00:25 +02:00
2025-07-28 14:46:04 +01:00
2026-02-03 14:10:49 -06:00
2025-07-03 13:22:54 +10:00
2025-02-24 05:38:17 +00:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-06-27 14:42:22 +04:00
2026-01-08 15:24:11 +04:00
2025-10-06 08:56:43 +00:00
2025-12-03 11:32:59 +02:00
2025-12-11 18:19:18 +00:00
2025-12-03 11:32:59 +02:00
2023-08-18 18:55:43 +00:00
2026-01-08 15:24:11 +04:00
2025-03-26 01:56:39 -05:00
2024-07-30 10:44:02 -06:00
2026-01-08 15:24:11 +04:00
2024-03-17 09:45:26 -05:00
2024-11-04 17:23:31 +01:00
2026-01-08 15:24:11 +04:00
2025-12-15 11:26:41 -06:00
2025-09-22 17:14:07 +04:00
2025-06-20 13:16:55 -06:00
2026-01-12 17:46:05 +00:00
2026-02-16 12:16:08 +11:00
2025-06-20 13:16:55 -06:00
2025-10-24 10:18:19 +00:00
2025-12-03 11:32:59 +02:00
2024-11-04 17:23:31 +01:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2025-10-23 14:24:54 +02:00
2026-01-08 15:24:11 +04:00
2024-03-17 09:45:26 -05:00
2026-02-09 14:20:57 +04:00
2026-02-12 13:40:47 -08:00
2026-01-22 08:12:15 -08:00
2026-01-08 15:24:11 +04:00
2026-01-16 15:45:33 +00:00
2026-01-16 15:45:33 +00:00
2024-03-15 13:16:36 +00:00
2024-03-15 13:16:36 +00:00
2024-11-18 14:09:22 +04:00
2026-01-08 15:24:11 +04:00
2026-02-09 09:56:33 +00:00
2023-07-20 12:05:39 +02:00
2026-02-09 09:56:33 +00:00
2023-07-20 12:05:39 +02:00
2026-02-09 09:56:33 +00:00
2026-01-30 13:24:06 +11:00
2026-02-03 14:10:49 -06:00
2025-03-26 10:36:53 +00:00
2025-03-26 10:36:53 +00:00
2026-01-12 15:16:59 +01:00
2026-01-12 15:16:59 +01:00
2025-09-22 17:14:07 +04:00
2026-01-20 10:28:52 +11:00
2026-01-20 10:28:52 +11:00
2025-11-28 08:33:50 +02:00
2025-11-28 08:33:50 +02:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2025-11-28 08:33:50 +02:00
2025-11-25 15:24:25 +00:00
2025-11-25 15:24:25 +00:00
2025-11-25 15:24:25 +00:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2025-12-03 11:32:59 +02:00
2026-02-13 14:21:31 +00:00
2026-02-02 15:50:09 +02:00
2026-02-13 14:21:31 +00:00
2026-02-13 14:21:31 +00:00
2026-02-13 14:21:31 +00:00
2025-11-25 15:24:25 +00:00
2025-11-25 15:24:25 +00:00
2025-11-25 15:24:25 +00:00
2026-02-13 14:21:31 +00:00
2026-02-13 14:21:31 +00:00
2024-07-25 16:07:53 -05:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2026-01-08 15:24:11 +04:00
2023-08-18 18:55:43 +00:00
2024-03-17 09:45:26 -05:00
2024-07-25 16:07:53 -05:00
2025-12-03 11:32:59 +02:00
2025-12-15 11:26:41 -06:00
2025-12-03 11:32:59 +02:00
2025-06-20 13:16:55 -06:00
2025-09-22 17:14:07 +04:00
2025-12-15 11:26:41 -06:00
2025-10-03 10:20:06 -05:00
2025-07-24 16:44:36 +01:00
2025-12-15 11:26:41 -06:00
2025-09-22 17:14:07 +04:00
2024-10-17 14:15:14 +05:00
2025-12-03 11:32:59 +02:00
2026-02-17 13:16:46 +00:00
2026-02-17 13:16:46 +00:00
2026-02-03 14:10:49 -06:00
2025-09-22 17:14:07 +04:00
2024-08-23 21:23:51 +00:00
2025-04-16 10:37:09 -06:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2025-04-15 18:30:20 -04:00
2025-09-22 17:14:07 +04:00
2025-05-12 11:45:24 -07:00
2025-12-03 11:32:59 +02:00
2025-04-15 18:30:20 -04:00
2023-10-10 11:14:20 +01:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-03-26 01:56:39 -05:00
2025-06-20 13:16:55 -06:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-02-12 12:14:56 +01:00
2026-02-12 12:14:56 +01:00
2026-02-12 12:14:56 +01:00
2026-02-12 12:14:56 +01:00
2024-11-18 21:10:01 +10:00
2024-11-18 14:09:22 +04:00
2026-01-08 15:24:11 +04:00
2024-07-09 13:23:11 -05:00
2025-09-26 11:20:25 +01:00