Skip to content

fix(superuser): Being superuser:read even if you're org owner results in fewer permissions #87689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/sentry/auth/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ def from_request_org_and_scopes(
rpc_user_org_context: RpcUserOrganizationContext | None = None,
scopes: Iterable[str] | None = None,
) -> Access:
"""
Note that `scopes` is usually None because request.auth is not set at `get_authorization_header`
when the request is made from the frontend using cookies
"""
is_superuser = is_active_superuser(request)
is_staff = is_active_staff(request)

Expand Down Expand Up @@ -929,6 +933,8 @@ def from_request_org_and_scopes(
superuser_scopes = get_superuser_scopes(auth_state, request.user, rpc_user_org_context)
if scopes:
superuser_scopes = superuser_scopes.union(set(scopes))
if member and member.scopes:
superuser_scopes = superuser_scopes.union(set(member.scopes))

return ApiBackedOrganizationGlobalAccess(
rpc_user_organization_context=rpc_user_org_context,
Expand Down Expand Up @@ -1033,6 +1039,8 @@ def from_request(
superuser_scopes = get_superuser_scopes(auth_state, request.user, organization)
if scopes:
superuser_scopes = superuser_scopes.union(set(scopes))
if member and (member_scopes := member.get_scopes()):
superuser_scopes = superuser_scopes.union(set(member_scopes))

return OrganizationGlobalAccess(
organization=organization,
Expand Down
6 changes: 4 additions & 2 deletions tests/sentry/auth/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,15 +587,17 @@ def test_superuser_readonly_scopes(self):
# superuser in organization
member = self.create_member(user=self.superuser, organization=self.org, role="member")

# If superuser is a member of the organization, it should have both
# the member scopes and the superuser scopes
result = self.from_request(request, self.org)
assert result.scopes == SUPERUSER_READONLY_SCOPES
assert result.scopes == set(member.get_scopes()).union(SUPERUSER_READONLY_SCOPES)

# readonly scopes does not override owner scopes if passed in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: update comment?

Copy link
Member

@iamrajjoshi iamrajjoshi Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

with assume_test_silo_mode(SiloMode.REGION):
member.update(role="owner")

result = self.from_request(request, self.org, scopes=member.get_scopes())
assert result.scopes == set(member.get_scopes()).union({"org:superuser"})
assert result.scopes == set(member.get_scopes()).union(SUPERUSER_READONLY_SCOPES)

@override_options({"superuser.read-write.ga-rollout": True})
@override_settings(SENTRY_SELF_HOSTED=False)
Expand Down
Loading