Sub topic 2
The trusted and trusting account model
Cross-account access in AWS is built on two roles for two accounts. One account owns a role and decides who may use it. The other account holds the people or workloads that want to use it. This chapter defines both sides, shows which policy lives where, and explains why a request needs approval from both accounts.
This chapter assumes you know IAM users, roles, and JSON policy documents, and that you can read an ARN. You should also have used the AWS CLI with at least one account.
Two accounts, two names
AWS documentation uses two terms for the accounts involved:
- The trusting account owns the resource and the role. It "trusts" another account to use that role. In the examples in this tutorial, this is account
222222222222. - The trusted account contains the principals that are allowed to use the role. AWS trusts this account to manage its own identities. In the examples, this is account
111111111111.
The names describe the direction of trust, not the direction of access. The trusting account extends trust. The trusted account receives it. Access flows from the trusted account into the trusting account.
| Term | Account in the examples | What it owns | What it controls |
|---|---|---|---|
| Trusting account | 222222222222 | The role and the resources the role can reach | Who may assume the role, and what the role can do |
| Trusted account | 111111111111 | The users, roles, or workloads that call AssumeRole | Which of its own principals may attempt the call |
A common mistake is to reverse the terms. A reliable check is to ask which account contains the role. That account is the trusting one.
Why a role instead of a shared user
You could create an IAM user in account 222222222222 and give its access keys to a person in account 111111111111. That works, but it has real costs:
- The access keys are long-lived and must be rotated by hand.
- The person now has two identities to manage, and the owning account must offboard them separately.
- Audit trails show a user that exists only for sharing, which hides who actually acted.
A role avoids these costs. The caller keeps one identity in its home account. When it needs the other account, it asks AWS Security Token Service (STS) for temporary credentials for the role. Those credentials expire on their own, and CloudTrail records the session name and the original caller.
The two-sided permission rule
Within a single account, an IAM principal can often get access from one policy. Across accounts, AWS requires approval from both accounts. The request succeeds only if both of these are true:
- The role's trust policy in the trusting account allows the caller.
- An identity policy in the trusted account allows the caller to call
sts:AssumeRoleon that role.
The role also has a permissions policy. It does not take part in the decision to assume the role. It decides what the session can do after the role has been assumed. Later chapters cover it in detail, so here it is enough to keep the three policies apart.
| Policy | Lives in | Question it answers |
|---|---|---|
| Trust policy | Trusting account, attached to the role | Who may assume this role? |
| Caller identity policy | Trusted account, attached to the user or role making the call | May this principal assume that role? |
| Permissions policy | Trusting account, attached to the role | What may the session do once it has the role? |
Each account protects itself. The trusting account does not need to know every user in the trusted account. The trusted account administrator can still decide which of their own users may use the role, without asking the trusting account to change anything.
Why the trusted account must also say yes
Suppose the trust policy names the whole trusted account, as in this policy for the role in 222222222222:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111111111111:root" },
"Action": "sts:AssumeRole"
}
]
}The :root in the principal does not mean the root user. It means "the account as a whole." The policy does not grant every user in 111111111111 access. It hands the decision to that account. Each principal there still needs its own identity policy permitting the call, such as this one:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::222222222222:role/ReadOnlyAuditor"
}
]
}This policy limits the caller to one named role. A user without it is refused, even though the trusting account named the account in its trust policy. This is how an administrator in the trusted account keeps control over their own people.
The exception: naming a specific principal
The rule above applies when the trust policy names an account. If the trust policy names a specific user or role ARN instead, the situation changes. For example, the principal can be arn:aws:iam::111111111111:role/DeployRole. In that case the trusting account has already decided exactly who is allowed. AWS evaluates the trust policy against that principal and accepts it even if the identity policy in the trusted account says nothing.
The practical advice for intermediate users:
- Naming the account (
:root) delegates the decision to the trusted account. Use it when the trusted account's administrators are responsible for their own people. - Naming a principal ARN makes the trusting account the decision maker. Use it when you want the strictest control from the role's side.
When in doubt, grant both: a narrow trust policy in the trusting account and a narrow identity policy in the trusted account. Two narrow policies fail safe if one of them is edited by mistake.
How a request flows
The diagram shows the order of events when a user in the trusted account assumes the role.
Two points in this flow matter for troubleshooting:
- STS makes the assume-role decision. A failure here means a trust policy or caller policy problem. The error comes back from the
AssumeRolecall itself. - The service makes the permission decision later. A failure here means the role's permissions policy does not allow the action. The error comes back from the service call, not from STS.
Knowing which stage failed removes half the guesswork when you debug.
What the caller actually becomes
After a successful call, the caller does not have both identities at once. The credentials returned by STS belong to an assumed-role session. When you use them, you act as the role, with the role's permissions, and not as your original user. The role's session appears in an ARN like this:
arn:aws:sts::222222222222:assumed-role/ReadOnlyAuditor/audit-sessionThe last segment is the session name you chose when you assumed the role. Pick names that identify the person or job, because CloudTrail logs show this name for every action the session takes.
Your original permissions do not carry over. A user with administrator rights in account 111111111111 gets no more power in account 222222222222 than the role grants. This is a useful property. It lets you give a highly privileged user a safe, narrow view of another account.
Checking your understanding of the model
Use the following checklist when you design a cross-account setup. Each line maps to one of the three policies.
- Identify the trusting account. It is the account that contains the role and the resources.
- Write the permissions policy for the role with the least access the work needs.
- Write the trust policy that names the trusted account or a specific principal.
- In the trusted account, attach an identity policy that allows
sts:AssumeRoleon the exact role ARN. - Test by assuming the role and checking which identity you have.
aws sts get-caller-identityRun this command before and after assuming the role. The first result shows your original user in 111111111111. The second, using the temporary credentials, shows an assumed-role ARN in 222222222222.
Common mistakes with the model
- Reversing the account names. If you put the caller's account in the role's permissions policy, or the role's ARN in the trust policy principal, nothing works. The trust policy names who may come in. The caller policy names which role may be entered.
- Only configuring one side. A correct trust policy with no caller policy gives
AccessDeniedwhen the principal names the account. A correct caller policy with no trust policy givesAccessDeniedtoo. Both are needed in the common case. - Treating
:rootas the root user. It means the account. It does not give the root user special rights. - Expecting combined permissions. The session has the role's permissions only.
- Using a wildcard principal without conditions. A principal of
*in a trust policy allows any AWS account unless a condition narrows it. A later chapter shows how to limit it withaws:PrincipalOrgID.
Exercises
Exercise
Account 222222222222 owns a role named ReadOnlyAuditor. Its trust policy names arn:aws:iam::111111111111:root as the principal. A user in account 111111111111 has no sts:AssumeRole permission in any of their policies. Does AssumeRole succeed? Which account is the trusting account, and which policy is missing?
Show answer
No, it fails with AccessDenied. The trusting account is 222222222222, because it owns the role. The trusted account is 111111111111. The missing policy is an identity policy attached to the user (or a group or role they use) in 111111111111, allowing sts:AssumeRole on arn:aws:iam::222222222222:role/ReadOnlyAuditor. Because the trust policy names the whole account, the trusted account must also approve the call.
Exercise
A user with AdministratorAccess in account 111111111111 assumes ReadOnlyAuditor in account 222222222222, which allows only read actions. The user then tries to delete an S3 bucket in 222222222222 using the session credentials. What happens, and why?
Show answer
The delete is denied. The session acts as the role, and only the role's permissions policy applies. The user's administrator rights in 111111111111 do not carry over into the assumed-role session.