infra: keep oversize fleet grants inline until the inline copy retires
Upgrading without conversion must keep every fleet configuration that planned before. A fleet grant too long for a customer-managed policy (three regions, 6,720 characters) now stays inline only while managed_fleets_inline_retired is false, with no managed copy; the old inline total check guards that path as before this branch. The 6,144 check refuses only once the inline copy would be retired, which conversion with fleets on requires. The size check is the only precondition on the managed policy, so its test pins the refusal to it; the retired-path inline total moves to the attachment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+148
−23
docs/superpowers/notes/media-conversion-copy-deck.md+2 −2docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md+1 −1infra/modules/region-host/README.md+1 −1infra/modules/region-host/managed_fleets.tf+41 −16infra/modules/region-host/tests/managed_fleets/managed_fleets.tftest.hcl+103 −3
CI failed — run details
diff --git a/docs/superpowers/notes/media-conversion-copy-deck.md b/docs/superpowers/notes/media-conversion-copy-deck.md| index d66cb9511..49bd5eb89 100644 |
| --- a/docs/superpowers/notes/media-conversion-copy-deck.md |
| +++ b/docs/superpowers/notes/media-conversion-copy-deck.md |
| @@ -725,8 +725,8 @@ refusal, for whoever deploys it. |
| | `infra.region_host.store_conversion.refused_overlap` | `store_conversion refuses a store_bucket_prefix that matches the deployment, data or sibling staging buckets, because this grant can replace the CORS, lifecycle and tag settings of every bucket it matches. Choose a prefix none of those bucket names start with.` (pending Luna pass; plan 3 Task 12 fix 1) | |
| | `infra.region_host.store_conversion.refused_fleet_overlap` | `store_conversion refuses a store_bucket_prefix that overlaps managed_fleet_bucket_prefix, even with managed fleets off, because fleet buckets outlive the switch and this grant can replace the CORS, lifecycle and tag settings of every bucket it matches. Choose prefixes where neither starts with the other.` (pending Luna pass; plan 3 Task 12 fix 2) | |
| | `infra.region_host.store_conversion.refused_inline_fleets` | `store_conversion with managed fleets on needs managed_fleets_inline_retired = true, so the inline copy of the managed fleet grant stops taking up the console role's limited inline policy space. Apply once with it false to attach the managed copy, then set it true and apply again.` (pending Luna pass; plan 3 Task 12 fix 2) | |
| -| `infra.region_host.managed_fleets.refused_size` | `The managed fleet grant exceeds IAM's 6,144-character limit for a customer-managed policy. Name fewer managed fleet regions, subnets or security groups.` (pending Luna pass; plan 3 Task 12 fix 2) | |
| -| `infra.region_host.managed_fleets.refused_inline_total` | `This host role's inline policies exceed IAM's 10,240-character total. Set managed_fleets_inline_retired once the managed fleet grant is attached, or turn off a grant this host does not need.` (pending Luna pass; plan 3 Task 12 fix 2) | |
| +| `infra.region_host.managed_fleets.refused_size` | `The managed fleet grant has too many regions for a customer-managed policy (6,144 characters), so its inline copy cannot be retired yet. Set managed_fleets_inline_retired back to false, or name fewer managed fleet regions, subnets or security groups.` (pending Luna pass; plan 3 Task 12 fix 3) | |
| +| `infra.region_host.managed_fleets.refused_inline_total` | Once the inline copy is retired: `This host role's inline policies exceed IAM's 10,240-character total. Turn off a grant this host does not need.` Before: `With the managed fleet grant this host role's inline policies exceed IAM's 10,240-character total. Name fewer managed fleet regions, subnets or security groups, turn off a grant this host does not need, or retire the inline copy (managed_fleets_inline_retired).` (pending Luna pass; plan 3 Task 12 fix 3) | |
| | `infra.region_host.managed_fleets_inline_retired.description` | The `description` of `variable "managed_fleets_inline_retired"` in `infra/modules/region-host/variables.tf` (pending Luna pass; plan 3 Task 12 fix 2) | |
| | `infra.region_host.readme.managed_fleets_move` | The `Moving the managed fleet grant` section of `infra/modules/region-host/README.md`, and the fleet prefix sentences in `Media conversion and browser uploads` (pending Luna pass; plan 3 Task 12 fix 2) | |
| | `infra.media_engine.readme.console_policy` | The paragraph on the customer-managed console policy in `infra/modules/media-engine/README.md`, before `Region` (pending Luna pass; plan 3 Task 12 fix 1) | |
diff --git a/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md b/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md| index 783e1260f..3b9f569cc 100644 |
| --- a/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md |
| +++ b/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md |
| @@ -271,7 +271,7 @@ Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box s |
| **Interfaces:** |
| - Produces: `variable "store_conversion"` (bool, default false; set it with `CARLOS_STORE_CONVERSION=1` on the console); `aws_iam_policy.host_store_conversion` and `aws_iam_role_policy_attachment.host_store_conversion` (count on the switch), a customer-managed policy allowing `s3:GetBucketPolicy`, `s3:GetEncryptionConfiguration`, `s3:GetBucketVersioning`, `s3:GetBucketCORS`, `s3:PutBucketCORS`, `s3:GetLifecycleConfiguration`, `s3:PutLifecycleConfiguration`, `s3:GetBucketTagging`, `s3:PutBucketTagging` on `arn:aws:s3:::<prefix>*`, and denying `s3:PutBucketCORS`, `s3:PutLifecycleConfiguration` and `s3:PutBucketTagging` on the deployment and data buckets; the store boundary's object statement gains `s3:AbortMultipartUpload` and `s3:ListMultipartUploadParts` when the switch is on. |
| - Preconditions with the switch on: `store_bucket_prefix` is set; it is a dedicated store prefix (literal, lower-case, ending in `-store-`, such as `carlos-store-`), because no root can list every bucket a broader prefix would match; and no deployment, data or sibling staging bucket name starts with it; and it does not overlap a non-empty `managed_fleet_bucket_prefix` in either direction, whatever `managed_fleets_enabled` says, because fleet buckets outlive that switch. With managed fleets on, the switch also requires `managed_fleets_inline_retired = true`. With the switch off every prefix plans as before. |
| -- The console role's inline total: `host_analytics_prune` and `host_managed_fleets` become customer-managed attached policies with the same statements and the same switches, and `host_inline_policies` counts every inline policy this module puts on the role. The managed fleet grant moves without a gap: a temporary `managed_fleets_inline_retired` (default false) keeps the old inline copy beside the attached managed one until a second apply sets it true, and the total counts that copy while it exists. Plan-time refusals: the module's inline policies over 10,240 characters, and the managed fleet policy over 6,144 (it grows with each managed region). The complete console role, every feature on, fits; the module cannot see inline policies a root adds, which the pre-rollout check (Rollout, R0) covers. |
| +- The console role's inline total: `host_analytics_prune` and `host_managed_fleets` become customer-managed attached policies with the same statements and the same switches, and `host_inline_policies` counts every inline policy this module puts on the role. The managed fleet grant moves without a gap: a temporary `managed_fleets_inline_retired` (default false) keeps the old inline copy beside the attached managed one until a second apply sets it true, and the total counts that copy while it exists. Plan-time refusals: the module's inline policies over 10,240 characters (checked on the inline copy while it exists, then on the managed policy), and the managed fleet policy over 6,144 (it grows with each managed region) once the inline copy is retired. Until then a grant too long for a managed policy keeps working inline only, as before this change, so upgrading without conversion keeps every fleet configuration that planned before. The complete console role, every feature on, fits; the module cannot see inline policies a root adds, which the pre-rollout check (Rollout, R0) covers. |
| - [ ] **Step 1: Write the failing tftest:** off by default creates nothing and leaves the boundary byte for byte; on grants exactly those nine actions on that resource and the Deny; on adds the two multipart actions to the boundary and nothing else; on without a prefix, with a broad or wildcard prefix, with a platform bucket under the prefix, or with a fleet prefix overlapping it in either direction (fleets off included) fails its precondition; on with fleets on and the inline copy not retired fails; off accepts every prefix as before, with fleets off and on; the complete console role fits IAM's quotas and reports its inline total; extra policy text over the inline total, and a managed fleet policy over 6,144 characters, are refused at plan. |
| - [ ] **Step 2:** Run `cd infra/modules/region-host && tofu init -backend=false && tofu test -filter=tests/store_conversion.tftest.hcl`. Expected: FAIL. |
diff --git a/infra/modules/region-host/README.md b/infra/modules/region-host/README.md| index b521ae44a..f16c4708a 100644 |
| --- a/infra/modules/region-host/README.md |
| +++ b/infra/modules/region-host/README.md |
| @@ -123,7 +123,7 @@ The managed fleet grant is a customer-managed policy attached to the console’s |
| `store_conversion` with managed fleets on is refused until step 2. `managed_fleets_inline_retired` is temporary, and goes once every root has set it. |
| -A customer-managed policy holds at most 6,144 characters, which is about two managed regions; with more, the plan fails. The plan also fails if this module’s inline policies on the role pass 10,240 characters. It cannot see inline policies your root adds to the same role, so if you add any, check the role’s total yourself. |
| +A customer-managed policy holds at most 6,144 characters, which is about two managed regions. With more, the module keeps the inline copy only, as before this change, and refuses `managed_fleets_inline_retired = true` (and so `store_conversion` with managed fleets on) until the grant fits. The plan also fails if this module’s inline policies on the role pass 10,240 characters. It cannot see inline policies your root adds to the same role, so if you add any, check the role’s total yourself. |
| ## Checking it worked |
diff --git a/infra/modules/region-host/managed_fleets.tf b/infra/modules/region-host/managed_fleets.tf| index 29b4938a3..018553b71 100644 |
| --- a/infra/modules/region-host/managed_fleets.tf |
| +++ b/infra/modules/region-host/managed_fleets.tf |
| @@ -284,11 +284,12 @@ locals { |
| Version = "2012-10-17" |
| Statement = local.managed_console_statements |
| }) |
| - # Every other inline policy on this role. IAM caps their total at 10,240 |
| - # characters without whitespace (jsonencode writes none), and the console |
| - # host already carries most of them. A new inline policy on this role |
| - # belongs here; customer-managed policies do not count toward the total. |
| - host_inline_policies = concat( |
| + # Every inline policy this module puts on the role, the fleet grant's inline |
| + # copy apart. IAM caps their total at 10,240 characters without whitespace |
| + # (jsonencode writes none), and the console host already carries most of |
| + # them. A new inline policy on this role belongs here; customer-managed |
| + # policies do not count toward the total. |
| + host_inline_policies_other = concat( |
| [aws_iam_role_policy.host_buckets.policy, aws_iam_role_policy.host_metrics.policy, aws_iam_role_policy.host_terminations.policy], |
| aws_iam_role_policy.host_route53[*].policy, aws_iam_role_policy.host_ingress_drain[*].policy, |
| aws_iam_role_policy.host_steering[*].policy, aws_iam_role_policy.host_costexplorer[*].policy, |
| @@ -296,8 +297,9 @@ locals { |
| aws_iam_role_policy.host_release_key_deny[*].policy, aws_iam_role_policy.host_store[*].policy, |
| aws_iam_role_policy.host_console_mail[*].policy, aws_iam_role_policy.host_store_scan[*].policy, |
| aws_iam_role_policy.alert_publish[*].policy, aws_iam_role_policy.group[*].policy, |
| - aws_iam_role_policy.host_managed_fleets[*].policy, |
| ) |
| + # All of them, the inline fleet copy included while it exists. |
| + host_inline_policies = concat(local.host_inline_policies_other, aws_iam_role_policy.host_managed_fleets[*].policy) |
| } |
| # The console grant is a customer-managed policy attached to the role, so it |
| @@ -308,30 +310,44 @@ locals { |
| # the old inline copy and attaches the managed one beside it, so the first |
| # apply only adds. Setting it true removes the inline copy. The inline total |
| # counts that copy while it exists. |
| +# |
| +# A grant too long for a managed policy (more regions than about two) works as |
| +# it did before this change while the input is false: inline copy only, no |
| +# managed copy. It is refused only once the inline copy would be retired. |
| +locals { |
| + managed_fleets_policy_fits = length(local.managed_console_policy) <= 6144 |
| + host_managed_fleets_copy = var.managed_fleets_enabled && (local.managed_fleets_policy_fits || var.managed_fleets_inline_retired) |
| +} |
| + |
| resource "aws_iam_policy" "host_managed_fleets" { |
| - count = var.managed_fleets_enabled ? 1 : 0 |
| + count = local.host_managed_fleets_copy ? 1 : 0 |
| name = "${var.iam_name}-managed-fleets" |
| policy = local.managed_console_policy |
| lifecycle { |
| # Fail the plan, not the middle of an apply. Unknown lengths (a policy |
| # naming a resource this apply creates) are checked at apply instead. |
| + # The only check on this resource, so a test can pin a refusal to it. |
| precondition { |
| - condition = length(local.managed_console_policy) <= 6144 |
| - error_message = "The managed fleet grant exceeds IAM's 6,144-character limit for a customer-managed policy. Name fewer managed fleet regions, subnets or security groups." |
| - } |
| - # Only this module's inline policies: a root that puts its own inline |
| - # policy on this role must check the role's total itself. |
| - precondition { |
| - condition = sum([for p in local.host_inline_policies : length(p)]) <= 10240 |
| - error_message = "This host role's inline policies exceed IAM's 10,240-character total. Set managed_fleets_inline_retired once the managed fleet grant is attached, or turn off a grant this host does not need." |
| + condition = local.managed_fleets_policy_fits |
| + error_message = "The managed fleet grant has too many regions for a customer-managed policy (6,144 characters), so its inline copy cannot be retired yet. Set managed_fleets_inline_retired back to false, or name fewer managed fleet regions, subnets or security groups." |
| } |
| } |
| } |
| resource "aws_iam_role_policy_attachment" "host_managed_fleets" { |
| - count = var.managed_fleets_enabled ? 1 : 0 |
| + count = local.host_managed_fleets_copy ? 1 : 0 |
| role = aws_iam_role.host.name |
| policy_arn = aws_iam_policy.host_managed_fleets[0].arn |
| + lifecycle { |
| + # Once the inline copy is retired the total is checked here; before |
| + # that, on the inline copy. Only this module's inline policies: a root |
| + # that puts its own inline policy on this role must check the role's |
| + # total itself. |
| + precondition { |
| + condition = !var.managed_fleets_inline_retired || sum([for p in local.host_inline_policies : length(p)]) <= 10240 |
| + error_message = "This host role's inline policies exceed IAM's 10,240-character total. Turn off a grant this host does not need." |
| + } |
| + } |
| } |
| # The inline copy, kept until managed_fleets_inline_retired. Temporary: it |
| @@ -341,4 +357,13 @@ resource "aws_iam_role_policy" "host_managed_fleets" { |
| name = "${var.iam_name}-managed-fleets" |
| role = aws_iam_role.host.id |
| policy = local.managed_console_policy |
| + lifecycle { |
| + # The check this grant carried before it moved: fail the plan, not the |
| + # middle of an apply. It counts its own text and every other inline |
| + # policy, the same total as local.host_inline_policies. |
| + precondition { |
| + condition = sum(concat([length(local.managed_console_policy)], [for p in local.host_inline_policies_other : length(p)])) <= 10240 |
| + error_message = "With the managed fleet grant this host role's inline policies exceed IAM's 10,240-character total. Name fewer managed fleet regions, subnets or security groups, turn off a grant this host does not need, or retire the inline copy (managed_fleets_inline_retired)." |
| + } |
| + } |
| } |
diff --git a/infra/modules/region-host/tests/managed_fleets/managed_fleets.tftest.hcl b/infra/modules/region-host/tests/managed_fleets/managed_fleets.tftest.hcl| index 02ae53f43..151f8d4c3 100644 |
| --- a/infra/modules/region-host/tests/managed_fleets/managed_fleets.tftest.hcl |
| +++ b/infra/modules/region-host/tests/managed_fleets/managed_fleets.tftest.hcl |
| @@ -472,8 +472,10 @@ run "policy_union" { |
| } |
| # The managed fleet grant grows with each managed region. Past IAM's 6,144 |
| -# characters for a customer-managed policy the plan refuses rather than an |
| -# apply failing half-way. |
| +# characters for a customer-managed policy, retiring the inline copy is |
| +# refused at plan rather than an apply failing half-way. The size check is the |
| +# only precondition on aws_iam_policy.host_managed_fleets, so this pins the |
| +# refusal to it. |
| run "managed_fleet_policy_size_limit" { |
| command = plan |
| variables { |
| @@ -491,6 +493,104 @@ run "managed_fleet_policy_size_limit" { |
| expect_failures = [aws_iam_policy.host_managed_fleets] |
| } |
| +# Upgrading without conversion keeps every fleet configuration that planned |
| +# before: a grant too long for a managed policy stays inline only, with no |
| +# managed copy, while the inline copy is not retired. |
| +run "three_regions_without_retirement_keep_the_inline_copy" { |
| + command = plan |
| + variables { |
| + managed_fleets_enabled = true |
| + managed_fleets_regions = { |
| + for i, r in ["eu-west-1", "eu-central-1", "us-east-1"] : r => { |
| + image = "ami-0123456789abcdef${i}" |
| + subnets = ["subnet-0123456789abcde${i}0", "subnet-0123456789abcde${i}1"] |
| + security_groups = ["sg-0123456789abcde${i}0"] |
| + instance_types = ["t4g.small", "t4g.medium"] |
| + } |
| + } |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.host_managed_fleets) == 1 |
| + error_message = "a grant too long for a managed policy keeps its inline copy" |
| + } |
| + assert { |
| + condition = length(aws_iam_policy.host_managed_fleets) == 0 && length(aws_iam_role_policy_attachment.host_managed_fleets) == 0 |
| + error_message = "a grant too long for a managed policy gets no managed copy until it fits" |
| + } |
| +} |
| + |
| +# On that inline-only path the role's inline total is checked as before this |
| +# change. |
| +run "inline_only_role_inline_limit" { |
| + command = plan |
| + variables { |
| + managed_fleets_enabled = true |
| + managed_fleets_regions = { |
| + for i, r in ["eu-west-1", "eu-central-1", "us-east-1"] : r => { |
| + image = "ami-0123456789abcdef${i}" |
| + subnets = ["subnet-0123456789abcde${i}0", "subnet-0123456789abcde${i}1"] |
| + security_groups = ["sg-0123456789abcde${i}0"] |
| + instance_types = ["t4g.small", "t4g.medium"] |
| + } |
| + } |
| + store_bucket_prefix = "carlos-store-" |
| + store_scanning = true |
| + enable_cost_explorer = true |
| + enable_analytics_version_prune = true |
| + console_mail_from = "noreply@example.com" |
| + console_mail_region = "eu-west-1" |
| + route53_zone_ids = ["Z0123456789ABCDEFGHIJ"] |
| + steering_zone_ids = ["Z0123456789ABCDEFGHIJ"] |
| + steering_record_names = ["*.example.com"] |
| + alerts_email = "ops@example.com" |
| + } |
| + expect_failures = [aws_iam_role_policy.host_managed_fleets] |
| +} |
| + |
| +# Two regions fit a managed policy, so they take the two-apply path. |
| +run "two_regions_first_apply_adds_the_managed_copy" { |
| + command = plan |
| + variables { |
| + managed_fleets_enabled = true |
| + managed_fleets_regions = { |
| + for i, r in ["eu-west-1", "us-east-1"] : r => { |
| + image = "ami-0123456789abcdef${i}" |
| + subnets = ["subnet-0123456789abcde${i}0", "subnet-0123456789abcde${i}1"] |
| + security_groups = ["sg-0123456789abcde${i}0"] |
| + instance_types = ["t4g.small", "t4g.medium"] |
| + } |
| + } |
| + } |
| + assert { |
| + condition = ( |
| + length(aws_iam_role_policy.host_managed_fleets) == 1 && |
| + length(aws_iam_role_policy_attachment.host_managed_fleets) == 1 && |
| + aws_iam_policy.host_managed_fleets[*].policy == aws_iam_role_policy.host_managed_fleets[*].policy |
| + ) |
| + error_message = "with two regions the first apply keeps the inline copy and attaches the same text as a managed policy" |
| + } |
| +} |
| + |
| +run "two_regions_second_apply_retires_the_inline_copy" { |
| + command = plan |
| + variables { |
| + managed_fleets_enabled = true |
| + managed_fleets_inline_retired = true |
| + managed_fleets_regions = { |
| + for i, r in ["eu-west-1", "us-east-1"] : r => { |
| + image = "ami-0123456789abcdef${i}" |
| + subnets = ["subnet-0123456789abcde${i}0", "subnet-0123456789abcde${i}1"] |
| + security_groups = ["sg-0123456789abcde${i}0"] |
| + instance_types = ["t4g.small", "t4g.medium"] |
| + } |
| + } |
| + } |
| + assert { |
| + condition = length(aws_iam_role_policy.host_managed_fleets) == 0 && length(aws_iam_policy.host_managed_fleets) == 1 && length(aws_iam_role_policy_attachment.host_managed_fleets) == 1 |
| + error_message = "with two regions the second apply leaves only the attached managed copy" |
| + } |
| +} |
| + |
| # Extra policy text, here many sibling staging buckets in the bucket grant, |
| # takes the role's inline policies over IAM's 10,240-character total, and the |
| # plan refuses. |
| @@ -521,7 +621,7 @@ run "role_inline_limit" { |
| ingress_target_group_arns = ["arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/carlos-test/0123456789abcdef"] |
| sibling_staging_arns = [for i in range(17) : "arn:aws:s3:::carlos-test-sibling-${i}"] |
| } |
| - expect_failures = [aws_iam_policy.host_managed_fleets] |
| + expect_failures = [aws_iam_role_policy_attachment.host_managed_fleets] |
| } |
| # The first apply after upgrading: the inline copy is still there, and the |