Skip to content

Commit 3e1613b

Browse files
authored
fix(seer): Allow org read permissions on seer public rpc (#104473)
Seer rpcs use POST request for a bunch of read operations. Relax the permissions on this endpoint so we only need `org:read`.
1 parent 4db1307 commit 3e1613b

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/sentry/seer/endpoints/organization_seer_rpc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sentry.api.api_owners import ApiOwner
1313
from sentry.api.api_publish_status import ApiPublishStatus
1414
from sentry.api.base import region_silo_endpoint
15-
from sentry.api.bases.organization import OrganizationEndpoint
15+
from sentry.api.bases.organization import OrganizationEndpoint, OrganizationPermission
1616
from sentry.constants import ObjectStatus
1717
from sentry.hybridcloud.rpc.service import RpcResolutionException
1818
from sentry.hybridcloud.rpc.sig import SerializableFunctionValueException
@@ -95,6 +95,14 @@
9595
}
9696

9797

98+
class SeerRpcPermission(OrganizationPermission):
99+
# Seer RPCs uses POST requests but is actually read only
100+
# So relax the permissions here.
101+
scope_map = {
102+
"POST": ["org:read", "org:write", "org:admin"],
103+
}
104+
105+
98106
@region_silo_endpoint
99107
class OrganizationSeerRpcEndpoint(OrganizationEndpoint):
100108
"""
@@ -114,6 +122,7 @@ class OrganizationSeerRpcEndpoint(OrganizationEndpoint):
114122
}
115123
owner = ApiOwner.ML_AI
116124
enforce_rate_limit = False
125+
permission_classes = (SeerRpcPermission,)
117126

118127
def _is_allowed(self, organization: Organization) -> bool:
119128
"""Check if the organization is allowed to use this endpoint."""

tests/sentry/seer/endpoints/test_organization_seer_rpc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from django.urls import reverse
22

3+
from sentry.models.apitoken import ApiToken
4+
from sentry.silo.base import SiloMode
35
from sentry.testutils.cases import APITestCase
46
from sentry.testutils.helpers.features import with_feature
7+
from sentry.testutils.silo import assume_test_silo_mode
58

69

710
class TestOrganizationSeerRpcEndpoint(APITestCase):
@@ -137,3 +140,20 @@ def test_unknown_method_returns_404_for_org_method(self) -> None:
137140
path = self._get_path("definitely_not_a_real_method")
138141
response = self.client.post(path, data={"args": {}}, format="json")
139142
assert response.status_code == 404
143+
144+
@with_feature("organizations:seer-public-rpc")
145+
def test_org_read_permission(self) -> None:
146+
self.user = self.create_user()
147+
self.organization = self.create_organization(owner=self.user)
148+
149+
for scope in ["org:read", "org:write", "org:admin"]:
150+
with assume_test_silo_mode(SiloMode.CONTROL):
151+
token = ApiToken.objects.create(user=self.user, scope_list=[scope])
152+
153+
path = self._get_path("get_organization_slug")
154+
response = self.client.post(
155+
path, data={"args": {}}, format="json", HTTP_AUTHORIZATION=f"Bearer {token.token}"
156+
)
157+
158+
assert response.status_code == 200
159+
assert response.data == {"slug": self.organization.slug}

0 commit comments

Comments
 (0)