Skip to content

Commit 7650c47

Browse files
authored
fix: Gamma users shouldn't be able to create roles (#29687)
1 parent 1818054 commit 7650c47

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

superset/security/manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
238238
"SQL Lab",
239239
"User Registrations",
240240
"User's Statistics",
241+
# Guarding all AB_ADD_SECURITY_API = True REST APIs
242+
"Role",
243+
"Permission",
244+
"PermissionViewMenu",
245+
"ViewMenu",
246+
"User",
241247
} | USER_MODEL_VIEWS
242248

243249
ALPHA_ONLY_VIEW_MENUS = {

tests/integration_tests/security/api_tests.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from superset.models.dashboard import Dashboard
2727
from superset.utils.urls import get_url_host
2828
from superset.utils import json
29+
from tests.integration_tests.conftest import with_config
2930
from tests.integration_tests.base_tests import SupersetTestCase
3031
from tests.integration_tests.constants import ADMIN_USERNAME, GAMMA_USERNAME
3132
from tests.integration_tests.fixtures.birth_names_dashboard import (
@@ -135,3 +136,64 @@ def test_post_guest_token_bad_resources(self):
135136
)
136137

137138
self.assert400(response)
139+
140+
141+
class TestSecurityRolesApi(SupersetTestCase):
142+
uri = "api/v1/security/roles/" # noqa: F541
143+
144+
@with_config({"FAB_ADD_SECURITY_API": True})
145+
def test_get_security_roles_admin(self):
146+
"""
147+
Security API: Admin should be able to get roles
148+
"""
149+
self.login(ADMIN_USERNAME)
150+
response = self.client.get(self.uri)
151+
self.assert200(response)
152+
153+
@with_config({"FAB_ADD_SECURITY_API": True})
154+
def test_get_security_roles_gamma(self):
155+
"""
156+
Security API: Gamma should not be able to get roles
157+
"""
158+
self.login(GAMMA_USERNAME)
159+
response = self.client.get(self.uri)
160+
self.assert403(response)
161+
162+
@with_config({"FAB_ADD_SECURITY_API": True})
163+
def test_post_security_roles_gamma(self):
164+
"""
165+
Security API: Gamma should not be able to create roles
166+
"""
167+
self.login(GAMMA_USERNAME)
168+
response = self.client.post(
169+
self.uri,
170+
data=json.dumps({"name": "new_role"}),
171+
content_type="application/json",
172+
)
173+
self.assert403(response)
174+
175+
@with_config({"FAB_ADD_SECURITY_API": True})
176+
def test_put_security_roles_gamma(self):
177+
"""
178+
Security API: Gamma shouldnt be able to update roles
179+
"""
180+
self.login(GAMMA_USERNAME)
181+
response = self.client.put(
182+
f"{self.uri}1",
183+
data=json.dumps({"name": "new_role"}),
184+
content_type="application/json",
185+
)
186+
self.assert403(response)
187+
188+
@with_config({"FAB_ADD_SECURITY_API": True})
189+
def test_delete_security_roles_gamma(self):
190+
"""
191+
Security API: Gamma shouldnt be able to delete roles
192+
"""
193+
self.login(GAMMA_USERNAME)
194+
response = self.client.delete(
195+
f"{self.uri}1",
196+
data=json.dumps({"name": "new_role"}),
197+
content_type="application/json",
198+
)
199+
self.assert403(response)

tests/integration_tests/superset_test_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def GET_FEATURE_FLAGS_FUNC(ff):
137137

138138
ALERT_REPORTS_QUERY_EXECUTION_MAX_TRIES = 3
139139

140+
FAB_ADD_SECURITY_API = True
141+
140142

141143
class CeleryConfig:
142144
broker_url = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}"

0 commit comments

Comments
 (0)