Skip to content

feat(auth): Add mocked service account APIs - #127588

Merged
gricha merged 11 commits into
masterfrom
feat/service-account-api-mocks
Oct 16, 2026
Merged

gricha merged 11 commits into
masterfrom
feat/service-account-api-mocks

Conversation

@gricha

@gricha gricha commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Mocked service account APIs behind organizations:service-accounts. They return canned, fully typed responses and persist nothing, so Seer can build against the contract while the real implementation lands behind it.

  • Management (control silo): GET/POST /organizations/{org}/service-accounts/ and GET/PUT/DELETE .../{id}/. Reads need org:read, writes need org:admin. An optional projectIds limits project access when the org doesn't have open membership (ignored when it does, like team membership for people). You can only grant scopes and projects you have.
  • Viewer context (cell silo, Seer only): POST .../{id}/viewer-context/. This is the service account counterpart of agent token minting. Seer sends its org-only ViewerContext and gets back {viewerContext, expiresAt, scopes}. It lives in the cell because Seer only reaches its region's Sentry. Until the service account actor exists, it returns Seer's own ViewerContext.

owner is a placeholder until the owning team has a tag.

Design: Service accounts, build order.

Depends on #127716 (control silo URL patterns, frontend), which lands first.

@gricha
gricha requested a review from trevor-e October 15, 2026 18:18
@github-actions github-actions Bot added Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components labels Oct 15, 2026
@gricha
gricha marked this pull request as ready for review October 15, 2026 21:13
@gricha
gricha requested review from a team as code owners October 15, 2026 21:13
@linear-code

linear-code Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

AIML-3687

ENG-8829

@gricha
gricha force-pushed the feat/service-account-api-mocks branch from d7e97e0 to 3a2a0cd Compare October 16, 2026 16:36
@gricha
gricha changed the base branch from master to feat/service-account-control-silo-urls October 16, 2026 16:36
@gricha
gricha force-pushed the feat/service-account-api-mocks branch from 3a2a0cd to 8251400 Compare October 16, 2026 16:36

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Base automatically changed from feat/service-account-control-silo-urls to master October 16, 2026 16:44
gricha added a commit that referenced this pull request Oct 16, 2026
Lists the service account management routes in the control silo URL
patterns, so the frontend sends them to control.

Frontend half of #127588, split out because frontend and backend deploy
separately. It lands first: the patterns are harmless before the backend
routes exist, and #127588's `test_no_missing_urls` passes once this is
in.
@gricha
gricha force-pushed the feat/service-account-api-mocks branch from 8251400 to 42f1c5d Compare October 16, 2026 16:45
@sentry

sentry Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 630 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

@gricha
gricha changed the base branch from master to fix/backfill-watermark-test-order October 16, 2026 17:58
@gricha
gricha force-pushed the feat/service-account-api-mocks branch from b65aaab to 5634591 Compare October 16, 2026 17:58
@gricha
gricha added this pull request to stack #127830 October 16, 2026 18:11
Base automatically changed from fix/backfill-watermark-test-order to master October 16, 2026 18:36
gricha and others added 4 commits October 16, 2026 11:36
Add the service account management endpoints and the Seer-only viewer context endpoint behind organizations:service-accounts. They validate input and return canned data with the final response shape so Seer can integrate against the contract while the real implementation is built.
Split create and update request serializers so updates are optional in the schema, type the validated request data, and return real datetimes so the spec carries date-time formats.
Management endpoints live in the control silo with the service accounts. The Seer-only viewer context endpoint stays in the cell, since Seer only reaches its region's Sentry, and moves to its own module. Its response now mirrors agent token minting by including scopes, and OIDC scopes are no longer grantable.
Send the service account management routes to control in the API gateway and list them as control silo URLs. The Seer-only viewer context route stays on the cell.
@gricha
gricha force-pushed the feat/service-account-api-mocks branch from 5634591 to 023e40d Compare October 16, 2026 18:36
Service accounts take an optional projectIds list that limits project access when the organization doesn't have open membership, mirroring team membership for people. Callers can only grant projects in their organization that they can access.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a2b6fb0. Configure here.

RpcBackedAccess.accessible_project_ids only covers team projects, so owners and managers couldn't grant projects outside their teams.
@gricha
gricha merged commit c142da5 into master Oct 16, 2026
91 checks passed
@gricha
gricha deleted the feat/service-account-api-mocks branch October 16, 2026 22:44
RudraPatel2003 pushed a commit that referenced this pull request Oct 19, 2026
Lists the service account management routes in the control silo URL
patterns, so the frontend sends them to control.

Frontend half of #127588, split out because frontend and backend deploy
separately. It lands first: the patterns are harmless before the backend
routes exist, and #127588's `test_no_missing_urls` passes once this is
in.
RudraPatel2003 pushed a commit that referenced this pull request Oct 19, 2026
Mocked service account APIs behind `organizations:service-accounts`.
They return canned, fully typed responses and persist nothing, so Seer
can build against the contract while the real implementation lands
behind it.

- **Management** (control silo): `GET/POST
/organizations/{org}/service-accounts/` and `GET/PUT/DELETE .../{id}/`.
Reads need `org:read`, writes need `org:admin`. An optional `projectIds`
limits project access when the org doesn't have open membership (ignored
when it does, like team membership for people). You can only grant
scopes and projects you have.
- **Viewer context** (cell silo, Seer only): `POST
.../{id}/viewer-context/`. This is the service account counterpart of
agent token minting. Seer sends its org-only ViewerContext and gets back
`{viewerContext, expiresAt, scopes}`. It lives in the cell because Seer
only reaches its region's Sentry. Until the service account actor
exists, it returns Seer's own ViewerContext.

`owner` is a placeholder until the owning team has a tag.

Design: [Service
accounts](https://app.notion.com/p/sentry/Service-accounts-3ca8b10e4b5d81c88869fc35039c1cf8),
[build
order](https://app.notion.com/p/3f98b10e4b5d813596a8c966e8ff67db).

Depends on #127716 (control silo URL patterns, frontend), which lands
first.

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
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 added a commit that referenced this pull request Oct 23, 2026
…se (#128239)

Step 4 of the service accounts database design: the list, create,
retrieve, update and delete endpoints from #127588 now read and write
`ServiceAccount` and `ServiceAccountProject` instead of returning canned
data. The request and response contract doesn't change, because Seer
builds against it.

- Create stores the account with `created_by` and its projects in one
transaction. A duplicate name in the org returns 400, and the unique
constraint covers the race between the check and the insert.
- Update is partial. Sending `projectIds` replaces the set, and `null`
or `[]` clears it. Leaving it out keeps the set. The account is saved
even when only its projects change, because the account's outbox is what
clears the cell's cached copy.
- Delete is a hard delete. The project rows cascade, and the outbox
clears the cell cache.
- An account in another org returns 404.
- The existing rules stay as they were: callers can only grant scopes
they hold and projects they can access.
- New audit log events: `SERVICE_ACCOUNT_ADD` (223),
`SERVICE_ACCOUNT_EDIT` (224) and `SERVICE_ACCOUNT_REMOVE` (225).

Review notes:
- `Factories.create_service_account` lands here instead of in step 7,
because the endpoint tests need it.
- The viewer-context endpoint is still mocked. Its canned scopes moved
into that module and are replaced in step 5.

Stacked on #128182.

Refs ENG-8829

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

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CA89MBDQB%3A1792514692.009019 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA89MBDQB%3A1792514692.009019)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA89MBDQB%3A1792514692.009019/?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]>
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 Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants