carlos / platform Public

infra: close the direct-S3 fleet write path (#1007)

region-remote-host no longer grants its principal anything on the platform
deployment bucket; a non-empty deployment_bucket_arn now fails the plan
with a message pointing at the fleet door. New access_key_status lets a
root pin a switched-off key Inactive so an apply cannot reactivate it.

The BYO fleet page drops the grandfathered direct-S3 paragraph. A Go guard
(CI has no tofu) and a tofu test keep the module from granting outside its
own data bucket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d5a309bdf4dcafe1680331845680b5bcbf783f01 parent 433fcf1
8 files changed, +190 −76
  • infra/modules/README.md +11 −12
  • infra/modules/region-remote-host/README.md +15 −15
  • infra/modules/region-remote-host/main.tf +8 −35
  • infra/modules/region-remote-host/tests/no_deployment_bucket.tftest.hcl +72 −0
  • infra/modules/region-remote-host/variables.tf +17 −1
  • internal/console/accountfleet_test.go +6 −6
  • internal/console/templates/fleet_byo.html +0 −7
  • internal/provision/remote_host_module_test.go +61 −0

CI cancelled — superseded by a newer push — run details

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="f160f8a5-4faa-4a1a-8a6e-aa420755421b"> Agent manager 8a3d302: (a): apply the targeted plan as is (the three added statements are the current module&apos;s own-bucket version grants; nothing outside the Pi bucket). Then close the trap you found: make an untargeted apply unable to reactivate the key, by setting that aws_iam_access_key&apos;s status to &quot;Inactive&quot; in the pi-fleet config (targeted plan: 0/1/0 on the key only, no new secret) and committing it in that repo; if the provider would recreate the key instead, stop and tell me. Record both, with counts, on #1007. Leave the bucket lifecycle drift alone (note it). </paseo-system>

diff --git a/infra/modules/README.md b/infra/modules/README.md
index e91c128f4..bf2ca851c 100644
--- a/infra/modules/README.md
+++ b/infra/modules/README.md
@@ -139,23 +139,22 @@ Outputs: `clamd_addr` (set as the console's `CARLOS_CLAMD_ADDR`), `stream_max_by
## region-remote-host
-What an off-cloud CARLOS host (customer fleets and tito's hq)
-needs from AWS when there is no EC2 instance profile to lean on: a region
-data bucket plus a scoped IAM user + access key, limited to this region's
-data bucket always, plus the deployment bucket only when
-`deployment_bucket_arn` is set — the same wrong-region-fails-at-IAM
-residency property `region-host` gives cloud hosts. Fleet-API consumers
-(issue #73) omit `deployment_bucket_arn` entirely: the box reaches the
-platform's deployment bucket over the console's edge with its tunnel
-token, not a direct IAM grant. Consumed by customer fleets (paulca/pi-fleet
-is the live example) and the platform's tito hq; the module is reusable
-as-is for both.
+What an off-cloud CARLOS host needs from AWS when there is no EC2
+instance profile to lean on: a region data bucket, plus an IAM user and
+access key limited to that bucket (the same wrong-region-fails-at-IAM
+property `region-host` gives cloud hosts). The user gets nothing on the
+platform's deployment bucket: the box reaches it through the console's edge
+with its tunnel token. Setting `deployment_bucket_arn` fails the plan
+(#1007); see the module's README.
| Variable | Description |
|---|---|
| `region_code` | Short region code this host serves (e.g. `pi`, `hq`). |
| `data_bucket_name` | Name of this region's data bucket (created here). |
-| `deployment_bucket_arn` | ARN of the existing deployment bucket the host reads releases/status from and writes heartbeats to. |
+| `sibling_staging_arns` | Sibling regions' data buckets this host may stage moves into (`moves/*` only). Default none. |
+| `data_noncurrent_days` | Days a noncurrent version in the data bucket is kept. Default 7. |
+| `access_key_status` | `Active` (default) or `Inactive`. Pin `Inactive` after switching a key off, so an apply cannot turn it back on. |
+| `deployment_bucket_arn` | Removed. Must stay unset. |
Outputs: `bucket_name`, `access_key_id`, `secret_access_key` (sensitive).
diff --git a/infra/modules/region-remote-host/README.md b/infra/modules/region-remote-host/README.md
index aceb8ff16..ffd0566f2 100644
--- a/infra/modules/region-remote-host/README.md
+++ b/infra/modules/region-remote-host/README.md
@@ -10,22 +10,22 @@ Consumed by customer fleets (paulca/pi-fleet is the live example) and
the platform's tito hq box. The module is reusable as-is for both — they
differ only in account and variable values, not shape.
-**`deployment_bucket_arn` is optional (default `""`).** The fleet API
-surface (issue #73) means a fleet box no longer needs any IAM grant on the
-platform's deployment bucket at all: it reads releases and status, and
-writes heartbeats, through the console's edge (`/store/o/...`) using the
-same tunnel token it already dials with — the door authenticates and
-scopes the request, not a bucket-level AWS credential. That is the shape
-every new fleet-API consumer's tofu root should apply with: leave
-`deployment_bucket_arn` unset, and the module emits no deployment-bucket
-IAM statement at all.
+**The principal gets nothing on the platform's deployment bucket.** A fleet
+box reads releases and status, and writes heartbeats, through the console's
+edge (`/store/o/...`) with the tunnel token it already dials in with. The
+door checks the token and limits the box to its own fleet and apps.
-The variable still exists for **grandfathered direct-S3 boxes** — ones
-still running the pre-#73 agent, or deliberately kept off the fleet API —
-which need RW straight on the deployment bucket exactly as before; set
-`deployment_bucket_arn` explicitly for those and the module emits the
-extra scoped statement (`aws_iam_user_policy.host_deployment_bucket`) on
-top of the always-present own-data-bucket grant.
+The module used to grant read and write on the whole deployment bucket when
+`deployment_bucket_arn` was set, for boxes on the pre-fleet-API agent. That
+let a box rewrite any instance record in the bucket (#1007), so the grant is
+gone. The variable stays only to fail a plan that still sets it. If your
+root sets it: remove it, and move the box to the fleet door
+(`CARLOS_TUNNEL_URL` and `CARLOS_TUNNEL_TOKEN`, no
+`CARLOS_DEPLOYMENT_BUCKET`).
+
+**`access_key_status`** (`Active` by default) switches the host's access
+key off without destroying it. Once you deactivate a key by hand, set this
+to `Inactive` in your root, or the next apply turns the key back on.
The S3 action list in the inline policy is not independently chosen: it is
copied verbatim from `infra/modules/region-host/main.tf`'s
diff --git a/infra/modules/region-remote-host/main.tf b/infra/modules/region-remote-host/main.tf
index 322fbee8d..95cca5593 100644
--- a/infra/modules/region-remote-host/main.tf
+++ b/infra/modules/region-remote-host/main.tf
@@ -4,10 +4,12 @@
#
# Residency is enforced the same way as region-host: the principal reaches
# ITS OWN region's data bucket and nothing else. A wrong-region host fails
-# loudly at the IAM layer, same property as every cloud host. The deployment
-# bucket is grandfathered-optional (var.deployment_bucket_arn, default "")
-# — a fleet-API box needs no platform-bucket grant at all; see the
-# aws_iam_user_policy.host_deployment_bucket comment below.
+# loudly at the IAM layer, same property as every cloud host. The principal
+# gets nothing on the platform's deployment bucket: a fleet box reaches it
+# through the fleet door with its tunnel token (#73). The direct-S3 grant
+# this module used to offer let a box write any deployment record (#1007);
+# var.deployment_bucket_arn now only exists to refuse a root that still
+# sets it.
#
# The data bucket follows the deployment-buckets convention for this class
# of bucket (infra/modules/README.md, infra/modules/deployment-buckets/
@@ -86,7 +88,8 @@ resource "aws_iam_user" "host" {
}
resource "aws_iam_access_key" "host" {
- user = aws_iam_user.host.name
+ user = aws_iam_user.host.name
+ status = var.access_key_status
}
# Scope: THIS region's data bucket, always — wrong-region-fails-at-IAM, same
@@ -156,33 +159,3 @@ resource "aws_iam_user_policy" "host" {
)
})
}
-
-# Deployment-bucket grant: GRANDFATHERED, direct-S3 boxes only. A fleet-API
-# box (issue #73) never needs this — it reaches the platform's deployment
-# bucket through the console's edge, over the same tunnel token it dials
-# with, so var.deployment_bucket_arn is left "" and this whole statement
-# (and the IAM policy resource carrying it) is omitted. count, not a dynamic
-# block, matches the same optional-statement pattern used by
-# aws_iam_role_policy.host_route53 in the region-host module.
-resource "aws_iam_user_policy" "host_deployment_bucket" {
- count = var.deployment_bucket_arn != "" ? 1 : 0
- name = "carlos-remote-host-${var.region_code}-deployment-bucket"
- user = aws_iam_user.host.name
- policy = jsonencode({
- Version = "2012-10-17"
- Statement = [
- {
- Sid = "DeploymentBucketObjects"
- Effect = "Allow"
- Action = ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"]
- Resource = ["${var.deployment_bucket_arn}/*"]
- },
- {
- Sid = "DeploymentBucketList"
- Effect = "Allow"
- Action = ["s3:ListBucket", "s3:GetBucketLocation"]
- Resource = [var.deployment_bucket_arn]
- },
- ]
- })
-}
diff --git a/infra/modules/region-remote-host/tests/no_deployment_bucket.tftest.hcl b/infra/modules/region-remote-host/tests/no_deployment_bucket.tftest.hcl
new file mode 100644
index 000000000..404221b0c
--- /dev/null
+++ b/infra/modules/region-remote-host/tests/no_deployment_bucket.tftest.hcl
@@ -0,0 +1,72 @@
+# Platform #1007: the module never grants the host anything on the platform's
+# deployment bucket, and a root that still sets deployment_bucket_arn is
+# refused rather than silently ignored. The key status is pinnable so an
+# apply cannot turn a switched-off key back on.
+
+mock_provider "aws" {
+ mock_resource "aws_s3_bucket" {
+ defaults = {
+ arn = "arn:aws:s3:::data"
+ }
+ }
+}
+
+variables {
+ region_code = "uk"
+ data_bucket_name = "data"
+}
+
+run "policy_reaches_only_its_own_bucket" {
+ command = plan
+
+ assert {
+ condition = alltrue(flatten([
+ for s in jsondecode(aws_iam_user_policy.host.policy).Statement : [
+ for r in flatten([s.Resource]) : r == "arn:aws:s3:::data" || r == "arn:aws:s3:::data/*"
+ ]
+ ]))
+ error_message = "with no siblings, every statement must name only the host's own data bucket"
+ }
+}
+
+run "deployment_bucket_arn_is_refused" {
+ command = plan
+
+ variables {
+ deployment_bucket_arn = "arn:aws:s3:::carlos-platform"
+ }
+
+ expect_failures = [var.deployment_bucket_arn]
+}
+
+run "access_key_defaults_active" {
+ command = plan
+
+ assert {
+ condition = aws_iam_access_key.host.status == "Active"
+ error_message = "the access key must default to Active"
+ }
+}
+
+run "access_key_can_be_pinned_inactive" {
+ command = plan
+
+ variables {
+ access_key_status = "Inactive"
+ }
+
+ assert {
+ condition = aws_iam_access_key.host.status == "Inactive"
+ error_message = "access_key_status must set the key's status"
+ }
+}
+
+run "access_key_status_refuses_other_values" {
+ command = plan
+
+ variables {
+ access_key_status = "active"
+ }
+
+ expect_failures = [var.access_key_status]
+}
diff --git a/infra/modules/region-remote-host/variables.tf b/infra/modules/region-remote-host/variables.tf
index 0dfa71070..edc232aab 100644
--- a/infra/modules/region-remote-host/variables.tf
+++ b/infra/modules/region-remote-host/variables.tf
@@ -9,9 +9,25 @@ variable "data_bucket_name" {
}
variable "deployment_bucket_arn" {
- description = "ARN of the existing deployment bucket the host reads releases/status from and writes heartbeats to. Optional (default \"\"): a fleet-API box (fleet API surface, issue #73) reaches the platform's deployment bucket over the console's edge with its tunnel token, not a direct IAM grant — leave this unset and no deployment-bucket statement is emitted. Only a grandfathered direct-S3 box needs it set."
+ description = "Removed (#1007). Must stay unset. The module no longer grants any access to the platform's deployment bucket: a fleet box reads releases and writes heartbeats through the fleet door with its tunnel token."
type = string
default = ""
+
+ validation {
+ condition = var.deployment_bucket_arn == ""
+ error_message = "deployment_bucket_arn is no longer supported (#1007): it gave the box write access to every record in the deployment bucket. Remove it from your root, and move the box to the fleet door: set CARLOS_TUNNEL_URL and CARLOS_TUNNEL_TOKEN, and unset CARLOS_DEPLOYMENT_BUCKET."
+ }
+}
+
+variable "access_key_status" {
+ description = "Status of the host's access key: Active (the default) or Inactive. Set Inactive to switch a key off without destroying it, so a later apply cannot quietly turn it back on."
+ type = string
+ default = "Active"
+
+ validation {
+ condition = contains(["Active", "Inactive"], var.access_key_status)
+ error_message = "access_key_status must be Active or Inactive."
+ }
}
variable "sibling_staging_arns" {
diff --git a/internal/console/accountfleet_test.go b/internal/console/accountfleet_test.go
index 975295770..825d26a52 100644
--- a/internal/console/accountfleet_test.go
+++ b/internal/console/accountfleet_test.go
@@ -406,12 +406,12 @@ func TestFleetBYOPageMemberReadable(t *testing.T) {
t.Fatalf("BYO page missing %q in:\n%s", want, body)
}
}
- // The primary env contract is bucketless: no platform-bucket var or
- // credential belongs there (the box reaches releases/heartbeats through
- // the console's edge with its tunnel token). CARLOS_DEPLOYMENT_BUCKET
- // still appears, but only inside the demoted legacy-direct-S3 note.
- if !strings.Contains(body, "Legacy direct-S3") {
- t.Fatalf("BYO page missing the legacy direct-S3 note in:\n%s", body)
+ // The env contract is bucketless: no platform-bucket var or credential
+ // belongs there (the box reaches releases/heartbeats through the
+ // console's edge with its tunnel token). The direct-S3 path is closed
+ // (#1007), so the page must not offer it any more.
+ if strings.Contains(body, "Legacy direct-S3") || strings.Contains(body, "grandfathered") {
+ t.Fatalf("BYO page still offers the closed direct-S3 path in:\n%s", body)
}
}
diff --git a/internal/console/templates/fleet_byo.html b/internal/console/templates/fleet_byo.html
index 52a05cb23..4746ebfa3 100644
--- a/internal/console/templates/fleet_byo.html
+++ b/internal/console/templates/fleet_byo.html
@@ -51,13 +51,6 @@ in with — not a bucket-level AWS grant.</p>
defaults to this on its own; set it explicitly only if you're pointing status/heartbeats
somewhere non-standard.</p>
-<h3>Legacy direct-S3 (grandfathered)</h3>
-<p class="small">A box still running a pre-fleet-API agent build needs
-<code>CARLOS_DEPLOYMENT_BUCKET</code> set to the platform's own deployment bucket, plus an AWS
-credential granting it RW there, in addition to the hibernate-bucket vars above. New boxes should
-not be configured this way — it is kept working for boxes that haven't upgraded yet, not as a
-choice.</p>
-
<h2>Hardening</h2>
<ul>
<li>Run the agent as a dedicated non-root user, not root.</li>
diff --git a/internal/provision/remote_host_module_test.go b/internal/provision/remote_host_module_test.go
new file mode 100644
index 000000000..1e871e0df
--- /dev/null
+++ b/internal/provision/remote_host_module_test.go
@@ -0,0 +1,61 @@
+package provision
+
+import (
+ "regexp"
+ "strings"
+ "testing"
+)
+
+// #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; the module's
+// own tofu tests (tests/no_deployment_bucket.tftest.hcl) check the plan.
+func TestRegionRemoteHostGrantsNoDeploymentBucket(t *testing.T) {
+ main := string(groupGuardFile(t, "infra/modules/region-remote-host/main.tf"))
+ vars := string(groupGuardFile(t, "infra/modules/region-remote-host/variables.tf"))
+ code := stripHCLComments(main)
+
+ // One IAM policy, the host's own. Any other way of attaching
+ // permissions to the user is a new grant this guard has not read.
+ policies := regexp.MustCompile(`(?m)^resource\s+"(aws_iam_[a-z_]*polic[a-z_]*|aws_iam_user_group_membership|aws_iam_group[a-z_]*)"\s+"([^"]+)"`).FindAllStringSubmatch(code, -1)
+ if len(policies) != 1 || policies[0][1] != "aws_iam_user_policy" || policies[0][2] != "host" {
+ t.Fatalf("region-remote-host must carry exactly one IAM policy, aws_iam_user_policy.host; found %v", policies)
+ }
+
+ // Every Resource names the host's own data bucket, or a sibling
+ // staging bucket's moves/ prefix (the arn loop variable).
+ resources := regexp.MustCompile(`(?m)^\s*Resource\s*=\s*(.+)$`).FindAllStringSubmatch(code, -1)
+ if len(resources) == 0 {
+ t.Fatal("no Resource lines found; the policy shape changed, update this guard")
+ }
+ allowed := map[string]bool{
+ `["${aws_s3_bucket.data.arn}/*"]`: true,
+ `[aws_s3_bucket.data.arn]`: true,
+ `"${arn}/moves/*"`: true,
+ `arn`: true,
+ }
+ for _, r := range resources {
+ if v := strings.TrimSpace(r[1]); !allowed[v] {
+ t.Errorf("region-remote-host grants on %s; it may name only its own data bucket or a sibling's moves/ prefix (#1007)", v)
+ }
+ }
+
+ if strings.Contains(code, "var.deployment_bucket_arn") {
+ t.Error("main.tf must not use var.deployment_bucket_arn (#1007)")
+ }
+ if !regexp.MustCompile(`condition\s*=\s*var\.deployment_bucket_arn\s*==\s*""`).MatchString(vars) {
+ t.Error(`variables.tf must refuse a non-empty deployment_bucket_arn (condition = var.deployment_bucket_arn == "")`)
+ }
+}
+
+func stripHCLComments(s string) string {
+ var out strings.Builder
+ for _, line := range strings.Split(s, "\n") {
+ if t := strings.TrimSpace(line); strings.HasPrefix(t, "#") || strings.HasPrefix(t, "//") {
+ continue
+ }
+ out.WriteString(line + "\n")
+ }
+ return out.String()
+}