feat(api-keys): allow organizations to create API keys#350
Merged
Conversation
Owners and admins of an organization can now create and revoke API keys on the org level, from a new "API Keys" tab. Organization keys are gated on the org's own plan (Top Secret Service is the only org plan with apiAccess) and are restricted to the org's white-label domain: requests must send X-Host matching a white-label site owned by that organization, otherwise they are rejected. Limits are resolved from the organization's tier rather than the creator's, so a key keeps working as configured if the creator downgrades or leaves the org. Keys carry the creator in userId, so secrets created via an org key stay attributed to a person; personal key queries now filter on a null organizationId so org keys don't leak onto the user's own API page. Also fixes two pre-existing bugs in the secrets endpoint that this work touched: revoked keys kept working until the nightly cron deleted the row (the lookup never filtered `revoked`), and an unknown X-Host threw on `.id` of undefined instead of returning a 400. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The five org tabs need more width than a phone viewport, so the bar pushed the whole page ~75px wider than the screen at 375px and wrapped labels onto two lines. Scroll the bar horizontally instead and stop the tabs shrinking. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Owners and admins of an organization can now create and revoke API keys on the org level, from a new API Keys tab (sits next to White-label, same owner/admin gate).
How org keys differ from personal keys
Top Secret Serviceis the only org plan withapiAccess, soSecret Serviceorgs see an upgrade teaser.X-Hostmatching a white-label site owned by that org. NoX-Host, the original hostname, or another org's domain are all rejected. With the npm client this is thehostoption — note org keys will not work with the client's defaulthost(scrt.link), which is intentional.userIdstill holds the creator, so secrets made via an org key stay attributed to a person. Personal key queries filter on a nullorganizationIdso org keys don't leak onto the user's own API page.Max 5 keys per org. Any owner/admin can revoke any org key, not just their own.
Drive-by fixes
Two pre-existing bugs in
api/v1/secretsthat this work touched:revoked.X-Hostthrew on.idofundefinedinstead of returning a 400.Schema
Adds
api_key.organization_id(nullable FK →organization,on delete cascade). Needsdb:push/ a migration on deploy.Verification
Exercised against a real org key on a Top Secret Service org with a white-label domain:
X-HostX-Host: localhostAlso drove the UI: create → key listed → revoke →
revoked = true, withorganizationIdcorrectly flowing through both actions. Test data cleaned up.Known limitation
Orgs whose white-label site predates the
organizationIdFK (site linked to a user, not the org) can't use org keys — the endpoint requires the site to be org-owned, and loosening that would defeat the restriction. The white-label page has a legacy fallback for these; a one-off backfill ofwhite_label_site.organization_idis the fix rather than weakening the check.🤖 Generated with Claude Code