infra: pin region-remote-host by digest (#1007, Astra R2)
A text scan of HCL can always be dodged (a quoted or multiline Resource, a block-commented condition). The module's .tf files are now pinned by SHA-256: any change fails until reviewed against #1007 and the pin is updated. The readable checks stay to say what that review confirms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/provision/remote_host_module_test.go+33 −4
CI failed — run details
Intent
<task-notification> <task-id>blz9xe6wi</task-id> <tool-use-id>toolu_01Fw52DppxLZFChTPoUuQLak</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/533b74b1-f52c-4095-800a-7716df14b9ab/tasks/blz9xe6wi.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra R2 to finish" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 14.8 g CO₂e (1,704,815 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on close-direct-s3-fleet-writes, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/provision/remote_host_module_test.go b/internal/provision/remote_host_module_test.go| index 24a8d26bb..c03f796f1 100644 |
| --- a/internal/provision/remote_host_module_test.go |
| +++ b/internal/provision/remote_host_module_test.go |
| @@ -1,6 +1,8 @@ |
| package provision |
| import ( |
| + "crypto/sha256" |
| + "encoding/hex" |
| "os" |
| "path/filepath" |
| "regexp" |
| @@ -12,13 +14,20 @@ import ( |
| // #1007: region-remote-host once granted its off-cloud principal read and |
| // write on the whole platform deployment bucket, which let a fleet box |
| // rewrite any instance record. These guards keep the module unable to grant |
| -// that again. CI has no OpenTofu, so they read the module text, strictly: |
| -// any shape they do not recognise fails, and the fix is to review the new |
| -// grant and update the guard. The module's own tofu tests |
| -// (tests/no_deployment_bucket.tftest.hcl) check the plan. |
| +// that again. CI has no OpenTofu and a text scan of HCL can always be |
| +// dodged (Astra #1007 R2), so the module's .tf files are pinned by digest: |
| +// any change fails until someone has reviewed it and updated the pin. The |
| +// readable checks below say what that review must confirm. The module's own |
| +// tofu tests (tests/no_deployment_bucket.tftest.hcl) check the plan. |
| const remoteHostModule = "infra/modules/region-remote-host" |
| +// SHA-256 of main.tf, outputs.tf and variables.tf (see remoteHostDigest). |
| +// Before changing it, confirm the module still grants nothing outside its |
| +// own data bucket and a sibling's moves/ prefix, and still refuses a |
| +// non-empty deployment_bucket_arn (#1007). |
| +const remoteHostModuleDigest = "d0bcbc927254cd8a29e7d5f4bbbc0b9748243a53f6bcb444e0cde26ed98c2af2" |
| + |
| // Every block the module may declare. A new resource, data source or child |
| // module is a possible new grant, so it fails here until reviewed. |
| var remoteHostBlocks = []string{ |
| @@ -110,6 +119,15 @@ func TestRegionRemoteHostGuardCatchesRegrants(t *testing.T) { |
| {"condition commented out", "variables.tf", func(s string) string { |
| return strings.Replace(s, condition, "# "+condition+"\n condition = true", 1) |
| }}, |
| + {"quoted Resource key", "main.tf", func(s string) string { |
| + return strings.Replace(s, ownObjects, `"Resource" = ["*"]`, 1) |
| + }}, |
| + {"multiline Resource list", "main.tf", func(s string) string { |
| + return strings.Replace(s, ownObjects, "Resource = [\n \"*\",\n ]", 1) |
| + }}, |
| + {"block-commented condition", "variables.tf", func(s string) string { |
| + return strings.Replace(s, condition, "/*\n "+condition+"\n */ condition = var.deployment_bucket_arn == \"\" || true", 1) |
| + }}, |
| {"new tf file", "extra.tf", func(string) string { return "# nothing yet\n" }}, |
| {"tf.json file", "extra.tf.json", func(string) string { return "{}" }}, |
| {"resource in variables.tf", "variables.tf", func(s string) string { |
| @@ -143,6 +161,9 @@ func remoteHostModuleProblems(files map[string]string) []string { |
| if !slices.Equal(names, []string{"main.tf", "outputs.tf", "variables.tf"}) { |
| problems = append(problems, "region-remote-host files changed to "+strings.Join(names, ", ")+"; review any new grant, then update this guard") |
| } |
| + if got := remoteHostDigest(files, names); got != remoteHostModuleDigest { |
| + problems = append(problems, "region-remote-host changed (digest "+got+"). Review it against #1007 (no grant outside its own data bucket and a sibling's moves/ prefix; deployment_bucket_arn still refused), then update remoteHostModuleDigest") |
| + } |
| var code strings.Builder |
| for _, name := range names { |
| @@ -192,6 +213,14 @@ func remoteHostModuleProblems(files map[string]string) []string { |
| return problems |
| } |
| +func remoteHostDigest(files map[string]string, names []string) string { |
| + h := sha256.New() |
| + for _, name := range names { |
| + h.Write([]byte(name + "\x00" + files[name] + "\x00")) |
| + } |
| + return hex.EncodeToString(h.Sum(nil)) |
| +} |
| + |
| func stripHCLComments(s string) string { |
| var out strings.Builder |
| for _, line := range strings.Split(s, "\n") { |