Grant self-managed permissions
This topic provides instructions on how to create the IAM service roles required by StackSets to deploy across accounts and Amazon Web Services Regions with self-managed permissions. These roles are necessary to establish a trusted relationship between the account you're administering the StackSet from and the account you're deploying stack instances to. Using this permissions model, StackSets can deploy to any Amazon Web Services account in which you have permissions to create an IAM role.
To use service-managed permissions, see Activate trusted access instead.
Topics
Self-managed permissions overview
Before you create a StackSet with self-managed permissions, you must have created IAM service roles in each account.
The basic steps are:
-
Determine which Amazon Web Services account is the administrator account.
StackSets are created in this administrator account. A target account is the account in which you create individual stacks that belong to a StackSet.
-
Determine how you want to structure permissions for the StackSet.
The simplest (and most permissive) permissions configuration is where you give all users and groups in the administrator account the ability to create and update all the StackSets managed through that account. If you need finer-grained control, you can set up permissions to specify:
-
Which users and groups can perform StackSet operations in which target accounts.
-
Which resources users and groups can include in their StackSets.
-
Which StackSet operations specific users and groups can perform.
-
-
Create the necessary IAM service roles in your administrator and target accounts to define the permissions you want.
Specifically, the two required roles are:
-
AWSCloudFormationStackSetAdministrationRole – This role is deployed to the administrator account.
-
AWSCloudFormationStackSetExecutionRole – This role is deployed to all accounts where you create stack instances.
-
Give all users of the administrator account permissions to manage stacks in all target accounts
This section shows you how to set up permissions to allow all users and groups of the administrator account to perform StackSet operations in all target accounts. It guides you through creating the required IAM service roles in your administrator and target accounts. Anyone in the administrator account can then create, update, or delete any stacks across any of the target accounts.
By structuring permissions in this manner, users don't pass an administration role when creating or updating a StackSet.
Important
Even when you don't specify the AdministrationRoleARN parameter,
the IAM principal calling CreateStackSet or
UpdateStackSet must have iam:PassRole permission for
the AWSCloudFormationStackSetAdministrationRole role.
CloudFormation requires this permission to use the default administration role on
your behalf.
The following example policy grants the required permission:
{ "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws-cn:iam::account-id:role/AWSCloudFormationStackSetAdministrationRole" }
Set up advanced permissions options for StackSet operations
If you require finer-grained control over the StackSets that users and groups are creating through a single administrator account, you can use IAM roles to specify:
-
Which users and groups can perform StackSet operations in which target accounts.
-
Which resources users and groups can include in their StackSets.
-
Which StackSet operations specific users and groups can perform.
Control which users can perform StackSet operations in specific target accounts
Use customized administration roles to control which users and groups can perform StackSet operations in which target accounts. You might want to control which users of the administrator account can perform StackSet operations in which target accounts. To do this, you create a trust relationship between each target account and a specific customized administration role, rather than creating the AWSCloudFormationStackSetAdministrationRole service role in the administrator account itself. You then activate specific users and groups to use the customized administration role when performing StackSet operations in a specific target account.
For example, you can create Role A and Role B within your administrator account. You can give Role A permissions to access target account 1 through account 8. You can give Role B permissions to access target account 9 through account 16.
Setting up the necessary permissions involves defining a customized administration role, creating a service role for the target account, and granting users permission to pass the customized administration role when performing StackSet operations.
In general, here's how it works once you have the necessary permissions in place: When creating a StackSet, the user must specify a customized administration role. The user must have permission to pass the role to CloudFormation. In addition, the customized administration role must have a trust relationship with the target accounts specified for the StackSet. CloudFormation creates the StackSet and associates the customized administration role with it. When updating a StackSet, the user must explicitly specify a customized administration role, even if it's the same customized administration role used with this StackSet previously. CloudFormation uses that role to update the stack, subject to the requirements above.
Control the resources that users can include in specific StackSets
Use customized execution roles to control which stack resources users and groups can include in their StackSets. For example, you might want to set up a group that can only include Amazon S3-related resources in the StackSets they create, while another team can only include DynamoDB resources. To do this, you create a trust relationship between the customized administration role for each group and a customized execution role for each set of resources. The customized execution role defines which stack resources can be included in StackSets. The customized administration role resides in the administrator account, while the customized execution role resides in each target account in which you want to create StackSets using the defined resources. You then activate specific users and groups to use the customized administration role when performing StackSets operations.
For example you can create customized administration roles A, B, and C in the administrator account. Users and groups with permission to use Role A can create StackSets containing the stack resources specifically listed in customized execution role X, but not those in roles Y or Z, or resource not included in any execution role.
When updating a StackSet, the user must explicitly specify a customized administration role, even if it's the same customized administration role used with this StackSet previously. CloudFormation performs the update using the customized administration role specified, so long as the user has permissions to perform operations on that StackSet.
Similarly, the user can also specify a customized execution role. If they specify a customized execution role, CloudFormation uses that role to update the stack, subject to the requirements above. If the user doesn't specify a customized execution role, CloudFormation performs the update using the customized execution role previously associated with the StackSet, so long as the user has permissions to perform operations on that StackSet.
Set up permissions for specific StackSet operations
In addition, you can set up permissions for which user and groups can perform specific StackSet operations, such as creating, updating, or deleting StackSets or stack instances. For more information, see Actions, resources, and condition keys for CloudFormation in the Service Authorization Reference.
Set up global keys to mitigate confused deputy problems
The confused deputy problem is a security issue where an entity that doesn't have permission to perform an action can coerce a more-privileged entity to perform the action. In Amazon, cross-service impersonation can result in the confused deputy problem. Cross-service impersonation can occur when one service (the calling service) calls another service (the called service). The calling service can be manipulated to use its permissions to act on another customer's resources in a way it shouldn't otherwise have permission to access. To prevent this, Amazon provides tools that help you protect your data for all services with service principals that have been given access to resources in your account.
We recommend using the aws:SourceArn and aws:SourceAccount global condition context keys in
resource policies to limit the permissions that Amazon CloudFormation StackSets gives another service to the
resource. If you use both global condition context keys, the
aws:SourceAccount value and the account in the
aws:SourceArn value must use the same account ID when used in the
same policy statement.
The most effective way to protect against the confused deputy problem is to use
the aws:SourceArn global condition context key with the full ARN of the
resource. If you don't know the full ARN of the resource or if you are specifying
multiple resources, use the aws:SourceArn global context condition key
with wildcards (*) for the unknown portions of the ARN. For example,
arn:aws-cn:.
Whenever possible, use cloudformation::123456789012:*aws:SourceArn, because it's more specific. Use
aws:SourceAccount only when you can't determine the correct ARN or
ARN pattern.
When StackSets assumes the Administration role in your
administrator account, StackSets populates your
administrator account ID and StackSets Amazon Resource
Name (ARN). Therefore, you can define conditions for global keys
aws:SourceAccount and aws:SourceArn in the trust
relationships to prevent confused deputy
problems. The following example shows how you can use the
aws:SourceArn and aws:SourceAccount global condition
context keys in StackSets to prevent the confused deputy problem.