| 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] |
| +} |