Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Limiting a CloudFormation template to the AWS service you intend to deploy does not, by itself, limit the authority used to deploy it. CloudFormation may act with the caller’s credentials or an attached service role; a macro can alter the template before provisioning; and a custom-resource provider can run its own implementation logic. Least privilege therefore requires reviewing the deployment identity, the processed template, and any provider code—not just the resource types visible in the authored template.

Why the template’s resource types do not tell the whole story

A template describes resources, but deployment authority also depends on how CloudFormation is invoked and what happens before or alongside built-in resource provisioning. A template that appears to define resources for one service may be processed by a macro or invoke a custom-resource provider with its own permissions.

These are boundaries to inspect, not evidence that every stack deployment escapes its stated service boundary. The practical question is: which identity makes each API call, what code runs, and what version of the template will actually be executed?

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Who makes the resource API calls?

CloudFormation has two baseline credential models. If no service role is specified, CloudFormation uses the credentials of the principal that invokes the stack. That caller therefore needs both permission to perform the CloudFormation stack operation and the permissions required to provision the resources. If a service role is specified, CloudFormation uses that role’s credentials for stack operations; the caller needs stack permissions and permission to pass the allowed role. See AWS CloudFormation service roles.

#1 Best Overall
Credential model Credentials used for resource operations What to govern
No service role The invoking principal’s credentials, according to AWS CloudFormation documentation. Stack permissions and the caller’s direct permissions to provision the template’s resources.
Service role attached The attached CloudFormation service role’s credentials, according to AWS CloudFormation documentation. Stack permissions, which role the caller may pass, the role’s permissions, and who can operate on the stack later.

Neither model is universally safer. Using a role can centralize provisioning authority, but that role must be scoped to the actions and resources the actual templates require. Build its policy from those needs rather than granting broad permissions for convenience.

Why an attached service role can outlast its original operator

A CloudFormation service role is part of a stack’s ongoing operating model, not merely a credential used during initial creation. AWS says the role is used for all operations on the stack and cannot be removed once associated. Other principals with permission to operate on that stack can rely on its attached role without separately having iam:PassRole. Consequently, broad stack-operation access combined with an overprivileged service role can create an escalation path. See AWS service-role guidance.

Control which roles a principal can pass with the cloudformation:RoleARN condition key, and monitor identities that can pass privileged roles. Also review stack operators: after a role is attached, their ability to operate on the stack matters even if they cannot pass that role themselves. AWS recommends IAM Access Analyzer to identify unused permissions on CloudFormation service roles. See AWS Prescriptive Guidance: CloudFormation least-privilege best practices.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What macros change—and what they do not

A macro is a Lambda-backed template processor. It can transform a portion of a template or the full template before CloudFormation handles the resulting resources. The processed template may contain resources, including IAM resources, that are not apparent from the original authored form. AWS describes CloudFormation creating a change set with the processed template and advises reviewing that result before execution. See AWS macro documentation.

Reviewing the processed change set is essential because the authored template is not necessarily the final deployment plan. A macro’s ability to rewrite a template is distinct from the credentials used later to provision the resources. AWS documentation states that users need permission to invoke the underlying Lambda function and describes CloudFormation impersonating the user while running the macro to prevent potential escalation. Do not treat macro execution as proof that a later attached service role is narrowly scoped—or assume that the macro’s rewrite capability alone determines provisioning authority. Check the macro permissions, the processed change set, and the stack’s credential model separately.

What custom resources add to the deployment path

A custom resource includes a service token that identifies its provider, such as an SNS topic ARN or Lambda function ARN. During create, update, or delete operations, CloudFormation sends the provider a lifecycle request containing request data and waits for a response. The provider handles the request and may perform provisioning work that is not expressed as a built-in CloudFormation resource type. See AWS custom-resource documentation.

For each custom resource, assess the provider implementation and its execution role as part of the effective deployment authority. Check the trust policy, the actions and resources allowed by the role, and the properties passed from the template. A narrow-looking custom-resource declaration does not establish what the provider’s code will do with those inputs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to review a stack’s effective authority

  1. Identify the credential model. In the stack’s create or update path, establish whether an attached CloudFormation service role is used. If there is none, review the invoking principal’s resource permissions as well as its stack permissions.
  2. Trace service-role access. For an attached role, inspect its trust relationship and permissions, who can pass it, and who can operate on the stack. Restrict role passing with cloudformation:RoleARN where appropriate.
  3. Inspect macro output. Before executing a change set for a template that uses macros, review the processed template for added or altered resources, especially permissions and resources outside the expected service boundary.
  4. Inspect each custom-resource provider. Follow the service token to its provider, then review the provider’s implementation, execution role, trust policy, and the template properties it receives.
  5. Apply controls to the right boundary. Scope role policies to required actions and resources; use stack policies to protect critical resources from selected unintended updates; and consider permissions boundaries or service control policies (SCPs) for additional constraints.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Cross-service trust conditions and other guardrails

For cross-service access in the CloudFormation registry and extension context, AWS recommends using aws:SourceArn and aws:SourceAccount conditions in resource policies to restrict which CloudFormation resource or account can exercise access. Prefer a full aws:SourceArn when possible; if that ARN does not include an account ID, pair it with aws:SourceAccount. These conditions apply to the relevant service-principal trust relationship; they are not a universal replacement for scoping IAM role permissions. See AWS CloudFormation registry resource-type trust guidance.

Guardrails address different risks. A role policy limits API authority; a stack policy protects selected stack resources against specified updates; and permissions boundaries or SCPs can impose additional limits on principals or accounts. Choose them to cover distinct boundaries rather than treating any one as a substitute for reviewing the template and the identities that execute it. AWS’s least-privilege best practices discuss these controls.

Choosing between caller credentials and a service role

The right choice depends on workload and governance. Caller credentials avoid attaching a persistent stack role, but they require deployers to hold the permissions needed to provision resources directly. A service role can centralize provisioning through infrastructure as code, but its durable permissions and the stack-operation access that can invoke it need careful limits.

Whichever model you use, least privilege depends on more than the visible resource list: govern who can invoke or operate on the stack, review any processed template before execution, and include custom-resource providers in the authority assessment.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.