Sub topic 1
Cross-Account Access with IAM Roles
Prerequisites
This chapter assumes basic familiarity with AWS accounts, IAM users and roles, JSON policies, the AWS CLI, and Amazon Resource Names (ARNs).
IAM roles and principals: a quick refresher
An IAM role is an identity with permissions that can be used temporarily. A role does not have a permanent password or access key. A principal is an identity that can make an AWS request, such as an IAM user, role, or AWS service.
When a principal assumes a role, AWS Security Token Service (STS) returns temporary credentials. Those credentials allow the caller to act with the role's permissions until they expire.
The trusted and trusting account model
Suppose account 111111111111 contains an auditor and account 222222222222 contains the role ReadOnlyAuditor.
- The trusting account owns the role and decides which principals may use it. Here, account
222222222222is trusting. - The trusted account contains the principal that wants to use the role. Here, account
111111111111is trusted.
Cross-account access normally requires agreement from both sides:
- The role's trust policy allows the external principal or account.
- The caller's identity policy allows
sts:AssumeRoleon the role ARN.
Defining what the role can do
A permissions policy attached to the role defines what actions the assumed role can perform. For example, a read-only policy might allow listing and reading resources but not changing them.
The role's permissions policy does not decide who may assume the role. That decision belongs to the trust policy.
Writing the trust policy in the role's account
The role in account 222222222222 can trust account 111111111111 with this policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:root"
},
"Action": "sts:AssumeRole"
}
]
}Here, the account principal means IAM principals in account 111111111111 may be delegated permission to assume the role. The caller still needs an identity policy allowing the specific role ARN.
Exercise
Which policy must allow sts:AssumeRole: the role's permissions policy or its trust policy?
Show answer
The trust policy must trust the caller, and the caller's identity policy must allow sts:AssumeRole. The role's permissions policy defines actions after assumption.