Repository navigation
feat(service-accounts): Generate service account tokens and scan for leaks - #130456
Merged
Merged
Conversation
skaasten
reviewed
Nov 9, 2026
michelletran-sentry
approved these changes
Nov 9, 2026
michelletran-sentry
left a comment
Contributor
There was a problem hiding this comment.
Generally LGTM!
…leaks Add a sntrym_ token type that reuses the org auth token layout. A token carries its org and region, and only its SHA-256 hash and last four characters are stored. User auth token authentication skips sntrym_ tokens. The GitHub secret-scanning webhook notifies org owners when an active service account token leaks. Co-Authored-By: Shaun Kaasten <[email protected]>
skaasten
force-pushed
the
feat/service-account-token-generation
branch
from
November 10, 2026 14:55
6f916c8 to
bd255bc
Compare
skaasten
pushed a commit
that referenced
this pull request
Nov 10, 2026
#130483) Adds a new endpoint for listing service account tokens, gated by service account feature flag ------ Adds `GET /organizations/{org}/service-accounts/{id}/tokens/`. This is the first of the small token endpoint PRs, one per endpoint. It's stacked on #130456, which adds token generation: 1. **List tokens (this PR)** 2. Create a token: #130507 3. Revoke a token: #130508 The endpoint runs in control, is private, and is gated on `organizations:service-accounts` like the other service account endpoints. It needs `service_account:read`. It returns the account's active tokens, newest first: `id`, `name`, `scopes`, `tokenLastCharacters`, `dateCreated`, `dateLastUsed`, `dateExpires`. Revoked tokens aren't listed, and the response never includes a token's value. Pagination works the same way as the service account list. The account in the URL must be active and in the URL's org, otherwise it returns 404. Only a person signed in as themselves can call it. A service account gets 403 `user-required` (`requires_user`). The account lookup from the details endpoint moved into a shared `ServiceAccountScopedEndpointBase`. The details endpoint behaves the same. The new URL is added to `static/app/utils/api/knownSentryApiUrls.generated.ts`, so the frontend PR (#130485) can type-check against it. <!-- junior-request-attribution:start --> via @skaasten. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CA89MBDQB%3A1793911581.772709 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA89MBDQB%3A1793911581.772709) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA89MBDQB%3A1793911581.772709/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.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.
This is PR 2 of the service account access tokens plan. It adds the token format and leak detection. Nothing creates or authenticates these tokens yet.
AuthTokenType.SERVICE_ACCOUNT = "sntrym_". Themis for machine, becausesis already used by org auth tokens.sentry.service_accounts.tokensgenerates and parses tokens in the org auth token layout (prefix + base64({iat, url, region_url, org}) + "_" + secret). To support that,orgauthtoken_token.generate_tokenandparse_tokentake an optionalprefix, and the default leaves org tokens unchanged.stored_token_fields()returns only the SHA-256 hash and the last 4 characters. The plaintext isn't stored on any object, and the hash isrepr=False.UserAuthTokenAuthentication.accepts_authskipssntrym_, the same way it skipssntrys_. Until a service account authenticator lands, these tokens authenticate as nothing.sntrym_token, it looks up the hash in activeServiceAccountTokenrows (date_deactivatednull) and emails the org owners. It only notifies and never revokes. Revoked or unknown tokens are labeledfalse_positive.No migration: the
ApiToken.token_typechoices change doesn't produce one (makemigrations --checkreports no changes).Open items and deviations:
sntrym_with GitHub's secret scanning partner program is a manual step outside this PR.Checks run:
prekon the changed files, mypy (SENTRY_MYPY_PRE_PUSH=1 … --stage pre-push),makemigrations --check, and pytest ontests/sentry/service_accounts/test_tokens.py,tests/sentry/utils/security/test_orgauthtoken_token.py,tests/sentry/api/endpoints/secret_scanning/test_github.py,tests/sentry/api/test_authentication.pyandtests/sentry/service_accounts/test_models.py(167 passed).via @skaasten.
--
View Session [Sentry]