IAM Basics
Identity and Access Management: users, groups, roles, policies, MFA, and least privilege.
What is it?
AWS Identity and Access Management (IAM) controls who can do what on which resources. It is global and free.
- Root user: created with the account, with unrestricted access. Protect it with MFA, do not use it for daily work, and do not create access keys for it.
- IAM users: identities for one person or app, with long-term credentials. For people, prefer federation or Identity Center.
- IAM groups: sets of users, so you attach permissions once.
- IAM roles: identities with temporary credentials that a person or service assumes. EC2 instances and Lambda functions use roles to call AWS without stored keys.
- Policies: JSON documents that allow or deny actions. Everything is denied by default, and an explicit Deny always wins.
- MFA: a second factor that protects sign-ins.
Least privilege means just enough access (only the permissions the task needs) for just enough time (just-in-time). Short-lived credentials beat long-lived keys.
Beyond users and roles
- AWS IAM Identity Center (successor to AWS SSO): workforce users sign in once and reach many accounts and apps, with permission sets mapped to roles. Uses its own directory or an external identity provider.
- Identity federation: people sign in with an identity from outside AWS (a corporate directory, SAML 2.0 or OpenID Connect provider) and get temporary credentials. No IAM user per person.
- Cross-account access: an IAM role in the target account trusts the source account. Users assume the role and get temporary credentials.
- Password policy: an account-level setting for IAM users: minimum length, required character types, expiry and reuse prevention.
Tasks only the root user can do:
- Change account settings (account name, root email address, root password) or close the account.
- Restore IAM permissions when the only administrator has locked themselves out.
- Activate IAM access to the Billing console and view certain tax invoices.
- Register as a seller on the Reserved Instance Marketplace.
- Enable MFA Delete on an S3 bucket, or fix an S3 bucket policy that denies everyone.
- Sign up for AWS GovCloud (US).
Do everything else with IAM identities. Note: changing the AWS Support plan is no longer root-only. An IAM user or role with the right permissions can do it, though older study material may still list it.
Account, root user and IAM users are three different things
- The account holds resources and identities.
- The root user is created with the account and signs in with an email address and password. It has full access, cannot be deleted, and there is one per account. Sign up with a team-owned email so root access does not depend on one person.
- IAM users sign in with the account ID (or alias), a user name and a password.
- IAM policies cannot restrict the root user in its own account. Only service control policies can restrict root, in member accounts of an organization.
Setting up people
- A common first step is an administrator identity (an IAM Identity Center user, or an IAM user in an Admins group with the
AdministratorAccessmanaged policy), only for the most trusted people.PowerUserAccessis one step down: full access except managing IAM and AWS Organizations. AWS also offers job-function managed policies: ready-made role-based permission sets. - Console users can get an autogenerated or custom password and be forced to pick a new one at first sign-in. An account alias gives a friendlier sign-in URL than the 12-digit account ID.
- An app that truly needs an IAM user gets a dedicated machine user with no console access and least-privilege permissions. Use a role instead whenever you can.
MFA options: passkeys or security keys (FIDO2: a hardware key you tap, or a passkey on your device), virtual authenticator apps on a phone (scan a QR code and enter two codes in a row to register), and hardware TOTP tokens. AWS strongly recommends MFA on the root user and IAM users.
Access keys (an access key ID plus secret) are long-term credentials for the CLI and SDKs.
- A key has exactly the permissions of its user.
- A user can have at most two keys at once, so you can rotate.
- The secret is shown only once, at creation. Lose it and you create a new key.
- Deactivate a key before you delete it. Delete unused keys.
- Never share keys, put them in code or commit them to a repository. Prefer roles.
Policy anatomy: Version (normally 2012-10-17) and one or more Statements. Each statement has:
Sid: an optional label.Effect: Allow or Deny.Action: API operations; wildcards allowed.Principal: who. Used in resource-based policies such as bucket policies.Resource: ARNs.Condition(optional): source IP, requested Region, MFA present, time of day and more.
Because Deny always wins, you can allow broad access and then deny one specific thing. Some console screens need several permissions, so least-privilege policies often take a few rounds of testing. The visual editor can write the JSON for you.
Guardrails that cap permissions (they never grant anything themselves):
- Permissions boundaries: the most an identity-based policy can give a particular user or role.
- Service control policies (SCPs) in AWS Organizations: the most whole accounts can do, for example denying use of a Region.
Identity vocabulary
- A directory service maps names of users, groups, computers and printers to their attributes. Examples: Microsoft Active Directory (domains grouped into a forest, objects in organizational units), Microsoft Entra ID (formerly Azure AD) and OpenLDAP.
- An identity provider (IdP) stores identities and authenticates users for other services. Federation links one identity across separate systems.
- OpenID Connect handles authentication (who you are). OAuth 2.0 handles authorization with tokens, without sharing passwords. SAML 2.0 is an XML standard used mainly for browser single sign-on.
- Single sign-on (SSO): log in once, reach many systems. LDAP gives same sign-on: one central password that you type into each app.
- Amazon Cognito is for your app's users, not your staff. User pools handle sign-up and sign-in (including adaptive, risk-based authentication); identity pools hand out temporary AWS credentials.
Finding excess permissions: credential reports list all IAM users and the state of their passwords, keys and MFA. IAM Access Analyzer and access reports (last accessed information) show unused or overly broad permissions to trim.
Explain like I'm 10
IAM is an office badge system. Employees (users) get badges, departments (groups) share default access, and a visiting contractor (a role) gets a day pass that expires. The policy on each badge says which doors open. The owner's master key (root) stays locked in a safe.
Examples
A least-privilege policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadOneBucket",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::zykit-demo-bucket-12345",
"arn:aws:s3:::zykit-demo-bucket-12345/*"
]
},
{
"Sid": "DenyUnencryptedTransport",
"Effect": "Deny",
"Action": "s3:*",
"Resource": "*",
"Condition": { "Bool": { "aws:SecureTransport": "false" } }
}
]
}Allow read-only access to one bucket, and explicitly deny any request not made over HTTPS.
A trust policy for a role (who may assume it)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}Lets EC2 assume the role, so instances get temporary credentials without stored keys.
Common CLI actions
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 asha
aws iam add-user-to-group --user-name asha --group-name developers
aws iam list-attached-group-policies --group-name developersHow it works
On each request, AWS checks every policy that applies: identity-based, resource-based, permission boundaries and organization-level controls. The default is implicit deny. A matching explicit Deny blocks the request; otherwise some applicable Allow is needed.
When a role is assumed, the Security Token Service (STS) issues temporary credentials that expire on their own, which limits damage if they leak.
Request: "Can asha s3:GetObject on bucket X?"
|
v
Explicit Deny anywhere? --yes--> DENIED
| no
v
Some Allow that applies? --yes--> ALLOWED
| no
v
Implicit deny ---------------> DENIEDWhy does it exist?
Cloud accounts are powerful. Without fine-grained identities and permissions, one mistake or stolen credential could affect everything. IAM limits the blast radius and ties every action to an identity.
When to use it
Always. Use groups for people's permissions, roles for apps and cross-account access, MFA on root and privileged users, and Identity Center for workforce SSO.
When not to use it
Avoid long-lived IAM user access keys when a role or Identity Center session would work. Avoid wildcard policies ("Action": "*") except in tightly scoped, reviewed cases.
Common mistakes
Using the root user for everyday tasks, or creating root access keys.
Attaching
AdministratorAccessto everyone to make errors go away.Sharing one IAM user between people.
Embedding access keys in code or a public repo instead of using roles.
Forgetting that Deny overrides Allow when debugging 'access denied'.
Creating shared IAM users for a team instead of using Identity Center or roles.
Leaving old access keys active after an employee or app no longer needs them.
Registering the root user with one employee's personal email, so access is lost when they leave.
Expecting a permissions boundary or SCP to grant access - they only limit what other policies allow.
Trying to restrict the root user with an IAM policy; only an SCP (in a member account) can do that.
Losing the secret access key and trying to recover it - it is shown once; create a new key instead.
Using IAM users for customers of your app instead of Amazon Cognito.
Practice exercises
- Easy:
Enable MFA on your own account and write down which identities should have it.
- Medium:
Write a policy that lets a user start and stop only EC2 instances tagged
Env=dev. (Hint: use a Condition onec2:ResourceTag/Env.) - Medium:
Paste the example policy into the JSON formatter or JSON Schema tool and explain each statement.
- Easy:
Write the policy statement that allows
s3:PutObjecton the objects of one bucket only, and label each element (Effect, Action, Resource). - Medium:
Rotate an access key safely: create a second key, switch the app to it, deactivate the old key, then delete it. Explain why the order matters.
- Hard:
Design access for three teams across two accounts using roles and Identity Center instead of per-account IAM users.
Interview questions
What is the principle of least privilege?
Grant only the permissions needed to perform a task, and no more, for the shortest necessary time.
User vs role?
A user has long-term credentials and stands for a person or app. A role is assumed to get temporary credentials and is preferred for services and cross-account access.
What happens if two policies conflict, one allowing and one explicitly denying?
The explicit Deny wins.
Exam-style: How should an EC2 application securely call S3? (A) Store access keys in code (B) Attach an IAM role to the instance (C) Use the root user (D) Share a user's password
B.
Exam-style: Which should be protected with MFA and not used for daily tasks?
The AWS account root user.
Exam-style: Which service gives workforce users single sign-on across multiple AWS accounts?
AWS IAM Identity Center.
Exam-style: Which task requires the root user? (A) Launch EC2 (B) Close the account (C) Create an S3 bucket (D) Create an IAM role
B.
How do you give users in one account access to resources in another?
Create a role in the resource account that trusts the other account and have users assume it.
Exam-style: Can an IAM administrator change the AWS Support plan, or is the root user required?
An IAM identity with the appropriate permissions can change it; it is no longer a root-only task. Closing the account or changing the root email still needs root.
Exam-style: What sets the maximum permissions for all accounts in an AWS Organization? (A) IAM groups (B) Permissions boundaries (C) Service control policies (D) Access keys
C. Service control policies.
Exam-style: Which service authenticates the end users of a mobile or web application? (A) IAM (B) IAM Identity Center (C) Amazon Cognito (D) AWS Organizations
C. Amazon Cognito.
How many access keys can an IAM user have, and why more than one?
Two at a time, so you can rotate: create the new key, switch over, then deactivate and delete the old one.
What is a permissions boundary?
A managed policy that sets the maximum permissions an identity-based policy can grant to a user or role; it grants nothing by itself.
SAML vs OpenID Connect vs OAuth 2.0?
SAML 2.0 is an XML standard mainly for browser SSO; OpenID Connect handles authentication (identity); OAuth 2.0 handles authorization with tokens.
Exam-style: Which MFA option is a physical device you tap to sign in?
A FIDO2 security key (shown in the console as 'Passkey or security key').