Skip to content

Commit a194e94

Browse files
committed
added new param to control enable destructive operations during seeding
1 parent 390089b commit a194e94

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

deploy/rbac-clowdapp.yml

+5
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ objects:
457457
value: ${ROLE_CREATE_ALLOW_LIST}
458458
- name: RBAC_DESTRUCTIVE_API_ENABLED_UNTIL
459459
value: ${RBAC_DESTRUCTIVE_API_ENABLED_UNTIL}
460+
- name: RBAC_DESTRUCTIVE_SEEDING_ENABLED_UNTIL
461+
value: ${RBAC_DESTRUCTIVE_SEEDING_ENABLED_UNTIL}
460462
- name: CLOWDER_ENABLED
461463
value: ${CLOWDER_ENABLED}
462464
- name: APP_NAMESPACE
@@ -729,6 +731,9 @@ parameters:
729731
- description: Timestamp expiration allowance on destructive actions through the internal RBAC API
730732
name: RBAC_DESTRUCTIVE_API_ENABLED_UNTIL
731733
value: ''
734+
- description: Timestamp expiration allowance on destructive actions through the seeding job
735+
name: RBAC_DESTRUCTIVE_SEEDING_ENABLED_UNTIL
736+
value: ''
732737
- description: Image tag
733738
name: IMAGE_TAG
734739
required: true

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ services:
3434
- PRINCIPAL_PROXY_SERVICE_SOURCE_CERT=${PRINCIPAL_PROXY_SERVICE_SOURCE_CERT-False}
3535
- PRINCIPAL_PROXY_SERVICE_SSL_VERIFY=${PRINCIPAL_PROXY_SERVICE_SSL_VERIFY-False}
3636
- RBAC_DESTRUCTIVE_API_ENABLED_UNTIL=${RBAC_DESTRUCTIVE_API_ENABLED_UNTIL}
37+
- RBAC_DESTRUCTIVE_SEEDING_ENABLED_UNTIL=${RBAC_DESTRUCTIVE_SEEDING_ENABLED_UNTIL}
3738
privileged: true
3839
ports:
3940
- 9080:8080

rbac/core/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def destructive_ok(operation_type):
2828
if operation_type == "api":
2929
return now < settings.INTERNAL_DESTRUCTIVE_API_OK_UNTIL
3030
if operation_type == "seeding":
31-
return False
31+
return now < settings.DESTRUCTIVE_SEEDING_OK_UNTIL
3232

3333
return False

rbac/rbac/settings.py

+9
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@
355355
GROUP_SEEDING_ENABLED = ENVIRONMENT.bool("GROUP_SEEDING_ENABLED", default=True)
356356
MAX_SEED_THREADS = ENVIRONMENT.int("MAX_SEED_THREADS", default=None)
357357

358+
try:
359+
DESTRUCTIVE_SEEDING_OK_UNTIL = parse_dt(
360+
os.environ.get("RBAC_DESTRUCTIVE_SEEDING_ENABLED_UNTIL", "not-a-real-time")
361+
)
362+
if DESTRUCTIVE_SEEDING_OK_UNTIL.tzinfo is None:
363+
DESTRUCTIVE_SEEDING_OK_UNTIL = DESTRUCTIVE_SEEDING_OK_UNTIL.replace(tzinfo=pytz.UTC)
364+
except ValueError as e:
365+
DESTRUCTIVE_SEEDING_OK_UNTIL = datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC)
366+
358367
# disable log messages less than CRITICAL when running unit tests.
359368
if len(sys.argv) > 1 and sys.argv[1] == "test":
360369
logging.disable(logging.CRITICAL)

tests/core/test_utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ def test_destructive_ok_true(self):
3939
def test_destructive_ok_false(self):
4040
"""Test that it's false when not within date range."""
4141
self.assertEqual(destructive_ok("api"), False)
42+
43+
@override_settings(DESTRUCTIVE_SEEDING_OK_UNTIL=valid_destructive_time())
44+
def test_destructive_ok_true(self):
45+
"""Test that it's true when within date range."""
46+
self.assertEqual(destructive_ok("seeding"), True)
47+
48+
@override_settings(DESTRUCTIVE_SEEDING_OK_UNTIL=invalid_destructive_time())
49+
def test_destructive_ok_false(self):
50+
"""Test that it's false when not within date range."""
51+
self.assertEqual(destructive_ok("seeding"), False)

tests/internal/test_views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_delete_selective_roles_disallowed(self):
410410
@override_settings(INTERNAL_DESTRUCTIVE_API_OK_UNTIL=valid_destructive_time())
411411
def test_delete_selective_roles(self):
412412
"""Test that we can delete selective roles when allowed and no roles."""
413-
# No name speicified
413+
# No name specified
414414
response = self.client.delete(f"/_private/api/utils/role/", **self.request.META)
415415
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
416416

0 commit comments

Comments
 (0)