Преглед изворни кода

chore: empty the destroy allowlist again after the cah-10-access teardown (#450) (#454)

* chore: empty the destroy allowlist again now the cah-10-access teardown has applied (#450)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* test: the shipped destroy allowlist is empty, pinned by the empty test (#450)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
ChiefGyk3D пре 1 месец
родитељ
комит
dcb0d0fa10
3 измењених фајлова са 27 додато и 33 уклоњено
  1. 1 13
      .spacelift/policies/plan.rego
  2. 19 16
      .spacelift/policies/plan_test.rego
  3. 7 4
      tests/test_destroy_allowlist_pins.py

+ 1 - 13
.spacelift/policies/plan.rego

@@ -172,19 +172,7 @@ address_groups := {}
 # rule as above: a pull request that names the stack, the address and the
 # reason, reviewed, then the new body pasted into Spacelift. Remove the entry
 # once the change has applied.
-#
-# TEMPORARY (issue #450): tear down the cah-10-access stack (the two connector
-# droplets, the only billable cloud assets). Both addresses are protected types
-# the destroy plan deletes:
-#   - twingate_remote_network.this: the Twingate site the connectors belong to
-#     (protected type twingate_remote_network).
-#   - module.connector_firewall.digitalocean_firewall.this: the connector
-#     firewall (protected type digitalocean_firewall).
-# A second pull request empties this list again once the destroy has applied.
-destroy_allowlist := {"cah-10-access": [
-	"twingate_remote_network.this",
-	"module.connector_firewall.digitalocean_firewall.this",
-]}
+destroy_allowlist := {}
 
 # Stack ids where a whole-service teardown is routine: a plan there that
 # deletes (not replaces) a digitalocean_firewall and the droplet it protects,

+ 19 - 16
.spacelift/policies/plan_test.rego

@@ -339,7 +339,7 @@ test_allowlists_are_empty_by_default if {
 	count(spacelift.address_groups) == 0
 
 	# destroy_allowlist is pinned by its own test further down (issue #450),
-	# not here.
+	# test_destroy_allowlist_is_empty.
 	count(spacelift.whole_service_teardown_stacks) == 0
 }
 
@@ -675,17 +675,13 @@ test_destroy_group_covers_members_in_its_stack_only if {
 	count(in_b) == 2
 }
 
-# Teardown of cah-10-access (issue #450). The shipped destroy_allowlist holds
-# exactly the two addresses the destroy plan shows for that stack, and nothing
-# else. While the teardown is under way, test_destroy_allowlist_is_exactly_teardown_list
-# pins it. No skipped test is used (opa test exits 2 on a skipped test).
-#
-# The follow-up pull request that empties the allowlist deletes that test, adds
-# test_destroy_allowlist_is_empty (count(spacelift.destroy_allowlist) == 0) and
-# sets destroy_allowlist := {} in plan.rego. tests/test_destroy_allowlist_pins.py
-# checks the test names against the shipped allowlist in both directions, so
-# the allowlist cannot be left filled after the teardown, nor emptied without
-# the flip.
+# Teardown of cah-10-access (issue #450) has applied, so the shipped
+# destroy_allowlist is empty again and test_destroy_allowlist_is_empty pins it.
+# The two teardown addresses below are still exercised by overriding the
+# allowlist in the test, so the keyed allowance keeps its coverage. No skipped
+# test is used (opa test exits 2 on a skipped test).
+# tests/test_destroy_allowlist_pins.py checks the test names against the
+# shipped allowlist in both directions.
 
 access_stack := "cah-10-access"
 
@@ -695,8 +691,8 @@ access_firewall := "module.connector_firewall.digitalocean_firewall.this"
 
 teardown_list := {access_stack: [access_network, access_firewall]}
 
-test_destroy_allowlist_is_exactly_teardown_list if {
-	spacelift.destroy_allowlist == teardown_list
+test_destroy_allowlist_is_empty if {
+	count(spacelift.destroy_allowlist) == 0
 }
 
 access_teardown := [
@@ -706,8 +702,15 @@ access_teardown := [
 	delete_of("module.connector_b.digitalocean_droplet.connector", "digitalocean_droplet", {"id": "2", "tags": ["cah-connector-nyc3"]}),
 ]
 
-test_access_teardown_is_allowed_in_access_stack if {
-	count(denied_on(access_stack, access_teardown)) == 0
+# With the teardown list supplied (it is not shipped), the access stack's
+# teardown passes; with the shipped empty list it is denied.
+test_access_teardown_is_allowed_in_access_stack_when_listed if {
+	reasons := spacelift.deny with input as on_stack(access_stack, access_teardown) with data.spacelift.destroy_allowlist as teardown_list
+	count(reasons) == 0
+}
+
+test_access_teardown_is_denied_in_access_stack_with_shipped_allowlist if {
+	count(denied_on(access_stack, access_teardown)) == 2
 }
 
 # The allowlist is keyed by stack: the same addresses elsewhere stay denied.

+ 7 - 4
tests/test_destroy_allowlist_pins.py

@@ -1,7 +1,7 @@
 """The destroy allowlist in plan.rego is pinned, and cannot be left filled.
 
-Issue #450 adds two addresses to destroy_allowlist for the cah-10-access
-teardown. plan_test.rego pins the allowlist by test name, in both directions:
+Issue #450 added two addresses to destroy_allowlist for the cah-10-access
+teardown and then emptied it again (the shipped state). plan_test.rego pins the allowlist by test name, in both directions:
 
   - allowlist filled: plan_test.rego has test_destroy_allowlist_is_exactly_teardown_list
     (matching the shipped entries) and no test_destroy_allowlist_is_empty;
@@ -103,7 +103,10 @@ TESTS_EMPTY = f"{EMPTY} if {{\n\tcount(spacelift.destroy_allowlist) == 0\n}}\n"
 
 def test_shipped_allowlist_and_tests_agree():
     policy, tests = POLICY.read_text(), POLICY_TESTS.read_text()
-    assert parse_allowlist(policy), "no destroy_allowlist entries were parsed"
+    # Shipped state after the #450 teardown: empty, pinned by the empty test.
+    assert parse_allowlist(policy) == {}
+    assert has_test(tests, EMPTY)
+    assert not has_test(tests, EXACT)
     assert problems(policy, tests) == []
 
 
@@ -113,7 +116,7 @@ def test_shipped_policy_tests_have_no_skipped_test():
 
 def test_allowlist_names_each_address_once():
     allowlist = parse_allowlist(POLICY.read_text())
-    for addresses in allowlist.values():
+    for addresses in [*allowlist.values(), *TEARDOWN.values()]:
         assert len(addresses) == len(set(addresses))