Repository navigation
Description
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
- 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).
- Do not attach
AdministratorAccessto the cfn-exec-role. export MISE_EXPERIMENTAL=1 && mise run //cdk:deploy -- --require-approval neverwith default context.- Deploy reaches changeset creation, then fails on
iam:PassRole. Grant that, redeploy, and it fails onstates:CreateStateMachineinside the nested stack.
Possible solution
- Allow the exec role to pass itself, scoped to exactly that role ARN, for nested-stack creation.
- Stop assuming the parent-stack prefix. Nested-stack physical names are not prefixed. Either:
- widen the affected
Resourcepatterns 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.
- widen the affected
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.
- 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.tsalready 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
- Node: v22.23.2 (mise) · mise: 2026.7.0 macos-arm64 · Region: us-east-1
- Bootstrap:
BootstrapVariant = "ABCA: Least-Privilege Bootstrap", version 32,ComputeTypes=agentcore - Commit:
6e865f2d - Related: RFC: Least-privilege CDK bootstrap policies as code (with preflight validation) #120 (least-privilege bootstrap policies as code — this is a gap in that design), Bootstrap policies stale — deploy fails with AccessDenied on current stack #350 (prior stale-policy AccessDenied), fix(bootstrap): least-privilege bootstrap template exceeds CFN 51,200-byte inline limit — fresh-account bootstrap is impossible #864 (blocks reaching this step at all)
Activity
vivibui commentedon Sep 8, 2026
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.
StateMachineNameis not set in the synthesized nested template: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: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:
aws:cloudformation:stack-nameto supported resources on create, and — usefully — nested stack names are prefixed with the parent (backgroundagent-dev-AgentRegistryStackNestedStack…). So aStringLikecondition onaws:RequestTag/aws:cloudformation:stack-nameofbackgroundagent-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.aws-cdk-lib'sProvider, which exposesproviderFunctionNamebut no waiter-state-machine name override.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'sLinearIdentityVaultexplicitly 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:PassRoleon the execution role itself (the first failure in the issue body) is separate and unambiguous — it can be fixed independently of this naming question.vivibui commentedon Sep 8, 2026
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
PassRolefailure is not caused by nested-stack namingThese 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:
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 theIAMPassRolestatement is scoped to a different namespace entirely:cdk-hnb659fds-cfn-exec-role-…never matchedrole/backgroundagent-dev-*, so the pass was denied on the very first nested stack. Name generation is irrelevant to this one — and note theiam:PassedToServicecondition wouldn't admit it either, since the consumer here is CloudFormation itself.The generated-name problem is the separate failure (detailed above):
states:CreateStateMachinedenied onAgentRegistryProviderwaiterstatemachineE27177B2-arZJxYWqV4wX, where CFN dropped the stack prefix to stay under Step Functions' 80-char name limit.Practical consequence: the
PassRolehalf 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:
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
PassRolegrant (easy, no posture question) and the generated-name scoping (needs a maintainer decision between a tag condition onaws:cloudformation:stack-nameand widening the resource pattern). I'm happy to implement whichever the maintainers prefer.fix(registry): name the Provider waiter state machine under the stack…
alvarohare commentedon Oct 28, 2026
Working on this as part of the bigger operator console and installer PRs (#449, #17). Part 1 (
iam:PassRoleon the exec role for nested stacks) is fixed on my branch with a scopedNestedStackPassRolestatement, and a fresh-account default deploy then succeeded. I still need to confirm whether part 2 (nested-stack resource names) reproduces.fix(bootstrap): make the least-privilege fresh-account deploy work (a…
krokoko commentedon Nov 20, 2026
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 thestateMachine:backgroundagent-dev-*grant (cdk/src/constructs/registry.ts); #976 (e5e243eb) adds theNestedStackPassRolestatement (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, andcdk/test/bootstrap/synth-coverage.test.tsnow walks every nested stack and pins the PassRole grant. An account bootstrapped earlier has to runmise //cdk:bootstrapagain;mise //cdk:deploystarts with a preflight that stops on an older policy bundle. Not done: a test that compares physical names with the policies'Resourcepatterns, 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
mainat3dbfada1. The issue is left open for a maintainer to close.