Skip to content

Commit 19ac662

Browse files
cathtengchloeho7
authored andcommitted
feat(secrecy): enable data secrecy for organizations (#53322)
1 parent 21322a4 commit 19ac662

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

Diff for: .github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ yarn.lock @getsentry/owners-js-de
347347
/static/app/views/settings/organizationAuth/ @getsentry/enterprise
348348
/tests/sentry/api/endpoints/test_auth*.py @getsentry/enterprise
349349

350+
/tests/sentry/api/test_data_secrecy.py @getsentry/enterprise
351+
350352
/src/sentry/scim/ @getsentry/enterprise
351353
/tests/sentry/api/test_scim*.py @getsentry/enterprise
352354
/src/sentry/tasks/integrations/github/pr_comment.py @getsentry/enterprise @AniketDas-Tekky

Diff for: src/sentry/api/exceptions.py

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class SuperuserRequired(SentryAPIException):
8585
message = "You need to re-authenticate for superuser."
8686

8787

88+
class DataSecrecyError(SentryAPIException):
89+
status_code = status.HTTP_401_UNAUTHORIZED
90+
code = "data-secrecy"
91+
92+
8893
class SudoRequired(SentryAPIException):
8994
status_code = status.HTTP_401_UNAUTHORIZED
9095
code = "sudo-required"

Diff for: src/sentry/api/permissions.py

+9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from rest_framework import permissions
66
from rest_framework.request import Request
77

8+
from sentry import features
89
from sentry.api.exceptions import (
10+
DataSecrecyError,
911
MemberDisabledOverLimit,
1012
SsoRequired,
1113
SuperuserRequired,
@@ -122,6 +124,13 @@ def determine_access(
122124
if org_context is None:
123125
assert False, "Failed to fetch organization in determine_access"
124126

127+
if (
128+
request.user
129+
and request.user.is_superuser
130+
and features.has("organizations:enterprise-data-secrecy", org_context.organization)
131+
):
132+
raise DataSecrecyError()
133+
125134
if request.auth and request.user and request.user.is_authenticated:
126135
request.access = access.from_request_org_and_scopes(
127136
request=request,

Diff for: src/sentry/conf/server.py

+2
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,8 @@ def SOCIAL_AUTH_DEFAULT_USERNAME() -> str:
13711371
"organizations:discover-basic": True,
13721372
# Enable discover 2 custom queries and saved queries
13731373
"organizations:discover-query": True,
1374+
# Enables data secrecy mode
1375+
"organizations:enterprise-data-secrecy": False,
13741376
# Enable archive/escalating issue workflow
13751377
"organizations:escalating-issues": False,
13761378
# Enable archive/escalating issue workflow in MS Teams

Diff for: src/sentry/features/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
default_manager.add("organizations:dashboards-import", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
7878
default_manager.add("organizations:discover", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
7979
default_manager.add("organizations:discover-events-rate-limit", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
80+
default_manager.add("organizations:enterprise-data-secrecy", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
8081
default_manager.add("organizations:grouping-stacktrace-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
8182
default_manager.add("organizations:grouping-title-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
8283
default_manager.add("organizations:grouping-tree-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)

Diff for: tests/sentry/api/test_data_secrecy.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from sentry.testutils import APITestCase
2+
from sentry.testutils.helpers.features import with_feature
3+
4+
5+
class SuperuserDataSecrecyTestCase(APITestCase):
6+
endpoint = "sentry-api-0-organization-details"
7+
method = "get"
8+
9+
def setUp(self):
10+
super().setUp()
11+
self.login_as(self.user)
12+
13+
@with_feature("organizations:enterprise-data-secrecy")
14+
def test_superuser_no_access(self):
15+
"""
16+
Please contact the Enterprise team if your code change causes this test to fail
17+
"""
18+
superuser = self.create_user(is_superuser=True)
19+
self.login_as(superuser, superuser=True)
20+
21+
# superuser cannot access orgs with data secrecy
22+
self.get_error_response(self.organization.slug, status_code=401)
23+
24+
def test_superuser_has_access(self):
25+
superuser = self.create_user(is_superuser=True)
26+
self.login_as(superuser, superuser=True)
27+
28+
# superuser can access orgs without data secrecy
29+
self.get_success_response(self.organization.slug)
30+
31+
def test_non_member_no_access(self):
32+
self.login_as(self.create_user())
33+
self.get_error_response(self.organization.slug, status_code=403)
34+
35+
def test_member_has_access(self):
36+
self.get_success_response(self.organization.slug)

0 commit comments

Comments
 (0)