Skip to content

ref(typing): Let shared helpers take a service account - #129413

Merged
gricha merged 1 commit into
masterfrom
ref/typing-shared-principal
Nov 3, 2026
Merged

gricha merged 1 commit into
masterfrom
ref/typing-shared-principal

Conversation

@gricha

@gricha gricha commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

The helpers that endpoints hand request.user to now take a RequestPrincipal: feature gates (get_excluded_detector_types, has_investigations_access, should_serve_action_log_activity), Seer agent access (SeerAgentClient, has_seer_agent_access_with_detail, collect_user_org_context, commit_author_for_user), is_demo_user, has_staff_option, TeamManager.get_for_user and the group activity serializers.

  • Most only pass the caller on to features.has() or serialize(), or already check has_user(): type-only.
  • SeerAgentClient reads the user id once through acting_user_id() instead of six hasattr(self.user, "id") checks. is_demo_user, collect_user_org_context and commit_author_for_user use acting_user_id() / has_user().

Users, agents and token callers get the same values as before. A service account now gets no user (no user_id on its Seer runs, org context without personal teams) instead of a ServiceAccountId that 403s when used as an int.

Without it, #129402's mypy check would flag 14 more files.

@gricha
gricha added this pull request to stack #129364 October 31, 2026 01:30
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2026
@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/typing-shared-principal branch from e468a0c to 6365812 Compare November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
gricha added a commit that referenced this pull request Nov 1, 2026
The SeerAgentClient change from #129413: read the caller's user id with
acting_user_id instead of request.user.id, so a service account gets None
instead of a 403 from the ServiceAccountId guard.
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 6365812 to 246502d Compare November 2, 2026 19:55
@gricha
gricha marked this pull request as ready for review November 2, 2026 20:06
@gricha
gricha requested review from a team as code owners November 2, 2026 20:06
@gricha
gricha requested review from azulus, cvxluo and skaasten November 2, 2026 20:25
@gricha
gricha removed this pull request from stack #129440 November 2, 2026 21:45
@gricha
gricha added this pull request to stack #129572 November 2, 2026 21:45
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 246502d to 1e83cd4 Compare November 2, 2026 22:08
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 1e83cd4 to 955b2bd Compare November 2, 2026 22:36
@sentry

sentry Bot commented Nov 2, 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 780 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

@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.

Comment thread src/sentry/demo_mode/utils.py Resolved
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 955b2bd to 965babd Compare November 2, 2026 23:08
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 965babd to 246b3c3 Compare November 2, 2026 23:18

@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 246b3c3. Configure here.

):
qs = qs.filter(run__user_id=int(self.user.id))
if only_current_user and self._user_id is not None:
qs = qs.filter(run__user_id=self._user_id)

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.

Latest run skips user scoping

Medium Severity

latest_run with only_current_user now skips the user_id filter whenever _user_id is missing. A service account used to 403 on int(ServiceAccountId); it now receives the newest run for that source from any user, so it can continue someone else's Seer session.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 246b3c3. Configure here.

Base automatically changed from ref/typing-serialize-principal to master November 2, 2026 23:31
@gricha
gricha requested review from a team as code owners November 2, 2026 23:31
Feature gates, Seer agent access, demo/staff checks, team lookup and activity serializers now take a RequestPrincipal. Most only pass the caller to features.has() or serialize(), so this is type-only. The rest read the user id through acting_user_id()/has_user(): users, agents and token callers get the same values, and a service account gets no user instead of a ServiceAccountId.
@gricha
gricha force-pushed the ref/typing-shared-principal branch from 246b3c3 to 2164a65 Compare November 2, 2026 23:31
@gricha
gricha merged commit 5a9aeef into master Nov 3, 2026
97 checks passed
@gricha
gricha deleted the ref/typing-shared-principal branch November 3, 2026 00:27
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