Repository navigation
feat(dashboards): Track service account and org token creators - #129219
Merged
Merged
Conversation
Service accounts and org auth tokens authenticate as an anonymous user, so dashboards they create stored a NULL created_by_id. Add created_by_service_account_id and created_by_org_auth_token_id columns, with a check that at most one creator column is set, and fill them from request.auth on create. Co-Authored-By: Dominik Buszowiecki <[email protected]>
Contributor
|
This PR has a migration; here is the generated SQL for for --
-- Add field created_by_org_auth_token_id to dashboard
--
ALTER TABLE "sentry_dashboard" ADD COLUMN "created_by_org_auth_token_id" bigint NULL;
--
-- Add field created_by_service_account_id to dashboard
--
ALTER TABLE "sentry_dashboard" ADD COLUMN "created_by_service_account_id" bigint NULL;
--
-- Create constraint sentry_dashboard_single_creator on model dashboard
--
ALTER TABLE "sentry_dashboard" ADD CONSTRAINT "sentry_dashboard_single_creator" CHECK ((("created_by_service_account_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_org_auth_token_id" IS NULL) OR ("created_by_id" IS NULL AND "created_by_service_account_id" IS NULL))) NOT VALID;
ALTER TABLE "sentry_dashboard" VALIDATE CONSTRAINT "sentry_dashboard_single_creator";
CREATE INDEX CONCURRENTLY "sentry_dashboard_created_by_org_auth_token_id_99851062" ON "sentry_dashboard" ("created_by_org_auth_token_id");
CREATE INDEX CONCURRENTLY "sentry_dashboard_created_by_service_account_id_776752e4" ON "sentry_dashboard" ("created_by_service_account_id"); |
…user-creator # Conflicts: # migrations_lockfile.txt Co-Authored-By: Dominik Buszowiecki <[email protected]>
DominikB2014
marked this pull request as ready for review
October 29, 2026 19:04
DominikB2014
approved these changes
Oct 29, 2026
edwardgou-sentry
approved these changes
Oct 29, 2026
skaasten
reviewed
Oct 29, 2026
Service account and org auth token requests can carry a user, so checking request.user first would attribute their dashboards to that user.
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. `DashboardRevision` read `user.id` for its creator, and `get_creator_reference` (#129219), which fills a new dashboard's creator columns, read `request.user.id` for the user one. Both now call `acting_user_id(...)`. `get_creator_reference` checks the credential first, so a service account is recorded in `created_by_service_account_id`; a revision it makes records no creator instead of a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. **Matrix:** fixes no service-account rows (known gaps stay at 69). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
DominikB2014
added a commit
that referenced
this pull request
Nov 3, 2026
…queries (#129549) Saved queries created by service accounts or org auth tokens currently get no author. Same approach as #129219 for dashboards. - Add nullable `created_by_service_account_id` / `created_by_org_auth_token_id` plus a single-creator check constraint to `DiscoverSavedQuery`, `ExploreSavedQuery` and `ExploreSavedFormula` - Create endpoints set the creator via `get_creator_reference(request)`; existing `created_by_id` is already `SET_NULL` on all three - Exhaustive relocation fixture now attributes the explore query and formula to a service account Fixes ENG-8935
DominikB2014
added a commit
that referenced
this pull request
Nov 16, 2026
…rt (#129571) Follow-up to #129219: org auth tokens are imported last during relocation, so a dashboard with `created_by_org_auth_token_id` can't be remapped and is silently dropped. - `Dashboard.normalize_before_relocation_import` clears `created_by_org_auth_token_id` so the dashboard imports without that creator. - Same override as #129550 (detectors/workflows). Refs ENG-8934
DominikB2014
added a commit
that referenced
this pull request
Nov 17, 2026
…130482) Stacked on #129550 (detectors). This adds service account and org auth tokens ids, so we can track whos created resources. Eventually this will help serve optional guardrails that will allow creators to modify/delete their own resources but not others. ### Generated description Workflows only recorded a user creator, so ones created by service accounts or org auth tokens had no author. - Add `created_by_service_account_id` / `created_by_org_auth_token_id` to `Workflow`, with an at-most-one-creator check constraint (same as #129219 for dashboards). - The workflow validator records the creator with `get_creator_reference(request)`. Refs ENG-8937
DominikB2014
added a commit
that referenced
this pull request
Nov 25, 2026
…129550) This adds service account and org auth tokens, so we can track whos created resources. Eventually this will help serve optional guardrails that will allow creators to modify/delete their own resources but not others. ## Generated description Detectors only recorded a user creator, so ones created by service accounts or org auth tokens had no author. - Add `created_by_service_account_id` / `created_by_org_auth_token_id` to `Detector`, with an at-most-one-creator check constraint (same as #129219 for dashboards). - The detector validator uses `get_creator_reference(request)`. The legacy `/monitors/` (`ensure_cron_detector`) and legacy uptime (`create_uptime_detector`) create paths now record the creator too. Workflows are in #132450. The two PRs are independent, but both add the next `workflow_engine` migration, so whichever merges second needs its migration renumbered. Fixes ENG-8937 <!-- junior-request-attribution:start --> via @DominikB2014. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CLH9SJT1N%3A1795553613.104619 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CLH9SJT1N%3A1795553613.104619) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CLH9SJT1N%3A1795553613.104619/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
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.
Dashboards record who created them with
created_by_id = request.user.id. Service accounts and org auth tokens authenticate asAnonymousUser, so anything they create storesNULLand can't be told apart from a deleted user or a prebuilt dashboard. This is groundwork for a setting that limits a service account or token to modifying only what it created.This adds
created_by_service_account_idandcreated_by_org_auth_token_idtoDashboard, following the patternInvestigationandNotebookalready use. Both areHybridCloudForeignKeys withSET_NULL. A new check constraint,sentry_dashboard_single_creator, allows at most one of the three creator columns to be set. "None set" stays valid, which covers prebuilt dashboards, rows created before this change, and creators that were later deleted.get_creator_reference(request)insentry/api/helpers/creator.pyfills the right column fromrequest.user/request.auth. The dashboard create serializer uses it in place ofrequest.user.id. It's a separate helper because the other shared resources (saved queries, detectors, workflows, …) need the same thing next. Users and internal-integration proxy users behave the same as before.Migration: two nullable columns, two
CREATE INDEX CONCURRENTLY, and the constraint addedNOT VALIDthen validated. Not marked post-deployment.Open questions for review:
OrganizationDashboardsEndpoint.poststill returns 401 whenrequest.userisn't authenticated, so service accounts and org tokens can't create dashboards through the API yet. The new columns won't be filled from real traffic until that gate is relaxed. I left the gate alone because it's an access change that belongs with the "only modify your own" setting.createdByis still user-only).created_by_id. A dashboard whose service account or token isn't in the export gets dropped, which matches the existing behavior for missing users.via @DominikB2014.
--
View Junior Session [Sentry]