carlos / platform Public

region-host: store_write_credentials switch for the store boundary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b6f32ecb871b00d5661d6ea7dc2f9775fa910858 parent 18fba0f
3 files changed, +127 −3
  • infra/modules/region-host/main.tf +22 −3
  • infra/modules/region-host/tests/store_write_credentials.tftest.hcl +99 −0
  • infra/modules/region-host/variables.tf +6 −0
diff --git a/infra/modules/region-host/main.tf b/infra/modules/region-host/main.tf
index 3397290d7..9976bbcd1 100644
--- a/infra/modules/region-host/main.tf
+++ b/infra/modules/region-host/main.tf
@@ -157,6 +157,10 @@ resource "aws_iam_role" "host" {
)
error_message = "group mode requires an explicit VPC and group configuration, scoped SSM and steering, and no fixed subnet, custom user data, relay, or console settings"
}
+ precondition {
+ condition = !var.store_write_credentials || var.store_bucket_prefix != ""
+ error_message = "store_write_credentials needs store_bucket_prefix: with no prefix there are no object stores on this deployment to write to, and the grant would name every bucket in the account."
+ }
}
name = var.iam_name
assume_role_policy = jsonencode({
@@ -825,8 +829,17 @@ data "aws_caller_identity" "current" {}
# prefix that matches that bucket: a store user's inline policy names its one
# bucket, and both actions act only on an upload in progress, never on a
# finished object.
+#
+# store_write_credentials adds what a store's writer user needs (store write
+# credential spec, 2026-11-25, §7): the two multipart actions, as
+# store_conversion does, and GetFederationToken for session names under
+# carlos-write- in this account. Every store user and managed fleet user is
+# under this boundary too, but their inline policies grant no STS, so only a
+# writer can mint. With store_conversion off, existing app keys do gain the
+# two multipart actions their inline policy already asks for, on their own
+# bucket. With the switch off the document renders exactly as before.
locals {
- store_boundary_statements = [
+ store_boundary_statements = concat([
{
Effect = "Allow"
Action = ["s3:ListBucket", "s3:GetBucketLocation"]
@@ -836,11 +849,17 @@ locals {
Effect = "Allow"
Action = concat(
["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
- var.store_conversion ? ["s3:AbortMultipartUpload", "s3:ListMultipartUploadParts"] : [],
+ var.store_conversion || var.store_write_credentials ? ["s3:AbortMultipartUpload", "s3:ListMultipartUploadParts"] : [],
)
Resource = "arn:aws:s3:::${var.store_bucket_prefix}*/*"
},
- ]
+ ], var.store_write_credentials ? [
+ {
+ Effect = "Allow"
+ Action = ["sts:GetFederationToken"]
+ Resource = "arn:aws:sts::${data.aws_caller_identity.current.account_id}:federated-user/carlos-write-*"
+ },
+ ] : [])
}
resource "aws_iam_policy" "store_user_boundary" {
diff --git a/infra/modules/region-host/tests/store_write_credentials.tftest.hcl b/infra/modules/region-host/tests/store_write_credentials.tftest.hcl
new file mode 100644
index 000000000..357b06b38
--- /dev/null
+++ b/infra/modules/region-host/tests/store_write_credentials.tftest.hcl
@@ -0,0 +1,99 @@
+# Plan-time tests for the write credentials grant (store write credential
+# spec, 2026-11-25, §7). mock_provider means no AWS account and no
+# credentials: these assert what the module WOULD create.
+mock_provider "aws" {}
+
+override_data {
+ target = data.aws_vpcs.default
+ values = { ids = ["vpc-0aaaaaaaaaaaaaaaa"] }
+}
+
+override_data {
+ target = data.aws_caller_identity.current
+ values = { account_id = "123456789012" }
+}
+
+# The termination queue's ARN feeds an EventBridge target, which the provider
+# validates as an ARN; the mock's random string is not one.
+override_resource {
+ target = aws_sqs_queue.terminations
+ values = { arn = "arn:aws:sqs:eu-west-1:123456789012:carlos-test-host-terminations" }
+}
+
+override_resource {
+ target = aws_iam_policy.host_store_conversion
+ values = { arn = "arn:aws:iam::123456789012:policy/carlos-test-host-store-conversion" }
+}
+
+variables {
+ name = "carlos-test-ie"
+ sg_description = "carlos test host"
+ iam_name = "carlos-test-host"
+ instance_type = "t4g.small"
+ root_volume_size = 20
+ user_data = "#!/bin/sh\n"
+ deployment_bucket_arn = "arn:aws:s3:::carlos-test-platform"
+ data_bucket_arn = "arn:aws:s3:::carlos-test-ie"
+ ssm_parameter_arn = "arn:aws:ssm:eu-west-1:123456789012:parameter/carlos/*"
+ store_bucket_prefix = "carlos-test-store-"
+}
+
+# Off, the boundary must render the very bytes it rendered before the switch
+# existed: every store user in the account is bound to this document.
+run "off_by_default" {
+ command = plan
+ assert {
+ condition = aws_iam_policy.store_user_boundary[0].policy == "{\"Statement\":[{\"Action\":[\"s3:ListBucket\",\"s3:GetBucketLocation\"],\"Effect\":\"Allow\",\"Resource\":\"arn:aws:s3:::carlos-test-store-*\"},{\"Action\":[\"s3:GetObject\",\"s3:PutObject\",\"s3:DeleteObject\"],\"Effect\":\"Allow\",\"Resource\":\"arn:aws:s3:::carlos-test-store-*/*\"}],\"Version\":\"2012-10-17\"}"
+ error_message = "with store_write_credentials off the boundary must stay byte for byte what it was"
+ }
+}
+
+# On, without store_conversion: the multipart pair and GetFederationToken for
+# carlos-write- session names in this account, and nothing else new. The
+# console role gets no new policy.
+run "on_adds_sts_and_the_multipart_pair" {
+ command = plan
+ variables {
+ store_write_credentials = true
+ }
+ assert {
+ condition = aws_iam_policy.store_user_boundary[0].policy == "{\"Statement\":[{\"Action\":[\"s3:ListBucket\",\"s3:GetBucketLocation\"],\"Effect\":\"Allow\",\"Resource\":\"arn:aws:s3:::carlos-test-store-*\"},{\"Action\":[\"s3:GetObject\",\"s3:PutObject\",\"s3:DeleteObject\",\"s3:AbortMultipartUpload\",\"s3:ListMultipartUploadParts\"],\"Effect\":\"Allow\",\"Resource\":\"arn:aws:s3:::carlos-test-store-*/*\"},{\"Action\":[\"sts:GetFederationToken\"],\"Effect\":\"Allow\",\"Resource\":\"arn:aws:sts::123456789012:federated-user/carlos-write-*\"}],\"Version\":\"2012-10-17\"}"
+ error_message = "store_write_credentials must add exactly the multipart pair and GetFederationToken for carlos-write- sessions"
+ }
+ assert {
+ condition = length(aws_iam_policy.host_store_conversion) == 0
+ error_message = "store_write_credentials must not switch on the conversion grant"
+ }
+ assert {
+ condition = !strcontains(aws_iam_role_policy.host_store[0].policy, "sts:")
+ error_message = "the console role gets no STS permission: the writer, not the role, calls GetFederationToken"
+ }
+}
+
+# With store_conversion too, the multipart pair appears once.
+run "on_with_conversion" {
+ command = plan
+ variables {
+ store_write_credentials = true
+ store_conversion = true
+ }
+ assert {
+ condition = jsondecode(aws_iam_policy.store_user_boundary[0].policy).Statement[1].Action == [
+ "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts",
+ ]
+ error_message = "with both switches the object statement lists the multipart pair once"
+ }
+ assert {
+ condition = length(jsondecode(aws_iam_policy.store_user_boundary[0].policy).Statement) == 3
+ error_message = "with both switches the boundary has the two store statements and the STS one"
+ }
+}
+
+run "refused_without_a_store_prefix" {
+ command = plan
+ variables {
+ store_write_credentials = true
+ store_bucket_prefix = ""
+ }
+ expect_failures = [aws_iam_role.host]
+}
diff --git a/infra/modules/region-host/variables.tf b/infra/modules/region-host/variables.tf
index 750f91806..e6f0416ab 100644
--- a/infra/modules/region-host/variables.tf
+++ b/infra/modules/region-host/variables.tf
@@ -312,6 +312,12 @@ variable "store_versioning" {
default = false
}
+variable "store_write_credentials" {
+ description = "Let stores issue write credentials: temporary credentials that can only upload under one folder of a store, for a service such as a LiveKit recorder. Adds GetFederationToken for session names under carlos-write- and the two multipart actions to the store user boundary; only a store's writer user, which never holds a lasting key, has an inline policy that uses them. Off by default: the boundary does not change. The console role gets no new permissions either way. Set it only with store_bucket_prefix, together with CARLOS_STORE_WRITE_CREDENTIALS=1 on the console."
+ type = bool
+ default = false
+}
+
variable "relay" {
description = "Open the platform STUN/TURN relay's ports (udp+tcp 3478, udp 49152-65535). Off by default; a box also needs /etc/carlos/relay-masters before the unit starts."
type = bool