Repository navigation
fix(auth)!: require a sign-in to manage API keys - #733
Merged
Merged
Conversation
A request authenticated with an API key could create another key with a later expiry, list the person's keys and revoke them. A key that leaked was therefore not bounded by its expiry: it could issue its own successor and remove the owner's other keys. The ApiKey policies now refuse every action except recording the key's own use to an actor signed in with a key, so the rule holds wherever keys are managed. The read is refused outright rather than filtered to nothing, and /api/auth/api_keys answers 403 with the reason instead of a 404 or an empty list. A key cannot revoke itself either; nothing relied on it. BREAKING CHANGE: POST, GET and DELETE on /api/auth/api_keys return 403 when authenticated with an API key. Sign in and send the JWT, or use the API keys page.
An administrator viewing huddlz as a person could create an API key for them on the API keys page. The creation was attributed in audit history, but the key kept working after the impersonation ended. Key creation is now refused for an actor carrying an impersonation, and the API keys page says so instead of offering Create key. Listing and revoking the person's keys still work, since neither outlasts the session.
A browser session keeps the viewed person's token and the id of the impersonation. When that id stopped resolving, the marking was dropped and the session carried on as an ordinary sign-in of the viewed person, held by the administrator, with nothing refused or attributed any more. Such a session is now nobody's sign-in. The next request revokes both saved tokens, clears the session and continues signed out; a page already open is sent to sign in when it next mounts, and that request ends the session.
Recording a key's use was allowed to the key's owner, so a request authenticated with one key could mark a sibling key of the same person as used, and so could a plain sign-in. The policy now compares the key the request was authenticated with, which is the only caller there is.
The refusal came from the resource, after the request had been validated, so a key that sent a blank name or a zero expiry was answered 422 and a malformed id 404. The three key-management endpoints now answer a request authenticated with an API key 403 before looking at what it sent. The ApiKey policies stay the rule; the controller no longer translates their error because no such request reaches them.
The API keys page took `validate` and `create` events in any state. With no form open, as when listing keys or viewing as someone, the event crashed the page; with a new key on show, a repeated submit made a second key. Both events now act only while the form is open.
The MCP guide and ADR-0012 said a key can do anything the JSON API allows. Both now name the exception: a key cannot create, list or revoke keys. The agent setup guide also stops offering "Create a key" while an administrator is viewing as someone, matching the API keys page.
…is ended Ending a session whose impersonation no longer resolves revoked both saved tokens. When the viewing had just been stopped in the same browser, a request already on its way with the old cookie then revoked the sign-in the stop had restored. The viewing's token is still revoked and the session emptied, but the administrator's token is only dropped, and a session with nobody loaded is left as it is.
…mes a viewing Ending a stale viewing rewrote the session, and a session that named a viewing with nobody loaded was turned away from every page, public ones included. A stale viewing now only has its token revoked, and with nobody loaded the visitor is simply signed out: public pages open, and signing in or out clears what is left.
Contributor
Author
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Managing API keys requires a sign-in. Owners can create, list and revoke keys from the API keys page or with a JWT from API sign-in. A request authenticated with an API key receives 403 for all three operations. The key continues to record its own use.
An administrator viewing as a member can review and revoke the member’s keys. The API keys page and agent setup guide show that key creation is unavailable during a viewing. The key creation form also ignores repeat submissions once the key is displayed.
Stopping a viewing, signing out and completing authentication now agree on which request closed it. When stop finishes first, the administrator keeps their restored sign-in. When authentication finishes first, a later stop cannot restore the previous identity. A viewing ended elsewhere continues as a signed-out visit, and the next browser request revokes its still-live viewing credential.
Evidence
Merge Danger
Door: Two-way. No schema migration is required.
Blast Radius: Authentication