Sub topic 3
Roles for AWS Services and Workloads
Assume you know basic JSON, AWS accounts, and the difference between authentication and authorization. This chapter focuses on how AWS workloads receive and use permissions.
Service roles and workload access
An IAM role is an identity that has permissions but no permanent password or access key. A workload, such as an EC2 instance or Lambda function, assumes the role and receives temporary credentials.
A role has two separate policy types:
- A trust policy says who may assume the role.
- A permissions policy says what the role may do after it is assumed.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}The EC2 instance profile connects an EC2 instance to this role. The application then uses temporary credentials instead of storing long-lived access keys.
Resource-based policies and cross-account access
A resource-based policy is attached to a resource, such as an S3 bucket. It names the allowed principal directly. This can grant access to a principal in another account.
The common cross-account pattern is role assumption:
- The target account creates a role with a trust policy.
- The source principal gets permission for
sts:AssumeRole. - AWS STS returns temporary credentials for the target role.
- The caller uses those credentials to access resources.
Policy evaluation and guardrails
AWS starts with no permission, adds applicable allows, and rejects the request if any applicable policy contains an explicit Deny. An allow in one policy cannot override an explicit deny.
A permissions boundary limits the maximum permissions for a user or role. A service control policy (SCP) limits the maximum permissions available to accounts in an AWS Organizations hierarchy. Neither policy grants permissions by itself.
Least privilege and troubleshooting
Grant only the actions, resources, and conditions a workload needs. Begin narrowly, then expand based on evidence. IAM Access Analyzer can identify unused or externally reachable access. The policy simulator can test a specific principal and action. CloudTrail records requests and often reveals the missing action, resource, or condition.
For command-line troubleshooting, confirm which identity is active:
aws sts get-caller-identityThen inspect the role trust policy, permissions policy, boundary, SCPs, resource policy, and request conditions. Check for an explicit deny before adding another allow.
Exercise
An EC2 application receives AccessDenied for s3:GetObject. What should you check first?
Show answer
Confirm the active role with get-caller-identity, then check its object-level permission, the bucket policy, the object ARN, boundaries, SCPs, conditions, and explicit denies.