Repository navigation
Refuse API keys when creating API keys - #2055
Merged
Merged
Conversation
Creating a key through the API needs a sign-in: a browser session, Basic auth, or an OAuth token from mix hex.user auth. An API key, or a token exchanged for one through the client credentials grant, gets a 403. Every key then comes from a sign-in, so revoking a key leaves behind no key it created. The docs for mix hex.organization key generate now say to sign in first.
The refusal ran after authorize, so a token exchanged for an API key got the OAuth TOTP challenge first and the caller was asked for a code before being told keys can't create keys. It now runs first. The message points to the dashboard for personal keys, and to the organization's dashboard or mix hex.organization key ORG generate for organization keys, since mix hex.user auth creates no keys.
ericmj
added a commit
to hexpm/hex
that referenced
this pull request
Oct 16, 2026
* Create keys in integration tests from a two-factor sign-in hexpm refuses an API key, or a token exchanged for one, when creating API keys (hexpm/hexpm#2055). The tests that created keys with a key now sign in the way mix hex.user auth does: a user with two-factor authentication and an OAuth token, with the TOTP code that OAuth writes need. They pass against hexpm with and without that change. * Sign in before organization auth in the deauth test The test authorized the organization with a stored key, which hexpm#2055 refuses for key creation, and then passed because deauth leaves no repo either way. It now signs in with two-factor and checks that auth added the repo before deauth removes it.
ericmj
added a commit
to hexpm/hex
that referenced
this pull request
Oct 16, 2026
hexpm refuses an API key, or a token exchanged for one, when creating API keys (hexpm/hexpm#2055). The tests that created keys with a key now sign in the way mix hex.user auth does: a user with two-factor authentication and an OAuth token, with the TOTP code that OAuth writes need. They pass against hexpm with and without that change.
ericmj
added a commit
to hexpm/hex
that referenced
this pull request
Oct 16, 2026
hexpm refuses an API key, or a token exchanged for one, when creating API keys (hexpm/hexpm#2055). The tests that created keys with a key now sign in the way mix hex.user auth does: a user with two-factor authentication and an OAuth token, with the TOTP code that OAuth writes need. They pass against hexpm with and without that change.
# Conflicts: # test/hexpm_web/controllers/api/key_controller_test.exs
# Conflicts: # lib/hexpm_web/controllers/api/key_controller.ex # lib/hexpm_web/templates/docs/publish.html.md
The refusal ran after fetch_organization, so a key creating keys in an organization that exists got a 403 naming it and one that doesn't exist got a 404. Every other answer on these routes treats the two the same. It runs first now and takes the name from the path.
KeyGrantor only sees an OAuth token or no credential now that a key can't create keys, so its clauses for a key never ran. Its refusal names the authenticating token instead of a key.
ericmj
marked this pull request as ready for review
November 1, 2026 14:09
ericmj
added a commit
that referenced
this pull request
Nov 4, 2026
A key, or a token exchanged for one, can no longer revoke keys, the same way it can't create them since #2055. A leaked key with keys or api:write could revoke every other key of its account or organization. Keys can't hold the keys permission any more: the key form doesn't offer it, write members asking for api:write get api:read and publish, and creating a key with it fails validation. The keys OAuth scope keeps working for signed-in users.
ericmj
added a commit
that referenced
this pull request
Nov 4, 2026
* Describe the Keys permission as revoking keys A key can't create other keys since #2055, but the Generate New Key form still described the Keys permission as creating keys with a subset of the key's permissions. The test that read-only organization members can't revoke keys matched any "Revoke key" text on the page, which the new description contains, so it now looks for the revoke button's aria-label. * Only let a signed-in person revoke keys A key, or a token exchanged for one, can no longer revoke keys, the same way it can't create them since #2055. A leaked key with keys or api:write could revoke every other key of its account or organization. Keys can't hold the keys permission any more: the key form doesn't offer it, write members asking for api:write get api:read and publish, and creating a key with it fails validation. The keys OAuth scope keeps working for signed-in users.
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.
Creating a key through
POST /api/keysorPOST /api/orgs/:organization/keysneeds a sign-in: a browser session, Basic auth, or an OAuth token frommix hex.user auth. An API key, or a token exchanged for one through the client credentials grant, gets a 403 that points to the dashboard for personal keys, and to the organization's dashboard ormix hex.organization key ORG generatefor organization keys. The refusal runs before the organization is looked up, so it's the same for an organization that exists and one that doesn't. Every key then comes from a sign-in, so revoking a key leaves behind no key it created. Creating keys on the dashboard is unchanged.The
keyspermission on a key, or on a token exchanged for one, now only allows revoking keys, and /docs/keys says so.KeyGrantoronly sees an OAuth token or no credential, so its clauses for a key credential are gone and its refusal names the authenticating token.Organization keys can't create keys any more, and neither can
mix hex.organization key ORG generatewhen it runs withHEX_API_KEY. Hex 2.3 and earlier create the read and repositories keys ofmix hex.user authwith the write key they created a moment before, and that flow stops working when Basic auth turns off on 2026-11-01, so this deploys after that date. The docs formix hex.organization key generatenow say to sign in first.