Beginner · AWS account, IAM and billing · topic 7 of 50 · 30 min
IAM: users, groups, roles and least privilege
Explanation
Two questions: who are you, and what may you do?
Authentication answers "who are you?": a password plus an MFA code, or an access key. Authorisation answers "what are you allowed to do?": for example read files in one S3 bucket but not delete servers. IAM, Identity and Access Management, handles both for AWS. It is a global service (not tied to one region) and costs nothing extra.
Identities
| Identity | What it is | Credentials | Use it for |
|---|---|---|---|
| IAM user | One person or program with long-term credentials | Password and/or access keys (long-term) | Learning accounts, rare legacy cases |
| IAM group | A collection of users that share permissions | None of its own; you cannot sign in as a group | Giving "developers" or "auditors" the same rights |
| IAM role | An identity anyone trusted can assume for a while | Temporary credentials from STS | EC2, Lambda, other accounts, people through Identity Center |
Groups cannot contain other groups. A user can be in several groups and gets the permissions of all of them, plus any attached to the user directly.
Policies
A policy is a JSON document that lists permissions. Identity-based policies attach to a user, group or role and say what that identity may do. Resource-based policies attach to a resource, such as an S3 bucket policy, and say who may use that resource. Policies come in three flavours: AWS managed (written and updated by AWS, such as ReadOnlyAccess or AmazonS3ReadOnlyAccess), customer managed (written by you, reusable), and inline (embedded in one identity; avoid unless you need a strict one-to-one link). The next topic reads policy JSON line by line.
Roles and temporary credentials
A role has two parts: a trust policy (who may assume the role) and permission policies (what the role may do). When an EC2 server needs to read from S3, you do not copy access keys onto it. You create a role that trusts the EC2 service, attach it to the server through an instance profile (a small wrapper that connects a role to an EC2 instance), and the server automatically receives temporary credentials from STS, the AWS Security Token Service. They expire and are rotated for you. Lambda functions get a role, called an execution role, in the same way.
Good habits
- Least privilege: give only the actions and resources a job needs. Start small and add when something is truly needed.
- MFA for every person who signs in, especially admins.
- People sign in through IAM Identity Center, which gives short-term credentials and one place to remove a leaver's access.
- Access keys (an access key ID starting with AKIA plus a secret) only when nothing else works. Rotate them, delete unused ones, and never commit them to Git. Temporary keys from STS start with ASIA.
- IAM Access Analyzer finds resources shared with outside accounts, flags unused permissions, and checks your policies for mistakes.
aws iam create-group --group-name developers
aws iam attach-group-policy --group-name developers \
--policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess
aws iam create-user --user-name ravi
aws iam add-user-to-group --user-name ravi --group-name developers
aws iam list-attached-group-policies --group-name developersNeed help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
IAM: users, groups, roles and least privilege · 1/6
IAM, identity and access management, decides who can do what in your AWS account.
Prefer a video by a teacher? Find free videos on “AWS IAM users groups roles policies tutorial for beginners” on YouTube ↗
In real life: A BPO gives each team the right access
A BPO in Gurugram runs its call-recording app on AWS. Agents never touch AWS. Developers are in a "developers" group with permission to deploy only to the development account. Two senior engineers have admin rights in production through IAM Identity Center, with MFA, and their sessions expire after a few hours. The recording servers run on EC2 with a role that can write only to the "call-recordings" bucket. When a developer leaves, HR's exit checklist removes one Identity Center user, and all access ends at once.
Practice (0/3 done)
An EC2 server must read files from one S3 bucket. What is the safest way to give it access?
A user's effective permissions are the actions attached to the user directly plus the actions of every group the user belongs to. users looks like {"ravi": {"groups": ["developers"], "actions": ["s3:GetObject"]}} and groups looks like {"developers": ["ec2:DescribeInstances", "s3:GetObject"]}. Write effective_actions(user, users, groups) that returns a sorted list with no duplicates.
Policies often use wildcards: "s3:Get*" matches s3:GetObject and s3:GetBucketPolicy, and "*" matches everything. Write is_allowed(user, action, users, groups) that returns True if ANY of the user's effective actions (direct plus groups, as in the previous task) matches action. AWS ignores upper and lower case in action names, so compare in lower case. Use fnmatch.fnmatchcase from the standard library for the wildcard match.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- IAM policy JSON and how AWS decidesAWS account, IAM and billing · same module
- Pricing, billing and cost controlAWS account, IAM and billing · same module
- Cloud identity and access managementCyber Security: from zero to SOC analyst · Cloud security basics
- Identity is the new perimeterCloud security and compliance
- Identity and access management, least privilege and RBACCyber Security: from zero to SOC analyst · Identity and network defence
- Securing and sharing S3 dataCompute and storage: EC2 and S3
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which IAM identity gives temporary credentials and is the right choice for a Lambda function?
Answer: IAM role
Lambda runs with an execution role; AWS supplies temporary credentials.
Can you sign in to AWS as an IAM group?
Answer: No, a group only holds users and their shared permissions
Groups have no credentials of their own; they only collect users.
Which is "authorisation"?
Answer: Deciding whether a signed-in user may delete a bucket
Authorisation is about what an identity is allowed to do; the others prove who you are.
You find an access key in a public GitHub repo. What do you do FIRST?
Answer: Deactivate the key immediately
Deactivate it at once, then check CloudTrail for what it did and create a new key.
Which tool finds resources shared with outside accounts and unused permissions?
Answer: IAM Access Analyzer
IAM Access Analyzer reports external access, unused access and policy problems.
Why are roles with temporary credentials better than access keys for apps?Related
Answer: Credentials expire automatically, so a leak is useful for a short time only
Short-lived credentials shrink the window of misuse.
Developers may create their own IAM roles, but never more powerful than a set limit. What enforces that limit?Related
Answer: A permissions boundary
A permissions boundary caps the permissions of the users or roles it is set on.
What is least privilege?Related
Answer: Each account gets only the access its job needs
Minimum access limits damage when an account is misused.
From Identity and access management, least privilege and RBAC
Which value should "Version" have in a new IAM policy?Related
Answer: "2012-10-17"
"2012-10-17" is the current policy language version.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “AWS account, IAM and billing” before its exam: IAM policy JSON and how AWS decides, Pricing, billing and cost control.
- Module 2 exam: AWS account, IAM and billing · 13 questions · 20 min, without help. 4 topics of this module still to finish first.
- Then the next module, Compute and storage: EC2 and S3. 50 topics left in the course before the final exam.