carlos / platform Public

test: pin the termination proof boundary blocks by digest

Branch fix re-review BRF1-P2-01. The re-pinned tripwire collected only
lines starting with Resource, so a statement added with NotResource
(and Get/Put/Delete) could widen the shared boundary to the proof
object while every checked line stayed the same.

TestTerminationProofCredentials now also pins a sha256, over
whitespace-collapsed text, of each boundary-relevant block: the
store_user_boundary policy resource, store_boundary_statements,
managed_boundary_statements, the fleet bucket and object locals, and
the conditions of the two managed prefix validations. A mismatch names
the block and asks for the termination-proof intersection to be
re-evaluated. The existing positive checks stay.
TestTerminationBoundaryDigestsTrip proves an added NotResource or
Resource statement in either list changes its digest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 186153e7079a6a7f81bab0d3d6b5f8fca3197ccd parent f588954
1 file changed, +122 −0
  • internal/objstore/termination_credentials_test.go +122 −0

CI passed — run details

diff --git a/internal/objstore/termination_credentials_test.go b/internal/objstore/termination_credentials_test.go
index 91de88970..5d0774a31 100644
--- a/internal/objstore/termination_credentials_test.go
+++ b/internal/objstore/termination_credentials_test.go
@@ -1,7 +1,10 @@
package objstore
import (
+ "crypto/sha256"
+ "encoding/hex"
"encoding/json"
+ "fmt"
"os"
"path/filepath"
"slices"
@@ -106,6 +109,18 @@ func TestTerminationProofCredentials(t *testing.T) {
t.Fatalf("fleet prefix validation changed; re-evaluate intersection: %s", pin)
}
}
+ // Every boundary-relevant expression, as whole text: an added statement,
+ // a NotResource or a new Action changes a digest even when every line
+ // checked above is still there.
+ got, err := terminationBoundaryDigests(tf, mf, string(vars))
+ if err != nil {
+ t.Fatal(err)
+ }
+ for name, want := range terminationBoundaryWant {
+ if got[name] != want {
+ t.Errorf("%s changed (digest %s): re-evaluate the termination-proof intersection, then update terminationBoundaryWant", name, got[name])
+ }
+ }
// 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")
@@ -132,3 +147,110 @@ func boundaryResources(t *testing.T, tf, open string) []string {
}
return out
}
+
+// terminationBoundaryWant is each boundary-relevant block's digest, over its
+// text with whitespace runs collapsed. Change one only after re-evaluating
+// that no store, app or fleet credential reaches the termination proof.
+var terminationBoundaryWant = map[string]string{
+ "store boundary policy": "0fd3b69dba6c26c85fc98947db4ecc879d13a39aba7eee318029a743d75b1c18",
+ "store boundary statements": "f4f29e497fbd5afa34d88dfd94692f480efa733c927698c9d6148c7b5fdff2c9",
+ "fleet boundary statements": "9f1f81aaff4e195096dae1b1c086d180071d43c76ef8750b684ea88da862b4c5",
+ "fleet bucket local": "2825c8094b6fb80aa0a25683134a22a5efb59a1a02227f528dba9a9ecdb15197",
+ "fleet object locals": "db659c3347257caaec610263af06c2126ce8a9b3e96f7c4e88ede9518a2ec6c7",
+ "fleet prefix coverage validation": "4d1ac1b667f57c84cfedf0d01dbe2ebf6648b179be911d1a26e94638d5c8adb6",
+ "fleet and store prefix overlap validation": "b56a6c3e3f3d42f3bcde8697074d30789ae8f6e299c7823a98a36c7c22401ed8",
+}
+
+// terminationBoundaryDigests extracts the boundary policy, both statement
+// lists, the fleet resource locals and the two prefix validations.
+func terminationBoundaryDigests(mainTF, fleetTF, varsTF string) (map[string]string, error) {
+ span := func(text, open, close string) (string, error) {
+ i := strings.Index(text, open)
+ if i < 0 {
+ return "", fmt.Errorf("missing %q", open)
+ }
+ j := strings.Index(text[i:], close)
+ if j < 0 {
+ return "", fmt.Errorf("unterminated %q", open)
+ }
+ return text[i : i+j+len(close)], nil
+ }
+ validation := func(pin string) (string, error) {
+ k := strings.Index(varsTF, pin)
+ if k < 0 {
+ return "", fmt.Errorf("missing validation %q", pin)
+ }
+ // The condition only: its error message is copy, not policy.
+ i := strings.LastIndex(varsTF[:k], " condition")
+ j := strings.Index(varsTF[k:], "\n error_message")
+ if i < 0 || j < 0 {
+ return "", fmt.Errorf("unterminated validation %q", pin)
+ }
+ return varsTF[i : k+j], nil
+ }
+ blocks := map[string]func() (string, error){
+ "store boundary policy": func() (string, error) {
+ return span(mainTF, `resource "aws_iam_policy" "store_user_boundary"`, `resource "aws_iam_role_policy" "host_store"`)
+ },
+ "store boundary statements": func() (string, error) { return span(mainTF, " store_boundary_statements = [\n", "\n ]\n") },
+ "fleet boundary statements": func() (string, error) { return span(fleetTF, " managed_boundary_statements = [\n", "\n ]\n") },
+ "fleet bucket local": func() (string, error) { return span(fleetTF, " managed_bucket_arn ", "\n") },
+ "fleet object locals": func() (string, error) {
+ return span(fleetTF, " managed_data_prefixes ", "\n managed_secrets_object = \"system/fleet-secrets-key.json\"\n")
+ },
+ "fleet prefix coverage validation": func() (string, error) {
+ return validation("startswith(trimprefix(arn, \"arn:aws:s3:::\"), var.managed_fleet_bucket_prefix)")
+ },
+ "fleet and store prefix overlap validation": func() (string, error) {
+ return validation("startswith(var.store_bucket_prefix, var.managed_fleet_bucket_prefix) ||")
+ },
+ }
+ out := map[string]string{}
+ for name, extract := range blocks {
+ text, err := extract()
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", name, err)
+ }
+ sum := sha256.Sum256([]byte(strings.Join(strings.Fields(text), " ")))
+ out[name] = hex.EncodeToString(sum[:])
+ }
+ return out, nil
+}
+
+// TestTerminationBoundaryDigestsTrip: a statement added to either list,
+// whether it names a Resource or a NotResource, changes a pinned digest.
+func TestTerminationBoundaryDigestsTrip(t *testing.T) {
+ read := func(name string) string {
+ raw, err := os.ReadFile("../../infra/modules/region-host/" + name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(raw)
+ }
+ mainTF, fleetTF, varsTF := read("main.tf"), read("managed_fleets.tf"), read("variables.tf")
+ base, err := terminationBoundaryDigests(mainTF, fleetTF, varsTF)
+ if err != nil {
+ t.Fatal(err)
+ }
+ added := map[string]string{
+ "NotResource": " {\n Effect = \"Allow\"\n Action = [\"s3:GetObject\", \"s3:PutObject\", \"s3:DeleteObject\"]\n NotResource = \"arn:aws:s3:::excluded-unrelated-bucket/*\"\n },\n",
+ "Resource": " {\n Effect = \"Allow\"\n Action = [\"s3:GetObject\"]\n Resource = \"arn:aws:s3:::*/*\"\n },\n",
+ }
+ for kind, statement := range added {
+ for _, list := range []string{"store", "fleet"} {
+ m, f := mainTF, fleetTF
+ if list == "store" {
+ m = strings.Replace(m, " store_boundary_statements = [\n", " store_boundary_statements = [\n"+statement, 1)
+ } else {
+ f = strings.Replace(f, " managed_boundary_statements = [\n", " managed_boundary_statements = [\n"+statement, 1)
+ }
+ got, err := terminationBoundaryDigests(m, f, varsTF)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got[list+" boundary statements"] == base[list+" boundary statements"] {
+ t.Fatalf("added %s statement in the %s list kept its digest", kind, list)
+ }
+ }
+ }
+}