Sub topic 1
How IAM Works: Principals, Authentication, and Authorization
Prerequisites
Assume familiarity with AWS accounts, JSON, authentication versus authorization, and basic AWS CLI usage.
How IAM Works
AWS Identity and Access Management (IAM) controls access to AWS resources. A principal is an identity that can make a request. Principals include IAM users, roles, federated users, and AWS services.
IAM processes a request in two stages:
- Authentication verifies who or what made the request. Credentials might be a password, access key, or temporary role credentials.
- Authorization evaluates policies to decide whether the authenticated principal may perform the requested action on the target resource.
IAM Users and the Root User
An IAM user represents a long-lived identity in one AWS account. It can have a console password, access keys, or both. Users are useful for specific human identities, but workloads should generally use roles instead of user access keys.
The root user is the account-owning identity. It has unrestricted access and cannot be limited by IAM policies. Protect it with MFA, avoid using it for routine work, and do not create root access keys.
Passwords, MFA, and Access Keys
A password authenticates console access. Multi-factor authentication (MFA) adds a separate factor, such as a hardware device or authenticator code. MFA reduces the impact of a stolen password.
An access key is a long-lived credential pair for API and CLI requests. Never place access keys in source code or commit them to a repository. Prefer temporary credentials from an IAM role.
What a Policy Is
A policy is a JSON document containing permissions. An identity-based policy attaches to a user, group, or role. A resource-based policy attaches to a resource, such as an S3 bucket. Trust policies are a special role policy that identify who may assume the role.
| Policy type | Attached to | Main purpose |
|---|---|---|
| Identity-based | User, group, or role | Grants actions to an identity |
| Resource-based | AWS resource | Grants access to named principals |
| Trust policy | IAM role | Controls who may assume the role |
Anatomy of a Policy Document
The main elements are Effect, Action, Resource, and optional Condition. This policy allows listing one bucket and reading its objects:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket"
},
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
}
]
}ListBucket uses the bucket ARN. GetObject uses object ARNs. An omitted permission is an implicit deny.
Exercise
Why does this example use two statements instead of one?
Show answer
Bucket-level listing and object-level reading require different actions and resource ARN formats.