Repository navigation
feat(service-accounts): Authenticate requests with service account tokens - #130914
Merged
Merged
Conversation
sentry-junior
Bot
force-pushed
the
feat/service-account-token-auth
branch
from
November 12, 2026 14:43
1fab28a to
734b97c
Compare
sentry-junior
Bot
force-pushed
the
feat/service-account-token-auth
branch
from
November 12, 2026 15:34
92b6ac7 to
4158fe0
Compare
skaasten
force-pushed
the
feat/service-account-token-auth
branch
from
November 12, 2026 17:28
4158fe0 to
a60f158
Compare
…kens Add ServiceAccountTokenAuthentication for sntrym_ bearer tokens and register it next to OrgAuthTokenAuthentication in the API and the auth middleware. It looks up the active token by hash (the cell replica in the cell, the token in control), rejects revoked and expired tokens, and resolves the account with resolve_service_account, so it applies the same active, org and feature checks as viewer-context auth. The credential is the same service_account AuthenticatedToken, with entity_id set to the account, so access, rate limits and attribution work unchanged. Its scopes are the token's scopes intersected with the account's current scopes. A token used on another organization's URL fails with a 401.
…owser login The auth middleware leaves Django's request.user anonymous for these tokens, so login_required views redirect to the login page.
skaasten
force-pushed
the
feat/service-account-token-auth
branch
from
November 13, 2026 14:34
a60f158 to
860210b
Compare
…ead of first() first() adds an ORDER BY to a lookup that matches at most one row, which can lead to poor query plans. Match the org auth token lookup and use get(). Co-Authored-By: Shaun Kaasten <900809+skaasten@users.noreply.github.com>
michelletran-sentry
approved these changes
Nov 13, 2026
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.
Allows service account access tokens to be authenticated
Stacked on #130679.
Adds
ServiceAccountTokenAuthentication, which acceptssntrym_bearer tokens. It's registered right afterOrgAuthTokenAuthentication, both in the API's default authenticators and in the auth middleware (so rate limits key on the same identity the endpoint sees).How a token becomes a request credential:
ServiceAccountTokenReplicain the cell,ServiceAccountTokenin control. Revoked (date_deactivatedset) and expired tokens return 401.resolve_service_account. That's the same helper the viewer-context path uses, so it applies the same checks: the account is active and in the token's org, and the org hasorganizations:service-accounts. We reuse that flag instead of adding a separate token flag, since service accounts aren't available outside the internal org yet.service_accountAuthenticatedTokenas viewer-context auth, withentity_idset to the account ID. Access, project reach,service_account:<id>rate limits and creator attribution work without changes.organization_id_or_slug, a token for another org fails with a 401. Access would deny it anyway, but this gives a clear error and covers endpoints that never build access.Not in this PR: throttled
date_last_usedupdates, which need a cell-to-control RPC, the management endpoints for creating and revoking tokens, and the token column in the service-account auth matrix.via @skaasten.
--
View Session [Sentry]