Skip to content

fix(coderd/httpmw): honor fixed lifetime for CLI API tokens (#26376)#26383

Merged
f0ssel merged 1 commit into
release/2.33from
backport/26376-to-2.33
Jun 17, 2026
Merged

fix(coderd/httpmw): honor fixed lifetime for CLI API tokens (#26376)#26383
f0ssel merged 1 commit into
release/2.33from
backport/26376-to-2.33

Conversation

@github-actions

Copy link
Copy Markdown

Backport of #26376

Original PR: #26376 — fix(coderd/httpmw): honor fixed lifetime for CLI API tokens
Merge commit: 450ddff
Requested by: @jdomeracki-coder

## What

API key validation applied a sliding-window expiry refresh to every key
type. Programmatic API tokens (created via `coder tokens create`, login
type `token`) had their `expires_at` extended to `now + lifetime` on
each authenticated request (with a ~1h debounce), so a token used within
its lifetime window never actually expired.

This restricts the sliding-window refresh to interactive login sessions
(password / OIDC / GitHub). Programmatic tokens now honor their fixed
`expires_at`.

## Why

A finite token `--lifetime` is expected to be a hard expiry. Silently
extending it on use defeats that expectation and prevents rotation of
long-lived automation credentials.

## Changes

- `coderd/httpmw/apikey.go`: skip the expiry refresh when `key.LoginType
== database.LoginTypeToken`.
- `coderd/httpmw/apikey_test.go`: regression test asserting a token's
expiry is not extended on use.

## Notes

- Interactive sessions are unaffected (they still slide while active).
- Tokens already extended are not retroactively shortened; this prevents
future extension.

<details>
<summary>Validation</summary>

- `go build ./coderd/httpmw/...`
- `go test ./coderd/httpmw/ -run TestAPIKey -count=1` (all pass,
including the new `TokenNoExpiryRefresh` and the interactive
`ValidUpdateExpiry`)
- `golangci-lint run ./coderd/httpmw/` (clean)
- Confirmed the new test fails without the production change and passes
with it.
</details>

---
🤖 Generated by Coder Agents on behalf of @jdomeracki-coder.

(cherry picked from commit 450ddff)
@f0ssel f0ssel merged commit e330564 into release/2.33 Jun 17, 2026
29 checks passed
@f0ssel f0ssel deleted the backport/26376-to-2.33 branch June 17, 2026 15:52
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants