Sub topic 9
The confused deputy problem
This chapter assumes you can read IAM trust policies and know how sts:AssumeRole works across accounts, as covered in the earlier chapters. It explains a specific risk that appears when a third party acts in your account, and why a trust policy alone does not prevent it.
What the problem is
A confused deputy is a service that holds legitimate authority and is tricked into using it for the wrong party. In AWS, the typical case involves a vendor that offers a monitoring or cost-analysis product. You create a role in your account and trust the vendor's account. The vendor then assumes that role to read your resources.
The trust policy says "account 333333333333 may assume this role." It does not say which customer of the vendor is asking. The vendor's account holds roles for many customers. If an attacker is also a customer, they can give the vendor your role ARN and ask it to scan "their" account. The vendor assumes your role, because your trust policy allows it. The vendor is the deputy. It has real authority over your account, and it was confused about who the request was for.
This works because role ARNs are not secret. They show up in logs, tickets, and console screenshots.
How the attack flows
Nothing in the AWS call is invalid. Both the vendor's identity policy and the victim's trust policy permit the action. The flaw is that the trust policy cannot tell the attacker's request from a genuine one.
What does not fix it
Trusting the vendor's account more narrowly does not help, because the vendor's account is the one making the call in both cases. Keeping the role ARN private is not enough either. You should assume an ARN can leak.
The fix: a value only the real customer knows
The fix is to add a second piece of information to the request. The vendor generates a unique value for each customer. You put that value in the trust policy as a condition. The vendor must send it when it calls sts:AssumeRole. This value is called an external ID, and the next chapter covers it in detail.
Here is the shape of a trust policy that uses it:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::333333333333:root" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": { "sts:ExternalId": "example-external-id-123" }
}
}
]
}When the attacker asks the vendor to scan your role, the vendor looks up the external ID it assigned to the attacker's account, not yours. The AssumeRole call carries the wrong ID and is denied. The attacker has no way to learn the ID the vendor assigned to you.
Who is responsible for what
The protection depends on the vendor's behavior as much as on your policy.
- The vendor must generate the external ID. If you choose it, a customer could pick a guessable value or one that another customer also uses.
- The vendor must keep one ID per customer and use the matching one for each call.
- The vendor must not let a customer supply a different customer's ID.
- You must add the condition to the trust policy. A role without it is still exposed.
The external ID is not a password. It can appear in your role's trust policy, which people with IAM read access can see. It works because the attacker cannot make the vendor send it for your role.
Exercise
Exercise
A vendor's account 333333333333 is trusted by your role, and the trust policy has no condition. Why can another customer of the vendor use the vendor to reach your account, and which single addition to the trust policy stops it?
Show answer
The trust policy only checks the calling account, and the vendor's account makes the call for every customer. An attacker who knows your role ARN can ask the vendor to assume it. Adding a StringEquals condition on sts:ExternalId, with a unique value the vendor assigned to you, stops it. The vendor sends the attacker's own ID for the attacker's request, so the call is denied.