Repository navigation
feat(auth): Add ServiceAccount and ServiceAccountProject models - #128049
Merged
Merged
Conversation
sentry-junior
Bot
force-pushed
the
feat/add-service-account-models
branch
from
October 19, 2026 17:18
02a0362 to
744982c
Compare
Contributor
Sentry Snapshot Testing
|
Contributor
|
This PR has a migration; here is the generated SQL for for --
-- Create model ServiceAccount
--
CREATE TABLE "service_accounts_serviceaccount" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "organization_id" bigint NOT NULL, "name" varchar(64) NOT NULL, "scope_list" text[] NOT NULL, "is_active" boolean DEFAULT true NOT NULL, "date_added" timestamp with time zone NOT NULL, "date_updated" timestamp with time zone NOT NULL, "created_by_id" bigint NULL);
--
-- Create model ServiceAccountProject
--
CREATE TABLE "service_accounts_serviceaccountproject" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NOT NULL, "project_id" bigint NOT NULL, "service_account_id" bigint NOT NULL);
--
-- Create constraint service_accounts_serviceaccount_org_name_unique on model serviceaccount
--
CREATE UNIQUE INDEX CONCURRENTLY "service_accounts_serviceaccount_org_name_unique" ON "service_accounts_serviceaccount" ("organization_id", "name");
ALTER TABLE "service_accounts_serviceaccount" ADD CONSTRAINT "service_accounts_serviceaccount_org_name_unique" UNIQUE USING INDEX "service_accounts_serviceaccount_org_name_unique";
--
-- Create constraint service_accounts_serviceaccountproject_unique on model serviceaccountproject
--
CREATE UNIQUE INDEX CONCURRENTLY "service_accounts_serviceaccountproject_unique" ON "service_accounts_serviceaccountproject" ("service_account_id", "project_id");
ALTER TABLE "service_accounts_serviceaccountproject" ADD CONSTRAINT "service_accounts_serviceaccountproject_unique" UNIQUE USING INDEX "service_accounts_serviceaccountproject_unique";
ALTER TABLE "service_accounts_serviceaccount" ADD CONSTRAINT "service_accounts_ser_created_by_id_07f80396_fk_auth_user" FOREIGN KEY ("created_by_id") REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "service_accounts_serviceaccount" VALIDATE CONSTRAINT "service_accounts_ser_created_by_id_07f80396_fk_auth_user";
CREATE INDEX CONCURRENTLY "service_accounts_serviceaccount_organization_id_c630fd27" ON "service_accounts_serviceaccount" ("organization_id");
CREATE INDEX CONCURRENTLY "service_accounts_serviceaccount_created_by_id_07f80396" ON "service_accounts_serviceaccount" ("created_by_id");
ALTER TABLE "service_accounts_serviceaccountproject" ADD CONSTRAINT "service_accounts_ser_service_account_id_d06c4b81_fk_service_a" FOREIGN KEY ("service_account_id") REFERENCES "service_accounts_serviceaccount" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "service_accounts_serviceaccountproject" VALIDATE CONSTRAINT "service_accounts_ser_service_account_id_d06c4b81_fk_service_a";
CREATE INDEX CONCURRENTLY "service_accounts_serviceaccountproject_project_id_db371335" ON "service_accounts_serviceaccountproject" ("project_id");
CREATE INDEX CONCURRENTLY "service_accounts_serviceac_service_account_id_d06c4b81" ON "service_accounts_serviceaccountproject" ("service_account_id"); |
sentry-junior
Bot
force-pushed
the
feat/add-service-account-models
branch
from
October 19, 2026 17:37
7dfb391 to
1ca261d
Compare
skaasten
marked this pull request as ready for review
October 19, 2026 17:48
wedamija
reviewed
Oct 19, 2026
wedamija
left a comment
Member
There was a problem hiding this comment.
Migration lgtm, I'll leave it to your team for final approval
sentry-junior
Bot
force-pushed
the
feat/add-service-account-models
branch
from
October 20, 2026 14:57
1ca261d to
d736278
Compare
skaasten
force-pushed
the
feat/add-service-account-models
branch
from
October 20, 2026 15:41
d736278 to
d79e54d
Compare
markstory
reviewed
Oct 20, 2026
Add the control-silo tables that will back the mocked service account APIs. ServiceAccount stores the org, name, scopes, active flag and creator. ServiceAccountProject stores the project IDs the API accepts, with a hybrid cloud foreign key so links are removed when a project is deleted. Cells won't keep a replica. They'll read accounts through a cached RPC, the same way they read users, so ServiceAccount is a ReplicatedControlModel with a new SERVICE_ACCOUNT_UPDATE outbox category that will clear that cache. Both models are relocatable with the organization, and user merges move created_by. Refs ENG-8829 Co-Authored-By: shaun.kaasten <[email protected]> Co-Authored-By: shaun.kaasten <[email protected]> Co-Authored-By: shaun.kaasten <[email protected]>
The outbox backfill reads outbox_replication.<table>.replication_version for every ReplicatedControlModel, so ServiceAccount needs its option registered like the other replicated models. Refs ENG-8829 Co-Authored-By: shaun.kaasten <[email protected]>
The exhaustive backup round-trip already checks that ServiceAccountProject.project_id is remapped on import, since hybrid cloud foreign keys get a ForeignKeyComparator. Refs ENG-8829 Co-Authored-By: shaun.kaasten <[email protected]>
ServiceAccount doesn't replicate state to cells, so it now uses ControlOutboxProducingModel with an explicit outbox instead of ReplicatedControlModel. ServiceAccountProject writes the same account outbox when links are added or removed, including the per-instance tombstone cascade after a project is deleted, so callers no longer have to remember to save the account to clear the cell's cached copy. Refs ENG-8829 Co-Authored-By: shaun.kaasten <[email protected]>
… app Following review, service accounts get their own Django app so models, endpoints and serializers can live together with their own migration history. The tables haven't shipped, so this replaces sentry migration 1231 with service_accounts 0001_initial and uses app-prefixed table and constraint names. The outbox replication options follow the new table names. Refs ENG-8829 Co-Authored-By: shaun.kaasten <[email protected]>
sentry-junior
Bot
force-pushed
the
feat/add-service-account-models
branch
from
October 20, 2026 17:38
41123fd to
f0b43c1
Compare
gricha
approved these changes
Oct 20, 2026
markstory
approved these changes
Oct 21, 2026
skaasten
added a commit
that referenced
this pull request
Oct 21, 2026
Step 3 of the service accounts database design: the cell reads service accounts through a cached RPC to control, the same way `ViewerContextAuthentication` reads users through `user_service.get_user()`. There is no cell replica table. - `service_account_service.get_service_account` (control) returns `RpcServiceAccount` with `scope_list`, `is_active` and the account's `ServiceAccountProject` IDs. - `service_account_service.get(service_account_id=...)` reads through the cell cache (`@back_with_silo_cache`) and is what callers should use. It doesn't check the org or `is_active`; callers (viewer-context and auth, in later PRs) check both against the request. - A `SERVICE_ACCOUNT_UPDATE` receiver in `receivers/outbox/control.py` clears the cached entry in the org's cell. `ServiceAccount` and `ServiceAccountProject` both write that outbox on save and delete, so changes to scopes, `is_active` and project links reach the next cell request without saving the account. - The service lives in `sentry.service_accounts.services`, next to the models, and that package is registered for RPC discovery. Stacked on #128049. Nothing calls the new service yet. <!-- junior-request-attribution:start --> via **shaun.kaasten**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CA89MBDQB%3A1792502266.308789 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA89MBDQB%3A1792502266.308789) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA89MBDQB%3A1792502266.308789/?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]>
2 tasks done
sentry-junior Bot
added a commit
that referenced
this pull request
Oct 23, 2026
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 Bot
added a commit
that referenced
this pull request
Oct 23, 2026
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]> Co-Authored-By: Shaun Kaasten <[email protected]>
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 adds a new
sentry.service_accountsDjango 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.ServiceAccountholds the org, the name (unique per org, at most 64 characters),scope_list,is_activeandcreated_by. Scopes are validated againstSENTRY_SCOPESminus the OIDC scopes.ServiceAccountProjectholds theprojectIdsthe API accepts.project_idis aHybridCloudForeignKey, 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 forsentrymigration 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_UPDATEoutbox (organization scope) will clear that cache. Both models areControlOutboxProducingModels and write that outbox for the account:ServiceAccounton every change, andServiceAccountProjectwhen 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:
RelocationScope.Organization. They're in the exhaustive backup fixtures, whose round-trip tests also check thatproject_idis remapped to the imported project instead of being copied.User.merge_tonow movescreated_by. The user-merge coverage test requires this for every org-scoped model that referencesUser.Refs ENG-8829
via shaun.kaasten.
--
View Junior Session [Sentry]