Skip to content

ttl-reaper: cross-account trust names a CFN-generated role ARN suffix — recreating the stack breaks EVERY account at once (#457 trap 1) #476

Closed

Description

@scttfrdmn

Every customer account's trust policy names the reaper's execution role by an ARN containing a CloudFormation-generated physical ID:

arn:aws:iam::966362334030:role/spawn-ttl-reaper-production-TTLReaperFunctionRole-ZJ84YZ2dCPei
                                                                                 ^^^^^^^^^^^^

Recreating the spawn-ttl-reaper-production stack regenerates that suffix. Every trust policy referencing the old ARN then denies, simultaneously, across every account.

Why it is worse than it sounds

This is #457 trap 1, and #469 documented the consequence precisely: from the reaper's side, "our role ARN changed" is indistinguishable from "the entire customer base uninstalled at once." #469's per-account aggregation means each broken account contributes 1 to AccountsDenied, and REAPER REACHED NO ACCOUNTS fires — which is the correct signal, but the operator sees a mass-uninstall shape and has to already know about this trap to look at the role ARN first. (The README's alarm table says "investigate our side first — the #457 role-ARN suffix" for exactly this reason.)

Recovery is O(number of accounts) and needs admin in each: every account must redeploy ttl-reaper-cross-account-role.yaml with the new ARN. For third-party accounts that means asking each owner. There is no way to fix it from the infra account alone.

Now affecting 2 accounts, not 1

  • 435415984226 (Mycelium Development)
  • 942542972736 — added 2026-07-31

Each account added multiplies the blast radius. Fixing this gets strictly more expensive over time and is cheapest now.

Proposed fix

Give the function role a stable, explicit name so its ARN is deterministic and stack-recreation-safe:

TTLReaperFunctionRole:
  Properties:
    RoleName: !Sub 'spawn-ttl-reaper-${Environment}-role'

Requires CAPABILITY_NAMED_IAM (the Makefile currently passes only CAPABILITY_IAM) and blocks a no-downtime rename, since the role cannot be renamed in place. Migration is the careful part and must not lock us out mid-flight:

  1. Add the new stable-named role alongside the existing one.
  2. Have each account's trust policy accept both principals.
  3. Cut the function over to the new role; confirm AccountsDenied: 0.
  4. Drop the old principal from each account, then the old role.

A Path-based ARN or a dedicated non-SAM role stack are alternatives; the two-principal migration is the part that matters regardless of which is chosen.

Acceptance

  • The reaper's role ARN survives a full stack delete/recreate.
  • deployment/cloudformation/ttl-reaper-cross-account-role.yaml documents that the ARN is now stable.
  • Migration does not require simultaneous redeploys across accounts.

Related: #457 (trap 1), #469 (why the failure presents as mass-uninstall).

Activity

  1. added
    bug
    area:lifecycle
    area:infra
    on Jul 31, 2026
  2. scttfrdmn commented on Oct 10, 2026

    @scttfrdmn
    ContributorAuthor

    Blast radius is smaller than this issue assumes — which is the argument for fixing it now

    "breaks EVERY onboarded account at once" is currently one account. Measured:

    REAPER_ROLE_ARNS = arn:aws:iam::435415984226:role/spawn-ttl-reaper-ec2   (1 entry)
    spore-portal-accounts                                                     0 rows
    

    The reaper's own log agrees — Accounts:1.

    So the fix costs one coordinated trust-policy update today, and one per onboarded
    account
    later. The cheapest moment to do this is before the second account
    onboards
    , which reframes it from "a latent trap" to "a closing window".

    The fix: give the role a stable name

    With an explicit RoleName, deleting and recreating the stack produces the same
    name and therefore the same ARN
    , so the cross-account trust survives. That is
    the actual root cause — not the suffix itself, but that the suffix is regenerated.

    The sequencing constraint, verified rather than assumed

    The obvious plan is "add the new ARN to the trust, then switch". IAM will not
    let you
    , because it validates principals on write:

    $ aws iam create-role --role-name spawn-trust-probe-476 \
        --assume-role-policy-document '…"AWS":"arn:aws:iam::966362334030:role/spawn-ttl-reaper-DOES-NOT-EXIST-YET"…'
    MalformedPolicyDocument: Invalid principal in policy:
      "AWS":"arn:aws:iam::966362334030:role/spawn-ttl-reaper-DOES-NOT-EXIST-YET"

    (Probed in the dev account; it created nothing, confirmed with get-role →
    NoSuchEntity.)

    So the new role must exist before it can be trusted, which forces an overlap
    migration rather than a swap.

    Plan — five steps, no window where reaping is dead

    1. Template: add an explicit AWS::IAM::Role with
      RoleName: spawn-ttl-reaper-production-role, carrying the same policies SAM
      currently generates from Policies:. Do not point the function at it yet.
      Deploy → the role exists, nothing uses it.
    2. Dev account: add the new ARN to spawn-ttl-reaper-ec2's trust alongside
      the existing one. Both are now trusted.
    3. Template: point the function at the new role (Role: !GetAtt …), drop the
      Policies: block. Deploy.
    4. Verify before touching anything else: simulate-principal-policy for
      ec2:TerminateInstances with ec2:ResourceTag/spawn:managed=true from the new
      role, plus one real dry-run reaper invocation showing Accounts:1 and a
      non-zero Scanned. A dry-run that scans 0 proves nothing — that was the
      --fsx-lifecycle ephemeral did not reap the filesystem when the instance terminated (1.2 TiB left AVAILABLE and billing) #613 lesson.
    5. Remove the old principal from the dev trust, and the old role from the
      template. Deploy. Re-verify.

    Each step is independently revertible, and reaping keeps working throughout
    because step 2 precedes step 3.

    Why not the obvious alternative

    Trusting arn:aws:iam::966362334030:root with the ExternalId condition would
    dodge the chicken-and-egg entirely (root always exists) and survive any role
    recreation. It is also the AWS-documented cross-account pattern.

    Rejected because it widens the trust from "this reaper's role" to "any
    principal in the infra account presenting the ExternalId", and what that trust
    grants is ec2:TerminateInstances. A narrower trust that survives recreation is
    achievable — that is what step 1 buys — so the widening is not necessary.

    Note on the deploy mechanism

    Steps 1, 3 and 5 are ttl-reaper deploys, which means the Makefile's
    read-live-parameters-first path and a reviewed change set each time. The role
    change will show as a replacement, which is expected; what must not appear
    is any change to the DynamoDB table or the function's Code beyond the
    intentional rebuild.

  3. scttfrdmn commented on Oct 10, 2026

    @scttfrdmn
    ContributorAuthor

    Revising my own plan: step 1 is riskier than it needs to be, and there is a better fix

    I proposed giving the role a stable RoleName. Starting it, two things turned up.

    Why renaming is riskier than it looked

    SAM generates the role from a Policies: block with 5 entries and heavy
    conditional logic
    — 16 !If … AWS::NoValue occurrences in the template, and
    the live role proves they fire: its inline policies are

    TTLReaperFunctionRolePolicy0, Policy2, Policy3, Policy4
    

    Policy1 is absent — one entry is conditioned out at the current parameter
    values. So an explicit AWS::IAM::Role would have to reproduce five conditional
    policy entries by hand, on the production reaper's IAM, where a mistake either
    over-grants ec2:TerminateInstances or silently disarms reaping. That is a poor
    place to hand-transcribe conditionals.

    The better fix: make the trust pattern-matched, and change nothing in the reaper

    The root cause is not the suffix — it is that the suffix is regenerated. That
    can be absorbed on the dev side only, with no change to the reaper's template
    or IAM at all:

    {
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::966362334030:root" },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": { "sts:ExternalId": "spawn-ttl-reaper" },
        "ArnLike": {
          "aws:PrincipalArn":
            "arn:aws:iam::966362334030:role/spawn-ttl-reaper-production-TTLReaperFunctionRole-*"
        }
      }
    }
    • :root always exists, so the chicken-and-egg that forced a five-step
      overlap disappears entirely.
    • ArnLike on aws:PrincipalArn keeps it narrow — only a role matching the
      reaper's generated-name pattern, not "anything in the infra account", which is
      why I rejected bare :root earlier.
    • It survives stack recreation: the suffix changes, the pattern still matches.
    • Zero change to the production reaper, which is the whole risk.

    Verified, not assumed

    • IAM accepts the policy. The earlier named-principal attempt failed with
      MalformedPolicyDocument; this one created cleanly
      (arn:aws:iam::435415984226:role/spawn-trust-probe-476b).
    • A non-matching principal is denied. Assuming it as
      …/OrganizationAccountAccessRole/dev-admin-session — same account, wrong ARN
      pattern — returned AccessDenied. So the condition is doing work rather than
      decorating.
    • Probe role deleted, confirmed NoSuchEntity.

    What is not yet verified is the positive case: that the reaper's actual role
    still assumes successfully. That cannot be simulated from here — trust evaluation
    is not simulate-principal-policy-shaped — so it is the gate for the change
    itself, below.

    Revised plan — two steps, no overlap migration

    1. Replace the dev trust statement with the pattern form above. One account,
      one policy document, instantly revertible (keep the old document to hand).
    2. Verify with the reaper itself: a dry-run invocation must report
      Accounts:1 with a non-zero Scanned. A dry-run that scans 0 proves
      nothing — the --fsx-lifecycle ephemeral did not reap the filesystem when the instance terminated (1.2 TiB left AVAILABLE and billing) #613 lesson — so this needs at least one instance in the dev
      account, or it is inconclusive and should be treated as such.

    If step 2 fails, revert step 1 and we are back to today's state with nothing lost.

    Trade-off, stated

    The trust is now "a role in 966362334030 whose name matches
    spawn-ttl-reaper-production-TTLReaperFunctionRole-*, presenting the ExternalId"
    rather than one exact ARN. Marginally wider: another role could be named into
    that pattern by someone who can already create roles in the infra account — which
    is a principal who could equally modify the reaper. I judge that acceptable
    against hand-transcribing five conditional IAM policies on the live reaper, but
    it is a judgement and worth disagreeing with.

    The stable-RoleName route stays available and is strictly narrower; it is just
    not worth its risk today, with one onboarded account and the regeneration
    hazard removable from the other side.

  4. added 2 commits that reference this issue on Oct 10, 2026
    40db08a
    eb15992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:infraarea:lifecyclebugcomponent:spawn

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions