The roles that CloudFormation and the AWS CDK use to deploy infrastructure are among the most powerful non-human identities in any AWS estate, and the CDK's default execution role uses AdministratorAccess, so scoping it at bootstrap is a customer-side task. Anyone who can run a stack update with that role, or who can assume a bootstrap role from a trusted account, can create IAM principals and change every resource the role can reach. This guide covers CloudFormation service roles and iam:PassRole, the CDK bootstrap stack and its five roles, StackSets permission models, stack policies, dynamic references for secrets, drift detection and the CloudTrail events worth alerting on. It is written for platform engineers, DevOps teams and cloud security reviewers. It goes deeper on AWS than the cross-tool Infrastructure as Code Security Guide, which covers template scanning and state files generally.
This is an independent guide from NHI Mgmt Group, based on AWS's public documentation as of November 2026. It is not sponsored or reviewed by AWS. Product features change, so confirm settings against AWS's current documentation.
Key takeaways
- A stack's service role is shared with everyone who can update the stack. AWS warns that users with permission to operate on a stack can use its role even without iam:PassRole, and the role cannot be removed after creation. An over-privileged role is a privilege escalation path.
- CDK bootstrap defaults are broad. Unless you pass --cloudformation-execution-policies, the cdk-<qualifier>-cfn-exec-role gets AdministratorAccess. Replace it with scoped policies and a permissions boundary.
- --trust is a cross-account grant. Accounts listed as trusted can assume the deploy, file publishing and image publishing roles. Trust only the pipeline account, and use --trust-for-lookup for read-only needs.
- StackSets execution roles are administrator by template. AWS's sample AWSCloudFormationStackSetExecutionRole grants full access in every target account. Scope it, and add aws:SourceArn and aws:SourceAccount to the administration role's trust policy.
- Drift is the detective control. Drift detection compares only properties you set explicitly, skips KMSKeyId and some unreturned values, and does not check nested stacks from the parent. Set security-relevant properties explicitly so drift can see them.
How identity and access work in CloudFormation and CDK
A deployment involves up to three identities: the human or pipeline that calls CloudFormation, the role CloudFormation uses to change resources, and, for CDK, a set of bootstrap roles that sit between them.
| Identity | Defined by | What it can do | Main risk |
|---|---|---|---|
| Caller (user or pipeline role) | IAM identity policy | CreateStack, UpdateStack, CreateChangeSet, ExecuteChangeSet, DeleteStack | Without a service role, CloudFormation uses a temporary session from the caller's own credentials |
| CloudFormation service role | IAM role trusting cloudformation.amazonaws.com, passed with iam:PassRole | Every resource change on the stack | Usable by anyone who can operate on the stack; cannot be removed |
| CDK deploy role (cdk-<qualifier>-deploy-role-<account>-<region>) | CDK bootstrap template | Create and execute change sets, pass the execution role | Assumable by every --trust account |
| CDK execution role (cdk-<qualifier>-cfn-exec-role-<account>-<region>) | Bootstrap template, trusting cloudformation.amazonaws.com | All resource changes; AdministratorAccess unless overridden | The real blast radius of every CDK deployment |
| CDK file and image publishing roles | Bootstrap template | Write assets to the staging S3 bucket and ECR repository | Asset tampering: code that later runs in Lambda or containers |
| CDK lookup role | Bootstrap template, ReadOnlyAccess with an explicit Deny on kms:Decrypt | Context lookups during synthesis | Broad read access for --trust-for-lookup accounts |
| StackSets administration and execution roles | Self-managed or service-managed StackSets | Deploy stacks into many accounts | One administrator account controls every target |
Service roles. AWS documents that a service role lets CloudFormation act with permissions that differ from the caller's, for example limiting CloudFormation to EC2 actions while the user is an administrator. Once set, CloudFormation uses it for all operations on that stack. That is the reason for the escalation warning: if a developer can call UpdateStack on a stack whose role is broader than the developer, the developer can deploy anything that role can create. Restrict who may pass which role with the cloudformation:RoleArn condition key on CreateStack and UpdateStack, and keep stack-update rights aligned with the role's power.
CDK bootstrap. cdk bootstrap deploys the CDKToolkit stack with a staging S3 bucket, an ECR repository with immutable tags, a KMS key alias (alias/cdk-<qualifier>-assets-key when a new key is created), the roles above, and an SSM parameter recording the bootstrap version. The default qualifier is hnb659fds. The template's staging bucket policy denies requests where aws:SecureTransport is false, and the bootstrap stack has termination protection on by default. Every bootstrap role tags its sessions and, by default, denies AssumeRole calls that carry an ExternalId: the template's DenyExternalId parameter exists so that roles meant for third-party deputies cannot accidentally assume CDK roles.
The cloud assembly is code. The CDK CLI documentation states that a cloud assembly is a trust boundary and warns against deploying assemblies from untrusted sources, because the CLI runs external code with your shell environment and AWS credentials. Treat cdk.out from an unknown branch or artifact store like an unsigned binary.
Admin roles and privileged access
The privileged actions in this space are the ones that decide which role does the deploying, not the deployments themselves.
| Action or setting | Why it is privileged | Control |
|---|---|---|
| iam:PassRole on CloudFormation service roles | Chooses the permissions CloudFormation will use | Scope Resource to named roles; condition on iam:PassedToService cloudformation.amazonaws.com |
| cloudformation:UpdateStack on stacks with powerful roles | Inherits the stack's role without PassRole | Grant only to the pipeline that owns the stack |
| cdk bootstrap --trust <account> | Lets that account assume deploy and publishing roles | Trust only the deployment pipeline account; review the trust list per environment |
| cdk bootstrap --cloudformation-execution-policies | Sets the execution role's managed policies | Never leave the AdministratorAccess default in production |
| Permissions boundary on the execution role | Caps what any deployed IAM role can do | --custom-permissions-boundary with a maintained boundary policy |
| CreateStackSet, UpdateStackSet | Deploys into every target account and Region | Separate administration roles per target group |
| SetStackPolicy and stack-policy-during-update | Removes protection on critical resources for an update | Grant to change approvers only |
| UpdateTerminationProtection, DeleteStack | Can remove an entire environment | Break-glass; alert on use |
Bootstrap hardening options
- Execution policies: pass --cloudformation-execution-policies with managed policy ARNs that cover only the services your apps deploy. The template uses AdministratorAccess only when no policies are given and no trusted accounts are configured; the CLI advertises that choice.
- Permissions boundary: --example-permissions-boundary applies the CDK-supplied example, which the CDK documentation says should be treated as an example only. For production use --custom-permissions-boundary with your own maintained policy. Changing bootstrap parameters later requires --no-previous-parameters and resupplying every parameter.
- Custom template: export the built-in template with cdk bootstrap --show-template, review it, store it in source control, and deploy it with --template or through your own StackSets so every account gets the same reviewed version.
- Encryption: use --bootstrap-kms-key-id or a new customer managed key for the staging bucket, and keep the public access block configuration enabled.
- Qualifiers: a separate qualifier per team or application creates separate role sets, which makes it possible to give one team's pipeline a narrower execution role than another's.
See the AWS IAM Policies and Roles Guide for boundary design and the AWS STS and AssumeRole Guide for trust policy conditions.
Integrations, API tokens and service accounts
- Pipelines: deployment pipelines should reach AWS through OIDC federation and short-lived role sessions, not stored access keys. Scope the federated role to assuming the CDK deploy role or passing one CloudFormation service role. See the GitHub Actions OIDC Federation Hardening Guide and the CI/CD Pipeline Identity Security Guide.
- Secrets in templates: AWS's CloudFormation security best practices say not to embed credentials in templates and to use dynamic references, for example {{resolve:secretsmanager:MyDBSecret:SecretString:password}} or {{resolve:ssm-secure:/prod/db/password:1}}. CloudFormation resolves the value during stack and change set operations and does not store the reference value. Use NoEcho on any parameter that must carry a sensitive value, remembering that it masks output and is not encryption.
- StackSets, self-managed: AWSCloudFormationStackSetAdministrationRole in the administrator account assumes AWSCloudFormationStackSetExecutionRole in each target, and the execution role's name must match exactly. AWS's sample execution policy is Action "*" on Resource "*"; its documented minimum is cloudformation:* plus whatever the templates create. Callers of CreateStackSet and UpdateStackSet need iam:PassRole on the administration role. To segment, create customised administration roles that only specific target execution roles trust, and customised execution roles with narrow permissions.
- StackSets, confused deputy: add aws:SourceAccount and an ArnLike aws:SourceArn on arn:aws:cloudformation:*:<account>:stackset/* (or named StackSet ARNs) to the administration role's trust policy, as AWS recommends.
- StackSets, service-managed: with AWS Organizations trusted access, StackSets uses service-managed permissions and you do not create the self-managed roles. Control who can create service-managed StackSets in the management or delegated administrator account carefully, because they deploy organisation-wide. See the AWS Organizations and SCPs Guide.
- Policy as code: AWS CloudFormation Guard is an open-source policy-as-code tool that validates templates, change sets, Terraform plan JSON and AWS Config items against Guard rules. Run it in the pipeline before deployment, and use CloudFormation Hooks where you need the check enforced at deploy time regardless of pipeline.
Logging and detection
AWS recommends CloudTrail logging for CloudFormation API, console and CLI calls. Calls CloudFormation makes with a service role are recorded too, with the role's session as the identity, so you can attribute resource changes to a stack. See the AWS CloudTrail Guide.
| Event | Why it matters | Alert condition |
|---|---|---|
| CreateStack or UpdateStack with a roleARN parameter | Which role is being used | Role not on the approved list, or caller not a pipeline |
| AssumeRole of cdk-*-deploy-role or cdk-*-cfn-exec-role | Deployment activity | Source account not the pipeline account; sessions outside pipeline hours |
| UpdateStack on the CDKToolkit stack | Bootstrap roles, trust or execution policies changing | Any change outside a reviewed bootstrap run |
| CreateStackSet, UpdateStackSet, CreateStackInstances | Multi-account deployment | Caller not the platform pipeline |
| SetStackPolicy, UpdateTerminationProtection | Protection removed | Always alert |
| PutObject to the CDK staging bucket or PutImage to the assets repository by a non-publishing role | Possible asset tampering | Principal not the file or image publishing role |
| Drift status DRIFTED or resource status MODIFIED or DELETED | Out-of-band change | Any drift on IAM, security group, KMS or logging resources |
Drift detection. Drift detection runs on stacks in CREATE_COMPLETE, UPDATE_COMPLETE, UPDATE_ROLLBACK_COMPLETE or UPDATE_ROLLBACK_FAILED status and reports stack status DRIFTED or IN_SYNC, resource status MODIFIED, DELETED or NOT_CHECKED, and property differences ADD, REMOVE or NOT_EQUAL. It needs cloudformation:DetectStackDrift and DetectStackResourceDrift plus read permission on every resource. Its limits matter for security: only properties set explicitly in the template are compared, KMSKeyId is never checked, values such as Lambda function code and IAM user passwords are excluded, cross-stack attachments such as AWS::IAM::ManagedPolicy can be misreported, and nested stacks must be checked directly. The CDK CLI offers cdk drift, with --fail to return non-zero in CI and --verbose to list unchecked resources.
Metrics that show it is working
- Admin execution roles: bootstrapped account and Region pairs whose cfn-exec-role still has AdministratorAccess (target: zero in production).
- Trust scope: distinct accounts trusted by bootstrap roles per environment (target: the pipeline account only).
- Stacks without service roles: production stacks deployed with caller credentials rather than a scoped service role.
- Drift: stacks in DRIFTED status, and median days to resolve (target: falling, IAM drift resolved within a day).
- Permission-broadening changes: deployments flagged by cdk diff --fail-on=broadening that were approved without security review (target: zero).
Hardening baseline
- Inventory: list every stack, its service role, termination protection status and stack policy; list every CDKToolkit stack with qualifier, bootstrap version, trusted accounts and execution policies.
- Re-bootstrap with scoped policies: export the template, set --cloudformation-execution-policies and --custom-permissions-boundary, trust only the pipeline account, and deploy the reviewed template. Test in a sandbox account by running a full deploy of a representative app; AccessDenied errors show missing permissions. Roll back by redeploying the previous template version with --no-previous-parameters and the old parameter set.
- Gate on permission changes: keep the CDK default --require-approval broadening for humans and run cdk diff --fail-on=broadening in CI so any new IAM statement or security group rule needs review.
- Bind roles to callers: use cloudformation:RoleArn conditions so each pipeline can pass only its own service role, and remove UpdateStack from humans on production stacks.
- Protect production stacks: enable termination protection and set stack policies that deny Update:Replace and Update:Delete on stateful resources such as databases. AWS notes that a stack policy cannot be deleted and that it is a fail-safe, not access control.
- Secure StackSets: scope execution roles, add source conditions to administration role trust, and segment administration roles by target group.
- Remove secrets from templates: replace parameters and literals with dynamic references and scan templates for embedded credentials.
- Schedule drift detection: run it daily on production stacks and set security properties explicitly so drift can see them.
- Treat assemblies and assets as supply chain: build cdk.out only in the pipeline, deploy only assemblies from trusted builds, and restrict writes to the staging bucket and assets repository to the publishing roles.
Framework mapping
| Control area | NIST SP 800-53 Rev 5 | NIST CSF 2.0 | ATT&CK |
|---|---|---|---|
| Scoped service and execution roles, boundaries | AC-6, AC-6(5) | PR.AA-05 | T1098.003 Additional Cloud Roles |
| Bootstrap trust and pipeline federation | AC-3, IA-5 | PR.AA-01 | T1078.004 Cloud Accounts |
| Change approval and broadening checks | CM-3, CM-4 | PR.PS-01 | Not applicable |
| Drift detection and baseline | CM-2, CM-6 | DE.CM-09 | T1578 Modify Cloud Compute Infrastructure |
| Secrets via dynamic references | IA-5, SC-28 | PR.DS-01 | T1552.001 Credentials In Files |
| Asset and assembly integrity | SI-7, SR-4 | PR.PS-02 | T1195.002 Compromise Software Supply Chain |
In ISO/IEC 27001:2022 terms the work maps mainly to A.8.2 Privileged access rights, A.8.9 Configuration management, A.8.32 Change management and A.8.15 Logging.
Common misconfigurations
- Default AdministratorAccess execution role: CDK bootstrapped once with defaults and never revisited, so every stack in the account deploys with administrator rights.
- Trusting too many accounts: --trust given to developer sandbox accounts or every account in the organisation, letting any of them assume the production deploy role.
- Developers with UpdateStack on admin-role stacks: no PassRole needed, so a developer can add an IAM user with AdministratorAccess to a template and deploy it.
- StackSets execution role left at "*": the AWS sample policy copied unchanged into every account, with no source conditions on the administration role.
- Secrets as plain parameters: database passwords passed as String parameters without NoEcho or dynamic references, visible in the console and in change set descriptions.
- Drift that cannot be seen: security group or bucket properties left at defaults in the template, so a console change to them is never reported, and nested stacks never checked.
Practitioner checklist
- Find every cdk-*-cfn-exec-role with AdministratorAccess and re-bootstrap with scoped execution policies.
- Apply a maintained permissions boundary with --custom-permissions-boundary.
- Limit --trust to the pipeline account and use --trust-for-lookup for read-only access.
- Give every production stack a least-privilege service role and restrict iam:PassRole with cloudformation:RoleArn.
- Remove UpdateStack rights from humans on stacks whose role exceeds their own.
- Scope StackSets execution roles and add aws:SourceArn and aws:SourceAccount to administration role trust.
- Replace template secrets with dynamic references and NoEcho parameters.
- Enable termination protection and stack policies on stateful production stacks.
- Run cdk diff --fail-on=broadening and Guard rules in CI.
- Schedule drift detection and alert on IAM, network and logging drift.
Standards and references
- AWS: CloudFormation service role
- AWS: CloudFormation security best practices
- AWS: Self-managed permissions for CloudFormation StackSets
- AWS: Prevent updates to stack resources with a stack policy
- AWS: Detect unmanaged configuration changes with drift detection
- AWS: AWS CDK Toolkit CLI documentation
- AWS: CDK bootstrap template
- AWS: CloudFormation Guard
Related NHI Mgmt Group resources: Infrastructure as Code Security Guide · CI/CD Pipeline Identity Security Guide · AWS Organizations and SCPs Guide · Terraform and IaC Pipeline Credential Security Guide · AWS Security Guide