Day 3Security · Lab⏱ 2h
IAM: Who Can Do What
By the end of today you can
Create users, groups, roles and policies, read an IAM policy in JSON, and apply the principle of least privilege.
1. First principles: authentication vs authorization
Every request to AWS (a click, a CLI command, code) answers two questions:
- Authentication: Who are you? (password, access key, role)
- Authorization: Are you allowed to do this to that? (policies)
IAM (Identity and Access Management) is AWS's system for both. It's free and global.
Analogy: a hotel
User = a guest with their own ID. Group = "Staff" or "VIP" (rules given to many people at once). Policy = what the keycard opens (Room 204 and the gym, not the manager's office). Role = a uniform you borrow temporarily: a plumber (or an EC2 server) puts on the "maintenance" uniform and gets those keys for a short time, with no permanent card.
2. Reading a policy
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::my-lab-bucket", "arn:aws:s3:::my-lab-bucket/*"]
}]
}
Read it as a sentence: "Allow these actions on these resources." Key rules:
- Everything is denied by default. You must explicitly allow.
- An explicit Deny always beats any Allow.
- ARN = Amazon Resource Name, the unique address of a thing.
- Least privilege: grant only what's needed. Start narrow, widen on demand.
3. Lab: build a read-only teammate
- IAM → User groups → Create group
ReadOnlyTeam, attachReadOnlyAccess. - IAM → Users → Create user
test-reader(console access), add toReadOnlyTeam. Note the generated password. - Open a private/incognito window, sign in with the IAM sign-in URL as
test-reader. Try to create an S3 bucket. You should get Access denied. Try to list buckets: allowed. - Back as admin, create a custom policy (IAM → Policies → Create → JSON) from the example above for a bucket name of your choice, name it
LabBucketRead. - Attach it to
test-readerand use the Policy Simulator (IAM → Policy simulator, or the "Simulate" tab) to tests3:PutObject(denied) vss3:GetObject(allowed). - Create a role: IAM → Roles → Create role → trusted entity AWS service → EC2 → attach
AmazonS3ReadOnlyAccess→ nameec2-s3-read-role. You'll use it on Day 5. - Cleanup: delete
test-reader. Keep the group and role (they cost nothing).
📸 Evidence: the "Access denied" message and the policy simulator result →
evidence/day03-access-denied.png, evidence/day03-simulator.png4. Why roles beat access keys
Access keys are long-lived passwords that people accidentally leak. A role hands out temporary credentials that expire and rotate automatically. When your EC2 server needs S3, attach a role, never paste keys onto the server.
5. Exam notes
Remember
- IAM is global, not regional, and free.
- Users = people/apps; groups contain users only (no nesting); roles = temporary access for services/other accounts.
- Identity-based policy (attached to identity) vs resource-based policy (e.g. S3 bucket policy).
- Password policy, MFA, access keys, credential report, Access Advisor = tools to audit.