Join our Newsletter — 33% off our NHI Course
Home› Guides› AWS CloudFormation and CDK Security Guide: Stack Roles,…
Guide Cloud Security

AWS CloudFormation and CDK Security Guide: Stack Roles, Bootstrap Trust, StackSets and Drift

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 14 min read
On this page

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.

IdentityDefined byWhat it can doMain risk
Caller (user or pipeline role)IAM identity policyCreateStack, UpdateStack, CreateChangeSet, ExecuteChangeSet, DeleteStackWithout a service role, CloudFormation uses a temporary session from the caller's own credentials
CloudFormation service roleIAM role trusting cloudformation.amazonaws.com, passed with iam:PassRoleEvery resource change on the stackUsable by anyone who can operate on the stack; cannot be removed
CDK deploy role (cdk-<qualifier>-deploy-role-<account>-<region>)CDK bootstrap templateCreate and execute change sets, pass the execution roleAssumable by every --trust account
CDK execution role (cdk-<qualifier>-cfn-exec-role-<account>-<region>)Bootstrap template, trusting cloudformation.amazonaws.comAll resource changes; AdministratorAccess unless overriddenThe real blast radius of every CDK deployment
CDK file and image publishing rolesBootstrap templateWrite assets to the staging S3 bucket and ECR repositoryAsset tampering: code that later runs in Lambda or containers
CDK lookup roleBootstrap template, ReadOnlyAccess with an explicit Deny on kms:DecryptContext lookups during synthesisBroad read access for --trust-for-lookup accounts
StackSets administration and execution rolesSelf-managed or service-managed StackSetsDeploy stacks into many accountsOne 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 settingWhy it is privilegedControl
iam:PassRole on CloudFormation service rolesChooses the permissions CloudFormation will useScope Resource to named roles; condition on iam:PassedToService cloudformation.amazonaws.com
cloudformation:UpdateStack on stacks with powerful rolesInherits the stack's role without PassRoleGrant only to the pipeline that owns the stack
cdk bootstrap --trust <account>Lets that account assume deploy and publishing rolesTrust only the deployment pipeline account; review the trust list per environment
cdk bootstrap --cloudformation-execution-policiesSets the execution role's managed policiesNever leave the AdministratorAccess default in production
Permissions boundary on the execution roleCaps what any deployed IAM role can do--custom-permissions-boundary with a maintained boundary policy
CreateStackSet, UpdateStackSetDeploys into every target account and RegionSeparate administration roles per target group
SetStackPolicy and stack-policy-during-updateRemoves protection on critical resources for an updateGrant to change approvers only
UpdateTerminationProtection, DeleteStackCan remove an entire environmentBreak-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.

EventWhy it mattersAlert condition
CreateStack or UpdateStack with a roleARN parameterWhich role is being usedRole not on the approved list, or caller not a pipeline
AssumeRole of cdk-*-deploy-role or cdk-*-cfn-exec-roleDeployment activitySource account not the pipeline account; sessions outside pipeline hours
UpdateStack on the CDKToolkit stackBootstrap roles, trust or execution policies changingAny change outside a reviewed bootstrap run
CreateStackSet, UpdateStackSet, CreateStackInstancesMulti-account deploymentCaller not the platform pipeline
SetStackPolicy, UpdateTerminationProtectionProtection removedAlways alert
PutObject to the CDK staging bucket or PutImage to the assets repository by a non-publishing rolePossible asset tamperingPrincipal not the file or image publishing role
Drift status DRIFTED or resource status MODIFIED or DELETEDOut-of-band changeAny 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Secure StackSets: scope execution roles, add source conditions to administration role trust, and segment administration roles by target group.
  7. Remove secrets from templates: replace parameters and literals with dynamic references and scan templates for embedded credentials.
  8. Schedule drift detection: run it daily on production stacks and set security properties explicitly so drift can see them.
  9. 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 areaNIST SP 800-53 Rev 5NIST CSF 2.0ATT&CK
Scoped service and execution roles, boundariesAC-6, AC-6(5)PR.AA-05T1098.003 Additional Cloud Roles
Bootstrap trust and pipeline federationAC-3, IA-5PR.AA-01T1078.004 Cloud Accounts
Change approval and broadening checksCM-3, CM-4PR.PS-01Not applicable
Drift detection and baselineCM-2, CM-6DE.CM-09T1578 Modify Cloud Compute Infrastructure
Secrets via dynamic referencesIA-5, SC-28PR.DS-01T1552.001 Credentials In Files
Asset and assembly integritySI-7, SR-4PR.PS-02T1195.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

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

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.