fix(coderd/httpmw): honor fixed lifetime for CLI API tokens#26376
Merged
Conversation
API key validation applied a sliding-window expiry refresh to every key type. Programmatic API tokens (created via `coder tokens create`, LoginType token) had their expires_at extended to now+lifetime on each authenticated request, so a token used within its lifetime window never expired. Restrict the refresh to interactive login sessions (password, OIDC, GitHub). Programmatic tokens now honor their fixed expires_at.
sreya
approved these changes
Jun 15, 2026
zedkipp
approved these changes
Jun 15, 2026
Contributor
Author
|
For changelog / docs (follow-up): when this ships, please surface the following breaking-change callout in the release notes and the token management docs. Warning Behavior change: API tokens now honor their fixed 🤖 Generated by Coder Agents on behalf of @jdomeracki-coder. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
API key validation applied a sliding-window expiry refresh to every key type. Programmatic API tokens (created via
coder tokens create, login typetoken) had theirexpires_atextended tonow + lifetimeon 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
--lifetimeis 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 whenkey.LoginType == database.LoginTypeToken.coderd/httpmw/apikey_test.go: regression test asserting a token's expiry is not extended on use.Notes
Validation
go build ./coderd/httpmw/...go test ./coderd/httpmw/ -run TestAPIKey -count=1(all pass, including the newTokenNoExpiryRefreshand the interactiveValidUpdateExpiry)golangci-lint run ./coderd/httpmw/(clean)🤖 Generated by Coder Agents on behalf of @jdomeracki-coder.