Skip to content

feat(dashboards): Track service account and org token creators - #129219

Merged
DominikB2014 merged 3 commits into
masterfrom
feat/dashboard-non-user-creator
Oct 30, 2026
Merged

DominikB2014 merged 3 commits into
masterfrom
feat/dashboard-non-user-creator

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Dashboards record who created them with created_by_id = request.user.id. Service accounts and org auth tokens authenticate as AnonymousUser, so anything they create stores NULL and 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_id and created_by_org_auth_token_id to Dashboard, following the pattern Investigation and Notebook already use. Both are HybridCloudForeignKeys with SET_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) in sentry/api/helpers/creator.py fills the right column from request.user / request.auth. The dashboard create serializer uses it in place of request.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 added NOT VALID then validated. Not marked post-deployment.

Open questions for review:

  • OrganizationDashboardsEndpoint.post still returns 401 when request.user isn'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.
  • The API response doesn't expose the new creator columns yet (createdBy is still user-only).
  • On relocation import, the new FKs are remapped like 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]

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]>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1248_add_dashboard_non_user_creator.py

for 1248_add_dashboard_non_user_creator in sentry

--
-- 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
DominikB2014 marked this pull request as ready for review October 29, 2026 19:04
@DominikB2014
DominikB2014 requested review from a team as code owners October 29, 2026 19:04
@linear-code

linear-code Bot commented Oct 29, 2026

Copy link
Copy Markdown

ENG-8934

@DominikB2014
DominikB2014 requested a review from a team October 29, 2026 19:16
Comment thread src/sentry/api/helpers/creator.py Resolved
Service account and org auth token requests can carry a user, so checking
request.user first would attribute their dashboards to that user.
@DominikB2014
DominikB2014 merged commit 9ed1c8a into master Oct 30, 2026
97 of 98 checks passed
@DominikB2014
DominikB2014 deleted the feat/dashboard-non-user-creator branch October 30, 2026 13:56
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>
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.

3 participants