Sub topic 3
The confused deputy problem
Assume you know IAM roles, ARNs, JSON policies, and basic AWS CLI use. A confused deputy is a trusted service or partner that has permission to access your account but is tricked into using that permission for another customer.
For example, a monitoring provider may use one IAM role to access many customer accounts. If its request identifies only the role ARN, an attacker might cause the provider to use your role while requesting access for the attacker’s account.
Using an external ID with third parties
An external ID is a shared value that the customer gives to the provider. The provider includes it in the AssumeRole request. The role’s trust policy checks the value:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::333333333333:root"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "customer-7f42-example"
}
}
}
]
}The value should be unique per customer and treated as a routing identifier. It is not a password. Do not use a predictable value shared by every customer.
Narrowing trust with conditions
Conditions can also restrict trusted principals to your AWS Organization:
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-exampleorgid"
}
}Use conditions such as aws:PrincipalOrgID, aws:PrincipalArn, source identity, or required MFA where they fit your access model. Keep the principal specific whenever possible.
Role chaining and its limits
Role chaining means assuming a second role while using temporary credentials from a first role. AWS limits a chained session to a maximum of one hour, even when the target role permits a longer duration. Prefer direct federation or a direct user-to-role path when longer sessions or simpler auditing are required.
When a resource-based policy is enough
A resource-based policy on an S3 bucket, KMS key, or similar resource can grant access directly to a principal in another account. This may avoid role assumption, but the service must support the needed policy and the resource policy must be carefully scoped.
Guardrails: SCPs and permissions boundaries
An AWS Organizations service control policy (SCP) sets the maximum permissions for accounts or organizational units. A permissions boundary sets the maximum permissions for a user or role. Neither grants permission by itself. Both can block an otherwise valid cross-account request.
Troubleshooting AccessDenied and auditing with CloudTrail
Check these independently:
- The role trust policy names the correct principal and conditions.
- The caller’s identity policy allows the exact role ARN.
- No SCP, permissions boundary, session policy, or explicit deny blocks the action.
- CloudTrail shows the failed
AssumeRoleevent, caller ARN, target role, and failure reason.
Exercise
A provider receives AccessDenied even though its account appears in the trust policy. What should you check first?
Show answer
Check the external ID condition, the provider's sts:AssumeRole permission for the exact role ARN, and any SCP or permissions boundary that could impose an explicit limit.