Lesson 2 of 4 AWS IAM and Access Troubleshooting

Granting Access with Roles, Federation and Resource-Based Policies

This lesson explains how roles provide temporary access within and across accounts, how federation uses existing identities, how resource-based policies grant access on the resource itself, and how conditions make them precise.

Learning outcomes

After completing this lesson, you will be able to:

  • Configure trust policies for cross-account access.
  • Describe SAML and OIDC federation.
  • Use resource-based policies with condition keys.

Trust policies and cross-account access

A role has a trust policy (who may assume it) and permissions policies (what it may do). For cross-account access, the role in account B trusts account A (or a specific role in A), and the principal in account A also needs sts:AssumeRole permission for the role ARN. Third parties are given an external ID condition in the trust policy to prevent the confused deputy problem. Service roles trust a service principal such as ec2.amazonaws.com or lambda.amazonaws.com, and instance profiles are the containers that deliver a role to EC2 instances.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"AWS": "arn:aws:iam::444455556666:role/OpsAutomation"},
    "Action": "sts:AssumeRole",
    "Condition": {"StringEquals": {"sts:ExternalId": "ops-7731"}}
  }]
}

The following diagram shows the policies on each side of a cross-account role.

Cross-account access with a role. The role in account B has a trust policy naming account A, or a role in it, with an external ID condition for third parties. The principal in account A also needs sts:AssumeRole on the role's ARN. Both sides must allow it, and the role's permissions policies decide what it can do in account B.
The external ID is supplied by the third party, not chosen by the account owner.
Troubleshooting scenario

Cross-account access

Exam skills 4.1.1 · 4.1.2

Fix cross-account role and resource access problems.

Log in to try this activity Interactive activities are free with an account.

Federated identity

Federation lets users authenticated by an external identity provider (IdP) access AWS without IAM users. SAML 2.0 federation (with Microsoft Entra ID, Okta, AD FS and others) maps IdP groups to IAM roles through AssumeRoleWithSAML; OIDC federation supports web identities and CI systems such as GitHub Actions through AssumeRoleWithWebIdentity. For workforce access to many accounts, IAM Identity Center is the recommended approach and is covered in the multi-account module. Customer-facing applications use Amazon Cognito, which is outside this exam's focus.

Resource-based policies and conditions

Resource-based policies are attached to resources such as S3 buckets, SQS queues, SNS topics, KMS keys, Lambda functions, ECR repositories, Secrets Manager secrets and EventBridge buses. They include a Principal element and can grant access to other accounts directly, without a role. Condition keys narrow statements. The following table lists keys that appear often in operations scenarios.

Condition keyUse
aws:SourceIpRestrict calls to corporate IP ranges (public IPs only)
aws:SourceVpce / aws:SourceVpcRestrict access to requests through a VPC endpoint or VPC
aws:PrincipalOrgIDAllow any principal in the organisation
aws:RequestedRegionAllow or deny actions by Region
aws:SecureTransportRequire TLS
aws:MultiFactorAuthPresentRequire MFA
aws:ResourceTag / aws:PrincipalTag / aws:RequestTagAttribute-based access control and tag enforcement
aws:SourceArn / aws:SourceAccountLimit service principals to your resources (confused deputy protection)
Match the pairs

Policy conditions

Exam skills 4.1.1 · 4.2.3

Match each requirement with the condition key that enforces it.

Log in to try this activity Interactive activities are free with an account.
Worked example

Sharing a bucket across the organisation

A central bucket holds deployment artefacts that roles in all 40 accounts of the organisation must read, including future accounts. Listing account IDs in the bucket policy would need constant updates. A single statement with "Principal": "*", actions s3:GetObject and s3:ListBucket, and the condition aws:PrincipalOrgID equal to the organisation ID allows every principal in the organisation, and nobody outside it. Each account's roles still need IAM permissions for the bucket, because cross-account access requires both sides to allow it.

Check yourself

What protects a role that a third party assumes from the confused deputy problem?

Show answer

An external ID required in the role's trust policy.

Exam Tips

Remember for the exam

  • Cross-account access needs the role's trust policy and sts:AssumeRole permission in the caller's account.
  • Use an external ID for third-party roles.
  • SAML and OIDC federation assume roles; IAM Identity Center is preferred for workforce access.
  • aws:PrincipalOrgID grants access to the whole organisation in resource policies.
  • aws:SourceArn and aws:SourceAccount protect service principal grants.