Skip to content

fix(service-accounts): Refuse service account tokens when starting Seer runs - #131251

Merged
skaasten merged 3 commits into
masterfrom
shaunkaasten/eng-9057-block-service-accounts-from-starting
Nov 17, 2026
Merged

skaasten merged 3 commits into
masterfrom
shaunkaasten/eng-9057-block-service-accounts-from-starting

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

These 2 seer endpoints create viewer contexts based on the service account scopes, not the service account token (which isn't passed in here), so we should block them from service account token auth until we've fixed viewer context to be limited to the token scopes (follow-up).


Starting Autofix or a Seer Agent chat hands Seer a signed viewer context through get_proxy_headers(). That context names the service account but not the token, so Seer's callbacks get the account's full current scopes. A token limited to event:write could start a run whose callbacks act with everything the account holds. Since #130507 tokens can be created, so this path is now reachable for orgs with organizations:service-accounts.

With this change, POST to GroupAutofixEndpoint and OrganizationSeerAgentChatEndpoint returns 403 user-required when the request was authenticated by ServiceAccountTokenAuthentication. The check lives in a shared refuse_service_account_token() helper in seer/endpoints/utils.py.

What stays the same:

  • Service-account viewer contexts still work. Seer's own runs use them. They don't widen anything, because the callback's identity is the same account that made the request.
  • GET is unchanged (reading run state).
  • Users, agents, org auth tokens and API keys are unaffected. I didn't use requires_user / require_user: they would also turn away userless API keys (401), and Seer's own service-account viewer contexts (403).

Open decision. This closes the gap at the two endpoints we know about. Any new endpoint that starts Seer work with proxy headers needs the same call. The broader fix is to carry the token ID or its narrowed scopes in the viewer context and intersect against them on callback. That covers user tokens too, which widen the same way today, so it's left for a follow-up.

Fixes ENG-9057

via @skaasten.

--

View Session [Sentry]

…er runs

Starting Autofix or a Seer Agent chat hands Seer a viewer context that
names the service account, not the token. Seer's callbacks then get the
account's full scopes, so a narrow token could start a run that acts
with more than it holds.

POST to GroupAutofixEndpoint and OrganizationSeerAgentChatEndpoint now
returns 403 user-required for a service account token. Service-account
viewer contexts, which Seer itself uses, keep working, and GET is
unchanged.

Fixes ENG-9057

Co-Authored-By: Shaun Kaasten <[email protected]>
@linear-code

linear-code Bot commented Nov 16, 2026

Copy link
Copy Markdown

ENG-9057

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 16, 2026
@skaasten
skaasten marked this pull request as ready for review November 16, 2026 15:34
@skaasten
skaasten requested a review from a team as a code owner November 16, 2026 15:34
@sentry-junior
sentry-junior Bot requested a review from skaasten November 16, 2026 15:34
…57-block-service-accounts-from-starting

# Conflicts:
#	src/sentry/seer/endpoints/utils.py
…57-block-service-accounts-from-starting

# Conflicts:
#	src/sentry/seer/endpoints/group_ai_autofix.py
@skaasten
skaasten merged commit 58b6976 into master Nov 17, 2026
82 checks passed
@skaasten
skaasten deleted the shaunkaasten/eng-9057-block-service-accounts-from-starting branch November 17, 2026 15:09
skaasten added a commit that referenced this pull request Nov 17, 2026
…h matrix (#131473)

Re-lands #131441, which was reverted in
c7135e47542 because it collided with
#131251.

Service accounts can authenticate with a bearer token
(#130914) as well as a viewer context. Before GA, both
need to follow the same authorization rules. This adds a
`service_account_token` column next to the viewer-context column in the
service account auth matrix, so every service account row also runs with
a bearer token for the same account.

#131251 makes POST to `GroupAutofixEndpoint` return 403 `user-required`
for service account tokens. So the token is refused there, but the
viewer context isn't:
- `SERVICE_ACCOUNT_TOKEN_USER_REQUIRED` lists rows that refuse only the
token. Right now that's only `GroupAutofix_post`.
- `_assert_service_account_outcome` takes the authentication. For those
rows it expects `user-required` with token auth, and the viewer context
still has to match the oracle.
- `OrganizationSeerAgentChatEndpoint` refuses tokens the same way, but
it isn't in the public matrix, so it isn't listed.

Test-only change.

Refs ENG-9059

<!-- junior-request-attribution:start -->
via @skaasten.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!--
junior-conversation-id:agent-dispatch%3Adispatch_1a2399a01a018d2d2e0b438397a5e72d
-->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_1a2399a01a018d2d2e0b438397a5e72d)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_1a2399a01a018d2d2e0b438397a5e72d/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Shaun Kaasten <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 3e8db9a5 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants