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
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 key | Use |
|---|---|
| aws:SourceIp | Restrict calls to corporate IP ranges (public IPs only) |
| aws:SourceVpce / aws:SourceVpc | Restrict access to requests through a VPC endpoint or VPC |
| aws:PrincipalOrgID | Allow any principal in the organisation |
| aws:RequestedRegion | Allow or deny actions by Region |
| aws:SecureTransport | Require TLS |
| aws:MultiFactorAuthPresent | Require MFA |
| aws:ResourceTag / aws:PrincipalTag / aws:RequestTag | Attribute-based access control and tag enforcement |
| aws:SourceArn / aws:SourceAccount | Limit service principals to your resources (confused deputy protection) |
Policy conditions
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.
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.