Skip to content

ref(auth): Move service account endpoints into sentry.service_accounts - #128257

Closed
sentry-junior[bot] wants to merge 1 commit into
masterfrom
ref/move-service-account-endpoints
Closed

sentry-junior[bot] wants to merge 1 commit into
masterfrom
ref/move-service-account-endpoints

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Following review on #128049, service accounts are getting their own Django app, sentry.service_accounts, so models, endpoints and serializers live in one tree. This PR moves the mocked endpoints from #127588 and their tests into it:

  • src/sentry/api/endpoints/organization_service_accounts.py → src/sentry/service_accounts/endpoints/organization_service_accounts.py
  • src/sentry/api/endpoints/organization_service_account_viewer_context.py → src/sentry/service_accounts/endpoints/organization_service_account_viewer_context.py
  • Their tests move to tests/sentry/service_accounts/endpoints/.

Only module paths change. Routes, URL names, silo routing (controlsiloUrlPatterns, the apigw proxy rules), the feature flag and responses are all untouched, so the contract Seer builds against doesn't change. api/urls.py and the viewer-context endpoint's import of organization_service_accounts are the only edits.

This PR only adds a plain package. #128049 registers the app and adds the models and migration. Both PRs add an identical empty src/sentry/service_accounts/__init__.py, so they merge in either order.

Heads up: #128080 and #128111 edit organization_service_account_viewer_context.py and its test, so whichever lands second needs a rebase onto the new path.

Refs ENG-8829

via shaun.kaasten.

--

View Junior Session [Sentry]

Service accounts are getting their own Django app (#128049), so the
mocked management and viewer-context endpoints and their tests move
there too. Only module paths change: routes, URL names, silo routing
and responses are untouched.

Refs ENG-8829

Co-Authored-By: shaun.kaasten <[email protected]>
@sentry-junior
sentry-junior Bot requested review from a team as code owners October 20, 2026 17:40
@linear-code

linear-code Bot commented Oct 20, 2026

Copy link
Copy Markdown

ENG-8829

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 20, 2026
sentry-junior Bot added a commit that referenced this pull request Oct 20, 2026
sentry-junior Bot added a commit that referenced this pull request Oct 20, 2026
skaasten added a commit that referenced this pull request Oct 21, 2026
)

This adds a new `sentry.service_accounts` Django app with the two
control-silo tables that will back the mocked service account APIs from
#127588. Nothing reads or writes them yet. The cell lookup and real
endpoints come in follow-up PRs, and #128257 moves the mocked endpoints
into the same app.

- `ServiceAccount` holds the org, the name (unique per org, at most 64
characters), `scope_list`, `is_active` and `created_by`. Scopes are
validated against `SENTRY_SCOPES` minus the OIDC scopes.
- `ServiceAccountProject` holds the `projectIds` the API accepts.
`project_id` is a `HybridCloudForeignKey`, so the tombstone cascade
removes a link after its project is deleted.

The app gets its own migration history (`service_accounts/0001_initial`)
and app-prefixed tables (`service_accounts_serviceaccount`,
`service_accounts_serviceaccountproject`), so it no longer competes for
`sentry` migration numbers.

Cells won't keep a replica table. They'll read accounts through a cached
RPC to control, the same way they read users, and a
`SERVICE_ACCOUNT_UPDATE` outbox (organization scope) will clear that
cache. Both models are `ControlOutboxProducingModel`s and write that
outbox for the account: `ServiceAccount` on every change, and
`ServiceAccountProject` when links are added or removed. That includes
the manager's bulk methods and the per-instance tombstone cascade.
Nothing consumes the outbox yet; cache clearing lands with the RPC.

Review notes:
- Both models use `RelocationScope.Organization`. They're in the
exhaustive backup fixtures, whose round-trip tests also check that
`project_id` is remapped to the imported project instead of being
copied.
- `User.merge_to` now moves `created_by`. The user-merge coverage test
requires this for every org-scoped model that references `User`.
- The migration only creates new tables.

Refs ENG-8829

<!-- junior-request-attribution:start -->
via **shaun.kaasten**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0BAS2BU2TC%3A1792416182.597029 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0BAS2BU2TC%3A1792416182.597029)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0BAS2BU2TC%3A1792416182.597029/?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]>
@skaasten

Copy link
Copy Markdown
Contributor

These were already moved as part of #128239 - sorry for not closing earlier @markstory 🙏

@skaasten skaasten closed this Oct 26, 2026
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