Skip to content

ref(users): Narrow request.user in user, auth and relocation endpoints - #129418

Merged
gricha merged 1 commit into
ref/sa-narrow-appsfrom
ref/sa-narrow-users
Nov 3, 2026
Merged

gricha merged 1 commit into
ref/sa-narrow-appsfrom
ref/sa-narrow-users

Conversation

@gricha

@gricha gricha commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

User, auth, auth_v2 and relocation code reads the caller through sentry.auth.principal: person-only paths (passwords, 2FA, account merge, relocation creator) use require_user(), self checks in user permissions use is_acting_user(), "mine" lookups (relocation list) use owned_by_acting_user(), id:me adds the caller's id only when there is one, and logs use acting_user_id(). access.from_user(), normalize_valid_user() and SessionSerializer.serialize() take a service account (type-only). Session auth flags are skipped for a service account (has_user()), as they are for anonymous callers; before, setting them raised.

Also fixes the account on backup-code removal: when an admin removes another user's last authenticator, the recovery-code removal was logged under the admin's user id (account=request.user). It now records the owner, like the other removal calls; the actor stays the caller. test_superuser_removing_last_authenticator_logs_the_owner fails without it (assert [3, 2] == [2, 2]). Found by Warden.

Password change checks for a user before saving the new password, so a caller with no user (system auth) gets 401 without changing anything.

  • A service account gets an empty relocation list instead of 403 (new test); creating or retrying one is 403 user-required. User and auth_v2 endpoints are control-silo.
  • An API key deleting a user's last primary authenticator with backup codes gets 401 instead of a 500.
  • Users and agents see no change.

Left: user_authenticator_details.py passes the caller to capture_security_activity on a path API keys reach, so it stays on #129402's mypy allowlist.

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

sentry Bot commented Oct 31, 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

@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/sa-narrow-users branch from 1680b0e to 27d5e3b Compare November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/sa-narrow-users branch from 27d5e3b to f761ad0 Compare November 1, 2026 04:57
@gricha
gricha force-pushed the ref/sa-narrow-users branch 2 times, most recently from 1d5622f to 9154896 Compare November 2, 2026 20:14
@gricha
gricha force-pushed the ref/sa-narrow-users branch 3 times, most recently from 9c5f789 to e6bd2e1 Compare November 2, 2026 20:35
@gricha
gricha marked this pull request as ready for review November 2, 2026 20:57
@gricha
gricha requested review from azulus and skaasten November 2, 2026 20:57
@gricha
gricha requested review from a team as code owners November 2, 2026 20:57
@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/sa-narrow-users branch from e6bd2e1 to d31da16 Compare November 2, 2026 22:08
@gricha
gricha force-pushed the ref/sa-narrow-users branch 2 times, most recently from 0c74149 to 828069c Compare November 2, 2026 23:08
@gricha
gricha force-pushed the ref/sa-narrow-users branch 2 times, most recently from 7fa9fa4 to ef4805a Compare November 2, 2026 23:31
@gricha
gricha requested a review from cvxluo November 2, 2026 23:35
@gricha
gricha force-pushed the ref/sa-narrow-users branch 3 times, most recently from 80a5541 to eb1401f Compare November 3, 2026 04:03
@gricha
gricha force-pushed the ref/sa-narrow-users branch from eb1401f to 96e6f45 Compare November 3, 2026 04:41
@gricha
gricha removed this pull request from stack #129572 November 3, 2026 06:52
@gricha
gricha added this pull request to stack #129650 November 3, 2026 06:52

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

lgtm though prob want a security review for this one

gricha commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

good point, i'll see if I can get Michelle's eye on it!

@gricha
gricha force-pushed the ref/sa-narrow-users branch from 96e6f45 to 38ace18 Compare November 3, 2026 19:53
@gricha
gricha removed this pull request from stack #129650 November 3, 2026 19:53
@gricha
gricha added this pull request to stack #129747 November 3, 2026 19:54
@gricha
gricha force-pushed the ref/sa-narrow-users branch from 38ace18 to db4d84f Compare November 3, 2026 20:09
User, auth, auth_v2 and relocation code reads the caller through `sentry.auth.principal`: person-only paths (passwords, 2FA, account merge, relocation creator) use `require_user()`, self checks in user permissions use `is_acting_user()`, "mine" lookups (relocation list, `id:me`) use `owned_by_acting_user()`, and logs use `acting_user_id()`. `access.from_user()`, `normalize_valid_user()` and `SessionSerializer.serialize()` take a service account (type-only).

- A service account gets an empty relocation list instead of 403 (new test); creating or retrying one is 403 `user-required`. User and auth_v2 endpoints are control-silo.
- An API key deleting a user's last primary authenticator with backup codes gets 401 instead of a 500.
- Users and agents see no change.
@gricha
gricha force-pushed the ref/sa-narrow-users branch from db4d84f to 4aa6817 Compare November 3, 2026 20:51
@gricha
gricha merged commit cef0817 into master Nov 3, 2026
91 of 133 checks passed
@gricha
gricha deleted the ref/sa-narrow-users branch November 3, 2026 21:09
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