Skip to content

fix(bootstrap): least-privilege policies deny all nested-stack resources — default-on Agent Registry cannot deploy without AdministratorAccess #865

Closed

Description

@vivibui

Component: cdk (bootstrap policies)

Describe the bug

The least-privilege bootstrap policies scope every resource ARN to the parent stack's name prefix (backgroundagent-dev-*). Resources created inside nested stacks do not carry that prefix in their generated physical names, so the CFN execution role is denied on all of them.

The Agent Registry is default-on (enableAgentRegistry !== false, cdk/src/stacks/agent.ts:115-128) and contributes two nested stacks — AgentRegistryStack and RegistryApi. So on a clean account with default context, mise //cdk:deploy cannot succeed with the repo's own least-privilege bootstrap.

This is not one missing action; it is a whole class of denials.

Expected behavior

A default-context deploy (Agent Registry enabled) succeeds against the least-privilege bootstrap, with no AdministratorAccess attached to cdk-hnb659fds-cfn-exec-role-*.

Current behavior

Two distinct denials, hit in sequence:

1. iam:PassRole on the exec role itself. Creating any nested stack makes CloudFormation pass the execution role to itself. No statement permits this:

User: arn:aws:sts::<acct>:assumed-role/cdk-hnb659fds-cfn-exec-role-<acct>-us-east-1/AWSCloudFormation
is not authorized to perform: iam:PassRole on resource:
arn:aws:iam::<acct>:role/cdk-hnb659fds-cfn-exec-role-<acct>-us-east-1
because no identity-based policy allows the iam:PassRole action

The existing IAMPassRole statement scopes to arn:aws:iam::*:role/backgroundagent-dev-* and conditions on iam:PassedToService, which does not cover this case.

2. Resource-name mismatch inside nested stacks. After granting the above, the next failure:

User: ...AWSCloudFormation is not authorized to perform: states:CreateStateMachine on resource:
arn:aws:states:us-east-1:<acct>:stateMachine:AgentRegistryProviderwaiterstatemachineE27177B2-arZJxYWqV4wX
because no identity-based policy allows the states:CreateStateMachine action

The action is granted; the StepFunctions statement scopes it to arn:aws:states:*:*:stateMachine:backgroundagent-dev-*. The waiter state machine is named AgentRegistryProviderwaiterstatemachine… — no parent-stack prefix — so the ARN never matches.

The same prefix assumption appears across the generated policies (SNS, CloudFront, Lambda, IAM roles/policies …), so fixing only states:* would just surface the next resource type. Patching one action at a time is not viable — each cycle is an ~8-minute deploy.

Reproduction steps

  1. Fresh account; bootstrap with the least-privilege template (see fix(bootstrap): least-privilege bootstrap template exceeds CFN 51,200-byte inline limit — fresh-account bootstrap is impossible #864 for the size workaround needed to do this at all).
  2. Do not attach AdministratorAccess to the cfn-exec-role.
  3. export MISE_EXPERIMENTAL=1 && mise run //cdk:deploy -- --require-approval never with default context.
  4. Deploy reaches changeset creation, then fails on iam:PassRole. Grant that, redeploy, and it fails on states:CreateStateMachine inside the nested stack.

Possible solution

  1. Allow the exec role to pass itself, scoped to exactly that role ARN, for nested-stack creation.
  2. Stop assuming the parent-stack prefix. Nested-stack physical names are not prefixed. Either:
    • widen the affected Resource patterns to also admit nested-stack-generated names, or
    • drive scoping off a stable tag/condition (e.g. aws:ResourceTag/aws:cloudformation:stack-id) rather than a name prefix, or
    • give nested-stack constructs explicit physical names carrying the prefix, so the existing scoping holds.

The tag-condition route is the most robust — it stays genuinely least-privilege without depending on CDK's name generation, which is not a stable contract.

  1. Add coverage. A synth/policy test asserting every resource ARN in the synthesized template (including nested templates) is authorized by the generated policies would catch this class before deploy. Note cdk/test/bootstrap/synth-coverage.test.ts already exists and did not catch it.

Workaround used to get unblocked: attached AdministratorAccess to the cfn-exec-role plus an inline iam:PassRole policy. That defeats the purpose of the custom bootstrap and should not be the documented path.

Environment

Activity

  1. vivibui commented on Sep 8, 2026

    @vivibui
    ContributorAuthor

    Refined root cause — the physical name is unpredictable, not just unprefixed

    Digging further while implementing, the mechanism is narrower than "nested-stack resources lose the prefix", and it rules out the fix I suggested above.

    StateMachineName is not set in the synthesized nested template:

    backgroundagentdevAgentRegistryStackFF9DF145.nested.template.json
      logical=AgentRegistryProviderwaiterstatemachineE27177B2
      StateMachineName=null
    

    So CloudFormation generates the physical name. It normally generates <stack-name>-<logical-id>-<random>, which would carry the prefix. It doesn't here because the nested stack's own name is already ~100 characters:

    backgroundagent-dev-AgentRegistryStackNestedStackAgentRegistryStackNestedStackResource-16VAX8Y6Y64W
    

    Add the 46-character logical id and a random suffix and the result blows past the 80-character limit on Step Functions state machine names, so CFN drops the stack-name portion and emits AgentRegistryProviderwaiterstatemachineE27177B2-arZJxYWqV4wX.

    Why this matters for the fix

    The generated name is a function of CFN's truncation behaviour under a per-service name-length limit. That is not a stable contract, so no name-prefix pattern can reliably authorize it — including the "widen the pattern" option I listed in the issue body. Any pattern narrow enough to be meaningful risks breaking when a logical id or nested-stack name changes length; any pattern broad enough to be safe is effectively stateMachine:*.

    That leaves three real options, in my order of preference:

    1. Condition on the CloudFormation stack tag rather than the name. CFN applies aws:cloudformation:stack-name to supported resources on create, and — usefully — nested stack names are prefixed with the parent (backgroundagent-dev-AgentRegistryStackNestedStack…). So a StringLike condition on aws:RequestTag/aws:cloudformation:stack-name of backgroundagent-dev-* covers parent and nested resources alike, independent of physical naming. Caveat: needs per-service verification that tag-on-create is supported and that CFN passes the tag in the create call.
    2. Set explicit physical names on the affected resources so the existing scoping holds. Blocked for this specific resource: the waiter state machine is created inside aws-cdk-lib's Provider, which exposes providerFunctionName but no waiter-state-machine name override.
    3. Widen to stateMachine:* for the already-narrow action set. Pragmatic and honest, but a real reduction in the posture this bootstrap exists to provide.

    Also worth noting

    This is likely why the bug went unnoticed: a waiter state machine only exists when a custom resource uses isComplete, and the Agent Registry appears to be the first construct here that does. #831's LinearIdentityVault explicitly notes it is "synchronous, so onEvent-only, no isComplete poller" — so it never provisions one.

    I'm not submitting a fix for this one, because picking between options 1 and 3 is a security-posture decision for the maintainers rather than something to guess at, and verifying either needs real deploy cycles against a fresh account. Happy to implement whichever you prefer.

    iam:PassRole on the execution role itself (the first failure in the issue body) is separate and unambiguous — it can be fixed independently of this naming question.

  2. vivibui commented on Sep 8, 2026

    @vivibui
    ContributorAuthor

    Thanks for looking. Two of the three points don't hold up against the code, and I want to correct them here so nobody implements against the wrong mechanism — but the third is a real option I had missed, so let me take that seriously too.

    The PassRole failure is not caused by nested-stack naming

    These are two independent bugs that happen to surface in sequence during the same deploy, and merging them obscures both.

    The role being passed is the bootstrap's own execution role:

    is not authorized to perform: iam:PassRole on resource:
    arn:aws:iam::<acct>:role/cdk-hnb659fds-cfn-exec-role-<acct>-us-east-1
    

    That name is fully deterministic — cdk-${Qualifier}-cfn-exec-role-${AWS::AccountId}-${AWS::Region}, set by the bootstrap template itself. Nothing generates it, and nothing truncates it. It fails because the IAMPassRole statement is scoped to a different namespace entirely:

    - Action: iam:PassRole
      Condition:
        StringEquals:
          iam:PassedToService: [lambda.amazonaws.com, ecs-tasks.amazonaws.com, ...]
      Effect: Allow
      Resource: arn:aws:iam::*:role/backgroundagent-dev-*     # exec role is cdk-hnb659fds-*
      Sid: IAMPassRole

    cdk-hnb659fds-cfn-exec-role-… never matched role/backgroundagent-dev-*, so the pass was denied on the very first nested stack. Name generation is irrelevant to this one — and note the iam:PassedToService condition wouldn't admit it either, since the consumer here is CloudFormation itself.

    The generated-name problem is the separate failure (detailed above): states:CreateStateMachine denied on AgentRegistryProviderwaiterstatemachineE27177B2-arZJxYWqV4wX, where CFN dropped the stack prefix to stay under Step Functions' 80-char name limit.

    Practical consequence: the PassRole half is unambiguous and can be fixed on its own, scoped to exactly that one role ARN. Only the second half needs a design decision.

    Pre-creating nested-stack execution roles isn't applicable

    Nested stacks don't have their own execution roles — CloudFormation reuses the parent's for the whole tree. There is no separate role to enumerate or pre-create; the pass target is the parent's own role, passed to itself. So "grant only the roles you will actually hand off" resolves here to exactly one ARN, which is what I'd propose granting.

    Collapsing the nested stacks is a real option — but the resource ceiling blocks it

    This part I hadn't considered, and you're right that it would dissolve the naming problem outright: in the parent stack every resource picks up the backgroundagent-dev- prefix and the existing scoping works with no policy change at all.

    It's ruled out by arithmetic, though. From the current synth:

    parent-stack resources:  480
    nested-stack resources:   60   (AgentRegistryStack 20 + RegistryApi 40)
    if un-nested:            540   ← CloudFormation hard ceiling is 500
    

    That lines up with #852 (P0, "8 resources of headroom on main"). The nesting looks load-bearing for that ceiling, so collapsing it would trade a policy-scoping bug for a hard deploy failure. If #852 ever lands a fix that frees several hundred slots, this becomes worth revisiting — it's the cleanest resolution of the three.

    Where that leaves it

    Unchanged from my earlier comment: split the issue in practice into the deterministic PassRole grant (easy, no posture question) and the generated-name scoping (needs a maintainer decision between a tag condition on aws:cloudformation:stack-name and widening the resource pattern). I'm happy to implement whichever the maintainers prefer.

  3. added
    approved
    on Oct 1, 2026
  4. self-assigned this
    on Oct 28, 2026
  5. alvarohare commented on Oct 28, 2026

    @alvarohare
    Contributor

    Working on this as part of the bigger operator console and installer PRs (#449, #17). Part 1 (iam:PassRole on the exec role for nested stacks) is fixed on my branch with a scoped NestedStackPassRole statement, and a fresh-account default deploy then succeeded. I still need to confirm whether part 2 (nested-stack resource names) reproduces.

  6. krokoko commented on Nov 20, 2026

    @krokoko
    Contributor

    Triage: what this issue asks for is on main; a small leftover is noted at the end.

    Both denials of this report are fixed on main. #911 (d34dc9ef) names the Agent Registry waiter state machine <root stack>-AgentRegistryWaiter, which is inside the stateMachine:backgroundagent-dev-* grant (cdk/src/constructs/registry.ts); #976 (e5e243eb) adds the NestedStackPassRole statement (cdk/src/bootstrap/policies/infrastructure.ts), and #904 (e4fbf8a8) lets the execution role pass exactly itself to CloudFormation. #976 records a default-context deploy that completed in a clean account bootstrapped with the least-privilege template, and cdk/test/bootstrap/synth-coverage.test.ts now walks every nested stack and pins the PassRole grant. An account bootstrapped earlier has to run mise //cdk:bootstrap again; mise //cdk:deploy starts with a preflight that stops on an older policy bundle. Not done: a test that compares physical names with the policies' Resource patterns, which the review of #911 asked for and which has no issue yet, and the scheduled fresh-account deploy proposed in #970.

    Posted from an automated sweep of the open issues. Each pull request, commit and file named above was checked against main at 3dbfada1. The issue is left open for a maintainer to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

approvedv1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions