Skip to content

ref(api): Narrow request.user in API plumbing and org endpoints - #129422

Draft
gricha wants to merge 1 commit into
ref/sa-narrow-miscfrom
ref/sa-narrow-api-b
Draft

gricha wants to merge 1 commit into
ref/sa-narrow-miscfrom
ref/sa-narrow-api-b

Conversation

@gricha

@gricha gricha commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

api/base.py, api/bases/organization.py, api/decorators.py, the group-index helpers and 22 org/project endpoints read the caller through sentry.auth.principal: who-did-this columns, analytics and Seer context use acting_user_id(); "mine" lookups (recent searches, prompts, monitoring identities) use owned_by_acting_user(); personal writes, user-only attributes and NOT NULL actors use require_user().

Per-request paths: the 2FA check and the release cache key call require_user() only after checks a service account never passes (it has no member row; service-account auth is excluded), and primary_email_verification_required now answers a service account with 403 instead of an AttributeError.

  • A service account gets empty prompts and recent searches, and can save transaction thresholds; recent-search POST, weekly-report exclusions, agentic onboarding and service hooks are 403 user-required. New tests cover five of these.
  • Token callers get 401 instead of a 500 on recent-search POST and weekly-report exclusions.
  • Users and agents see no change.

Left: three features.batch_has(actor=request.user) calls (widening it reaches getsentry's handlers), _get_member, organization_releases serialize, prompts_activity PUT and organization_auth_tokens.

@gricha
gricha added this pull request to stack #129364 October 31, 2026 02:27
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

decision-model-linter

audit

src/sentry/api/endpoints/organization_auth_tokens.py

  • warn issuesOrRevokesTokenWithoutRecord = TRUE (0.75): Token changes should be logged with create_audit_entry for org tokens or capture_security_activity for personal tokens. This file creates, revokes, or rescopes a token, but neither call was found in it. Ignore this if a function the file calls already logs the change.

decision-model-linter: 90 calls on 30 files, 171,786 input tokens, $0.0072, model typesafe/jev-1.13-20260917

@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/sa-narrow-api-b branch from 6dbeab1 to 9491893 Compare November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
`api/base.py`, `api/bases/organization.py`, `api/decorators.py`, the group-index helpers and 22 org/project endpoints read the caller through `sentry.auth.principal`: who-did-this columns, analytics and Seer context use `acting_user_id()`; "mine" lookups (recent searches, prompts, monitoring identities) use `owned_by_acting_user()`; personal writes, user-only attributes and NOT NULL actors use `require_user()`.

Per-request paths: the 2FA check and the release cache key call `require_user()` only after checks a service account never passes (it has no member row; service-account auth is excluded), and `primary_email_verification_required` now answers a service account with 403 instead of an `AttributeError`.

- A service account gets empty prompts and recent searches, and can save transaction thresholds; recent-search POST, weekly-report exclusions, agentic onboarding and service hooks are 403 `user-required`. New tests cover five of these.
- Token callers get 401 instead of a 500 on recent-search POST and weekly-report exclusions.
- Users and agents see no change.

Left: three `features.batch_has(actor=request.user)` calls (widening it reaches getsentry's handlers), `_get_member`, `organization_releases` serialize, `prompts_activity` PUT and `organization_auth_tokens`.
@gricha
gricha force-pushed the ref/sa-narrow-api-b branch from 9491893 to 3326f75 Compare November 1, 2026 04:57
@sentry

sentry Bot commented Nov 1, 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

This branch has not been deployed

No deployments
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.

1 participant