carlos / platform Public

test: re-pin the termination proof tripwire to the shared boundary

TestTerminationProofCredentials read the store boundary's object
resource as one literal, which Task 5's concatenated store and managed
fleet statements moved into locals. Re-evaluated: store statements are
still bounded by store_bucket_prefix, fleet statements by
managed_fleet_bucket_prefix on fleet object prefixes that exclude
control/terminations/, and variables.tf refuses a managed prefix that
covers the deployment, data or staging bucket or overlaps the store
prefix. The tripwire now pins the concat, every Resource line of both
statement lists, the fleet bucket and prefix locals and those two
validations, so any change to them fails again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f5889545fa305306c490ab9376f58d8dae815a21 parent 72b657f
1 file changed, +73 −1
  • internal/objstore/termination_credentials_test.go +73 −1

CI cancelled — superseded by a newer push — run details

diff --git a/internal/objstore/termination_credentials_test.go b/internal/objstore/termination_credentials_test.go
index 27065dea4..91de88970 100644
--- a/internal/objstore/termination_credentials_test.go
+++ b/internal/objstore/termination_credentials_test.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"path/filepath"
+ "slices"
"strings"
"testing"
)
@@ -52,11 +53,82 @@ func TestTerminationProofCredentials(t *testing.T) {
t.Fatal("boundary missing")
}
boundary := tf[start : start+end]
- if !strings.Contains(boundary, `Resource = "arn:aws:s3:::${var.store_bucket_prefix}*/*"`) {
+ // The boundary is the store statements (with a store prefix) and the
+ // managed fleet statements (with managed fleets on), nothing else.
+ if !strings.Contains(boundary, "Statement = concat(\n [for st in local.store_boundary_statements : st if var.store_bucket_prefix != \"\"],\n [for st in local.managed_boundary_statements : st if var.managed_fleets_enabled],\n )") {
t.Fatal("store boundary changed; re-evaluate intersection")
}
+ // Store statements stay bounded by store_bucket_prefix.
+ if got := boundaryResources(t, tf, " store_boundary_statements = ["); !slices.Equal(got, []string{
+ `Resource = "arn:aws:s3:::${var.store_bucket_prefix}*"`,
+ `Resource = "arn:aws:s3:::${var.store_bucket_prefix}*/*"`,
+ }) {
+ t.Fatalf("store boundary changed; re-evaluate intersection: %q", got)
+ }
+ // Fleet statements stay bounded by managed_fleet_bucket_prefix, on fleet
+ // object prefixes that do not include control/terminations/.
+ fleet, err := os.ReadFile("../../infra/modules/region-host/managed_fleets.tf")
+ if err != nil {
+ t.Fatal(err)
+ }
+ mf := string(fleet)
+ for _, pin := range []string{
+ `managed_bucket_arn = "arn:aws:s3:::${var.managed_fleet_bucket_prefix}*"`,
+ `managed_data_prefixes = ["instances/*", "moves/*", "move-snapshots/*"]`,
+ `managed_probe_prefix = "_carlos/probes/*"`,
+ `managed_secrets_object = "system/fleet-secrets-key.json"`,
+ } {
+ if !strings.Contains(mf, pin) {
+ t.Fatalf("fleet boundary changed; re-evaluate intersection: %s", pin)
+ }
+ }
+ if got := boundaryResources(t, mf, " managed_boundary_statements = ["); !slices.Equal(got, []string{
+ `Resource = [local.managed_bucket_arn]`,
+ `Resource = [local.managed_bucket_arn]`,
+ `Resource = [for p in local.managed_data_prefixes : "${local.managed_bucket_arn}/${p}"]`,
+ `Resource = ["${local.managed_bucket_arn}/${local.managed_probe_prefix}"]`,
+ `Resource = ["${local.managed_bucket_arn}/${local.managed_secrets_object}"]`,
+ `Resource = ["${local.managed_bucket_arn}/${local.managed_secrets_object}"]`,
+ }) {
+ t.Fatalf("fleet boundary changed; re-evaluate intersection: %q", got)
+ }
+ // And a managed prefix may not cover the deployment, data or staging
+ // buckets, nor overlap the store prefix.
+ vars, err := os.ReadFile("../../infra/modules/region-host/variables.tf")
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, pin := range []string{
+ "for arn in concat([var.deployment_bucket_arn, var.data_bucket_arn], var.sibling_staging_arns) :\n startswith(trimprefix(arn, \"arn:aws:s3:::\"), var.managed_fleet_bucket_prefix)",
+ "startswith(var.store_bucket_prefix, var.managed_fleet_bucket_prefix) ||\n startswith(var.managed_fleet_bucket_prefix, var.store_bucket_prefix)",
+ } {
+ if !strings.Contains(string(vars), pin) {
+ t.Fatalf("fleet prefix validation changed; re-evaluate intersection: %s", pin)
+ }
+ }
// The box's own data-bucket object grant covers the proof and its locks.
if !strings.Contains(tf, `Action = ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"]`+"\n Resource = [\n \"${var.deployment_bucket_arn}/*\",\n \"${var.data_bucket_arn}/*\",") {
t.Fatal("trusted box data grant changed")
}
}
+
+// boundaryResources returns the trimmed Resource lines of the HCL list that
+// opens with the line open and closes at the next line " ]".
+func boundaryResources(t *testing.T, tf, open string) []string {
+ t.Helper()
+ start := strings.Index(tf, open+"\n")
+ if start < 0 {
+ t.Fatalf("missing %s", open)
+ }
+ end := strings.Index(tf[start:], "\n ]\n")
+ if end < 0 {
+ t.Fatalf("unterminated %s", open)
+ }
+ var out []string
+ for _, line := range strings.Split(tf[start:start+end], "\n") {
+ if line = strings.TrimSpace(line); strings.HasPrefix(line, "Resource") {
+ out = append(out, line)
+ }
+ }
+ return out
+}