service accounts: Phase 1 — backend CRUD and API key token exchange#2943
Open
GregorShear wants to merge 1 commit into
Open
service accounts: Phase 1 — backend CRUD and API key token exchange#2943GregorShear wants to merge 1 commit into
GregorShear wants to merge 1 commit into
Conversation
044861d to
899d324
Compare
GregorShear
commented
May 20, 2026
|
|
||
| .claude/* | ||
| !.claude/skills/ | ||
| mise.local.toml |
Contributor
Author
There was a problem hiding this comment.
not related to this PR but helping me not commit a file related to a parallel workstream...
899d324 to
3c9246f
Compare
b07c268 to
66e5620
Compare
0917cc1 to
312d85f
Compare
312d85f to
dc5e4cd
Compare
…h (and refresh tokens). also a new token exchange rest api
dc5e4cd to
dbbeaeb
Compare
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
internal.service_accountsandinternal.api_keystables for non-human identities that authenticate via API keys and are authorized through the existinguser_grants/role_grantssystemcreateServiceAccount,disableServiceAccount,enableServiceAccount,createApiKey,revokeApiKey) and a paginatedserviceAccountsquery, all gated on admin capability of the service account's prefixPOST /api/v1/auth/tokenREST endpoint that exchanges either aflow_sa_-prefixed API key or a refresh token for a short-lived access token, selected by thegrant_typefieldrefreshTokensquery,createRefreshToken/deleteRefreshTokenmutations), self-scoped to the authenticated userKey design decisions
auth.usersrows. All existing RLS policies, PostgREST authorization,user_roles()resolution, androle_grantstraversal work unchanged. This avoids putting the PostgREST→GraphQL migration on the critical path.user_grantsrow per service account. Created from the SA's stored prefix/capability. Disabling deletes the grant and all API keys; re-enabling restores the grant (but not the keys — new ones must be minted).generate_access_token. Theflow_sa_-prefixed key encodesbase64(key_id:secret); the endpoint decodes it, verifies the secret against a bcrypt hash using SQLcrypt()(no Rust bcrypt dependency), checks expiry anddisabled_at, then mints a 1-hourauthenticatedJWT directly. Theflow_sa_prefix routes the request and avoids collisions with refresh-token inputs.valid_forISO-8601 duration →now() + interval), not the sliding window used by refresh tokens.generate_access_tokenis unchanged. The refresh-token branch of/api/v1/auth/tokencalls the existinggenerate_access_token(refresh_token_id, secret)and passes its JSON result through. Existing callers are unaffected.Test plan
/api/v1/auth/token