Skip to content

Commit 390089b

Browse files
committed
rename existing param for destructive operations to be related only with api requests
next commit will introduce new param for destructive operations within seeding that will allow us to have a finer control over destructive RBAC operations
1 parent 28ff218 commit 390089b

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

Diff for: deploy/rbac-clowdapp.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ objects:
455455
value: ${BYPASS_BOP_VERIFICATION}
456456
- name: ROLE_CREATE_ALLOW_LIST
457457
value: ${ROLE_CREATE_ALLOW_LIST}
458-
- name: RBAC_DESTRUCTIVE_ENABLED_UNTIL
459-
value: ${RBAC_DESTRUCTIVE_ENABLED_UNTIL}
458+
- name: RBAC_DESTRUCTIVE_API_ENABLED_UNTIL
459+
value: ${RBAC_DESTRUCTIVE_API_ENABLED_UNTIL}
460460
- name: CLOWDER_ENABLED
461461
value: ${CLOWDER_ENABLED}
462462
- name: APP_NAMESPACE
@@ -727,7 +727,7 @@ parameters:
727727
name: ROLE_CREATE_ALLOW_LIST
728728
value: cost-management,remediations,inventory,drift,policies,advisor,catalog,approval,vulnerability,compliance,automation-analytics,notifications,patch,integrations,ros,staleness,config-manager,idmsvc
729729
- description: Timestamp expiration allowance on destructive actions through the internal RBAC API
730-
name: RBAC_DESTRUCTIVE_ENABLED_UNTIL
730+
name: RBAC_DESTRUCTIVE_API_ENABLED_UNTIL
731731
value: ''
732732
- description: Image tag
733733
name: IMAGE_TAG

Diff for: docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ services:
3333
- PRINCIPAL_PROXY_SERVICE_PATH=${PRINCIPAL_PROXY_SERVICE_PATH}
3434
- PRINCIPAL_PROXY_SERVICE_SOURCE_CERT=${PRINCIPAL_PROXY_SERVICE_SOURCE_CERT-False}
3535
- PRINCIPAL_PROXY_SERVICE_SSL_VERIFY=${PRINCIPAL_PROXY_SERVICE_SSL_VERIFY-False}
36-
- RBAC_DESTRUCTIVE_ENABLED_UNTIL=${RBAC_DESTRUCTIVE_ENABLED_UNTIL}
36+
- RBAC_DESTRUCTIVE_API_ENABLED_UNTIL=${RBAC_DESTRUCTIVE_API_ENABLED_UNTIL}
3737
privileged: true
3838
ports:
3939
- 9080:8080

Diff for: rbac/core/utils.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
from django.conf import settings
2323

2424

25-
def destructive_ok():
25+
def destructive_ok(operation_type):
2626
"""Determine if it's ok to run destructive operations."""
2727
now = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
28-
return now < settings.INTERNAL_DESTRUCTIVE_API_OK_UNTIL
28+
if operation_type == "api":
29+
return now < settings.INTERNAL_DESTRUCTIVE_API_OK_UNTIL
30+
if operation_type == "seeding":
31+
return False
32+
33+
return False

Diff for: rbac/internal/views.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def tenant_view(request, org_id):
137137
"""
138138
logger.info(f"Tenant view: {request.method} {request.user.username}")
139139
if request.method == "DELETE":
140-
if not destructive_ok():
140+
if not destructive_ok("api"):
141141
return HttpResponse("Destructive operations disallowed.", status=400)
142142

143143
tenant_obj = get_object_or_404(Tenant, org_id=org_id)
@@ -391,7 +391,7 @@ def invalid_default_admin_groups(request):
391391
}
392392
return HttpResponse(json.dumps(payload), content_type="application/json")
393393
if request.method == "DELETE":
394-
if not destructive_ok():
394+
if not destructive_ok("api"):
395395
return HttpResponse("Destructive operations disallowed.", status=400)
396396
invalid_default_admin_groups_list.delete()
397397
return HttpResponse(status=204)
@@ -405,7 +405,7 @@ def role_removal(request):
405405
"""
406406
logger.info(f"Role removal: {request.method} {request.user.username}")
407407
if request.method == "DELETE":
408-
if not destructive_ok():
408+
if not destructive_ok("api"):
409409
return HttpResponse("Destructive operations disallowed.", status=400)
410410

411411
role_name = request.GET.get("name")
@@ -433,7 +433,7 @@ def permission_removal(request):
433433
"""
434434
logger.info(f"Permission removal: {request.method} {request.user.username}")
435435
if request.method == "DELETE":
436-
if not destructive_ok():
436+
if not destructive_ok("api"):
437437
return HttpResponse("Destructive operations disallowed.", status=400)
438438

439439
permission = request.GET.get("permission")

Diff for: rbac/management/role/definer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def seed_roles():
137137
# Find roles in DB but not in config
138138
roles_to_delete = Role.objects.filter(system=True).exclude(id__in=current_role_ids)
139139
logger.info(f"The following '{roles_to_delete.count()}' roles(s) eligible for removal: {roles_to_delete.values()}")
140-
if destructive_ok():
140+
if destructive_ok("seeding"):
141141
logger.info(f"Removing the following role(s): {roles_to_delete.values()}")
142142
# Actually remove roles no longer in config
143143
with transaction.atomic():
@@ -202,7 +202,7 @@ def seed_permissions():
202202
logger.info(
203203
f"The following '{perms_to_delete.count()}' permission(s) eligible for removal: {perms_to_delete.values()}"
204204
)
205-
if destructive_ok():
205+
if destructive_ok("seeding"):
206206
logger.info(f"Removing the following permissions(s): {perms_to_delete.values()}")
207207
# Actually remove perms no longer in DB
208208
with transaction.atomic():

Diff for: rbac/rbac/settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@
367367
INTERNAL_API_PATH_PREFIXES = ["/_private/"]
368368

369369
try:
370-
INTERNAL_DESTRUCTIVE_API_OK_UNTIL = parse_dt(os.environ.get("RBAC_DESTRUCTIVE_ENABLED_UNTIL", "not-a-real-time"))
370+
INTERNAL_DESTRUCTIVE_API_OK_UNTIL = parse_dt(
371+
os.environ.get("RBAC_DESTRUCTIVE_API_ENABLED_UNTIL", "not-a-real-time")
372+
)
371373
if INTERNAL_DESTRUCTIVE_API_OK_UNTIL.tzinfo is None:
372374
INTERNAL_DESTRUCTIVE_API_OK_UNTIL = INTERNAL_DESTRUCTIVE_API_OK_UNTIL.replace(tzinfo=pytz.UTC)
373375
except ValueError as e:

Diff for: tests/core/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def invalid_destructive_time():
3333
@override_settings(INTERNAL_DESTRUCTIVE_API_OK_UNTIL=valid_destructive_time())
3434
def test_destructive_ok_true(self):
3535
"""Test that it's true when within date range."""
36-
self.assertEqual(destructive_ok(), True)
36+
self.assertEqual(destructive_ok("api"), True)
3737

3838
@override_settings(INTERNAL_DESTRUCTIVE_API_OK_UNTIL=invalid_destructive_time())
3939
def test_destructive_ok_false(self):
4040
"""Test that it's false when not within date range."""
41-
self.assertEqual(destructive_ok(), False)
41+
self.assertEqual(destructive_ok("api"), False)

0 commit comments

Comments
 (0)