Sub topic 9
The confused deputy problem
This chapter assumes you can read IAM JSON policies, know how a trust policy differs from an identity policy, and have run aws sts assume-role before. It explains one specific weakness in cross-account role trust and why a plain "trust that account" statement is not always safe.
What a confused deputy is
A confused deputy is a program that holds legitimate authority and is tricked by a less-privileged party into using that authority for the wrong person. The deputy is not hacked. It does exactly what it was built to do, but on behalf of the wrong requester.
In AWS, the deputy is usually a third-party service that you hire to work inside your account. Examples are a cost-analysis vendor, a monitoring product, or a backup service. You give it access by creating a role in your account that trusts the vendor's AWS account. The vendor then calls sts:AssumeRole against your role.
The weakness is in what the trust policy actually says. A trust policy that names the vendor's account says "any principal in that account that has permission to call sts:AssumeRole may assume this role." It does not say which of the vendor's customers the request is being made for.
The attack in concrete terms
Suppose a vendor named ExampleCo runs account 333333333333. Its customers connect by creating a role and giving ExampleCo the role ARN. ExampleCo's backend then assumes that role to read the customer's resources.
Now suppose two customers exist:
- You, the victim, with account
222222222222and a role namedExampleCoAccess. - An attacker, who is also an ExampleCo customer.
The attacker does not need access to your account. They only need to learn your role ARN, which is not a secret in the way a password is. ARNs appear in logs, tickets, screenshots, and configuration files. The attacker registers your role ARN in their own ExampleCo account, as if it were theirs. ExampleCo's backend then assumes your role and returns your data to the attacker's dashboard.
ExampleCo did nothing unusual. Your trust policy did allow ExampleCo's account to assume the role. The failure is that the trust policy cannot tell your request from the attacker's request, because both arrive from the same vendor account.
The vulnerable trust policy
This is the trust policy that creates the exposure. It trusts the vendor's whole account and nothing else.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::333333333333:root" },
"Action": "sts:AssumeRole"
}
]
}Using :root as the principal does not mean the root user. It means the account as a whole, so IAM delegates the decision to that account's own identity policies. Your trust policy has no say in which of the vendor's customers triggered the call.
Why the vendor cannot fix this alone
A careful vendor can add checks on its side, such as verifying that a customer owns the account they register. That helps, but it moves the security guarantee into code you cannot inspect. It also fails whenever the vendor has a bug. You want a control in your own trust policy that you can read and audit.
That control has to be a value the attacker cannot supply. It must be tied to your relationship with the vendor, not just to your role ARN. The vendor, not the customer, must decide this value, so that a customer cannot choose someone else's.
The mitigation: a value only the right customer's session carries
The standard fix is the sts:ExternalId condition key. The vendor generates a unique identifier for each customer and stores it against that customer's record. When the vendor assumes a role for customer X, it passes customer X's external ID in the AssumeRole call. Your trust policy requires that value.
{
"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" }
}
}
]
}Now replay the attack. The attacker registers your role ARN in their ExampleCo account. ExampleCo looks up the attacker's external ID, which is different from yours, and passes it to STS. Your trust policy requires your external ID, so STS rejects the call with AccessDenied. The attacker has no way to learn or inject your value, because the vendor attaches the external ID on its own side from its own records.
The call from the vendor looks like this:
aws sts assume-role \
--role-arn arn:aws:iam::222222222222:role/ExampleCoAccess \
--role-session-name exampleco-session \
--external-id example-external-id-123The next chapter covers how to generate, store, and rotate external IDs. Here the point is why the condition exists.
What the external ID does and does not protect
The control is narrow, and it is worth knowing its limits.
| Question | Answer |
|---|---|
| Does it stop a different vendor customer from using your role? | Yes, if the vendor assigns IDs and never lets customers choose them. |
| Does it replace the caller's `sts:AssumeRole` permission? | No. The caller still needs an identity policy that allows the call. |
| Does it protect against a vendor that is itself malicious? | No. The vendor holds your ID and can use it. |
| Does it help when the caller is one of your own principals? | No. It is meant for third parties acting on behalf of several customers. |
| Does it need to stay hidden? | It is better not to publish it, but the design does not depend on secrecy. |
The same pattern inside AWS services
The confused deputy problem is not limited to third-party vendors. AWS services also act as deputies. For example, a service in one account may write to your S3 bucket or SNS topic through a resource-based policy that trusts the service principal, such as sns.amazonaws.com. Without more conditions, any account's use of that service could reach your resource.
For service principals, the equivalent controls are the global condition keys aws:SourceArn and aws:SourceAccount. They let your policy say "this service may act, but only on behalf of this specific resource or account." This follows the same principle as the external ID: add a condition that identifies who the deputy is working for.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "sns.amazonaws.com" },
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::example-bucket/*",
"Condition": {
"StringEquals": { "aws:SourceAccount": "222222222222" }
}
}
]
}Check each service's documentation to see which key it supports. Not every service populates both keys on every call.
Edge cases and common mistakes
- Reusing one external ID for all roles. An ID that is unique per customer should also be unique per integration. If one ID covers several roles, one leak affects all of them.
- Letting the customer type the ID. The vendor must generate it. A user-supplied value allows the attacker to copy yours.
- Forgetting the condition on a new role. Each trust policy is separate. Copying a role without its condition reopens the gap.
- Assuming the ARN is a secret. Design as if role ARNs are known to attackers.
- Expecting the condition to work through role chaining. With chained calls, the external ID applies only at the hop where the trust policy requires it, so each trusting role needs its own check.
- Checking only the vendor's documentation. The vendor may supply a template that omits the condition. Read the trust policy before you create the role.
Checking your own roles
To find exposed roles, list roles whose trust policy names an external account and look for a missing sts:ExternalId condition.
aws iam get-role \
--role-name ExampleCoAccess \
--query 'Role.AssumeRolePolicyDocument'If the output shows a third-party account principal and no Condition block, the role is open to the attack described above. For roles assumed only by your own accounts, a missing external ID is expected and not a finding.
Exercise
Your trust policy for the role ExampleCoAccess names the vendor's account 333333333333 as principal and has no conditions. A vendor engineer tells you that adding an external ID is unnecessary because your role ARN is never shared publicly. Give two reasons the engineer's argument does not remove the risk, and state who must generate the external ID.
Show answer
First, role ARNs are not secrets. They appear in logs, tickets, and configuration, and any other customer of the vendor who learns the ARN can register it in their own vendor account. Second, the vendor backend assumes the role for whichever customer asks, and the trust policy only identifies the vendor account, so STS cannot tell your request from the attacker's. The vendor must generate the external ID, one per customer, so a customer cannot choose another customer's value.
Exercise
A vendor assumes your role with the correct external ID, but the call still fails with AccessDenied. Name one check on the vendor's side that has nothing to do with the confused deputy problem.
Show answer
Confirm that the vendor's calling identity has an identity policy allowing sts:AssumeRole on your role's ARN. The trust policy and the external ID are only one half of the requirement. The caller's own account must also grant the permission.