AWS IAM Explained: Users, Groups, Roles, Policies, Least Privilege and Policy Evaluation

AWS Solutions Architect 45 min min read Updated: Nov 17, 2026 Beginner
AWS IAM Explained: Users, Groups, Roles, Policies, Least Privilege and Policy Evaluation
Beginner Topic 1 of 3

What IAM Does

AWS Identity and Access Management (IAM) decides who (authentication) can do what (authorization) on which resources. IAM is global (not tied to a Region) and free.

IAM pieceWhat it isExample
UserA person or app with long-term credentials (password, access keys)alice
GroupA set of users that share permissions. Groups cannot contain groupsDevelopers
RoleAn identity with no password, used by AWS services or people for a short time (temporary credentials)EC2-S3-ReadRole
PolicyA JSON document that allows or denies actionsAmazonS3ReadOnlyAccess

A Policy Document

json { "Version": "2012-10-17", "Statement": [ { "Sid": "ReadReportsBucket", "Effect": "Allow", "Action": ["s3:GetObject", "s3:ListBucket"], "Resource": [ "arn:aws:s3:::acme-reports", "arn:aws:s3:::acme-reports/*" ], "Condition": { "Bool": {"aws:SecureTransport": "true"} } } ] }
ElementMeaning
VersionPolicy language version. Always 2012-10-17
StatementOne or more rules
EffectAllow or Deny
ActionAPI calls such as s3:GetObject, wildcards allowed (s3:*)
ResourceARN of the target. Bucket ARN for list, bucket/* for objects
ConditionExtra rules: source IP, MFA, time, tags, HTTPS, Region
PrincipalWho is allowed. Used only in resource-based and trust policies

ARNs

text arn:aws:service:region:account-id:resource arn:aws:s3:::my-bucket/path/file.txt (S3 has no Region or account in the ARN) arn:aws:ec2:ap-south-1:123456789012:instance/i-0abc123 arn:aws:iam::123456789012:role/AppRole

Types of Policies

TypeAttached toNotes
Identity-basedUser, group, roleSays what this identity may do. AWS managed, customer managed or inline
Resource-basedA resource (S3 bucket, SQS queue, KMS key, Lambda)Has a Principal. Can allow cross-account access directly
Permission boundaryUser or roleA maximum limit. Effective permissions are the overlap with the identity policy
Service control policy (SCP)AWS Organizations account or OUA guardrail for whole accounts. Does not grant, only limits
Session policyTemporary sessionFurther limits an assumed-role session
Trust policyA roleSays who may assume the role
Managed policy kindMeaning
AWS managedCreated and updated by AWS, for example AdministratorAccess, ReadOnlyAccess
Customer managedYou write it, reuse it on many identities, and it has versions
InlineEmbedded in one identity. One-to-one, avoid unless you need that strict link

Roles and Temporary Credentials

A role is like a hat: someone or something puts it on to get the permissions for a while. Credentials are temporary (issued by STS, the Security Token Service) and expire, so there is nothing long-lived to leak.

json // Trust policy: EC2 instances may assume this role { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": {"Service": "ec2.amazonaws.com"}, "Action": "sts:AssumeRole" }] }
bash # Create a role for EC2 that can read one S3 bucket aws iam create-role --role-name AppS3Read --assume-role-policy-document file://trust-ec2.json aws iam put-role-policy --role-name AppS3Read --policy-name ReadReports --policy-document file://read-reports.json # EC2 uses roles through an instance profile aws iam create-instance-profile --instance-profile-name AppS3Read aws iam add-role-to-instance-profile --instance-profile-name AppS3Read --role-name AppS3Read aws ec2 associate-iam-instance-profile --instance-id i-0abc123 --iam-instance-profile Name=AppS3Read
Who uses rolesExample
AWS servicesEC2 reading S3, Lambda writing to DynamoDB, ECS tasks
People in other accountsA role in the prod account that a dev account user assumes
Federated usersStaff signing in with company SSO (SAML, OIDC)
Applications outside AWSIAM Roles Anywhere, or OIDC from GitHub Actions
bash # Assume a role from the CLI aws sts assume-role --role-arn arn:aws:iam::222222222222:role/ProdReadOnly --role-session-name alice-check # returns AccessKeyId, SecretAccessKey, SessionToken, Expiratio
Rule of thumb: Never put access keys on an EC2 instance or in code. Attach a role. The SDK finds the temporary credentials automatically from the instance metadata service.

How AWS Decides: Policy Evaluation

  1. Everything is denied by default (implicit deny)
  2. An explicit Deny anywhere always wins
  3. An Allow is needed in the right places (identity policy, and resource policy for cross-account)
  4. SCPs and permission boundaries must also allow it
text Request ─► explicit Deny anywhere? ─ yes ─► DENIED │ no ▼ SCP (if Organizations) allows? ─ no ─► DENIED ▼ yes Permission boundary allows? ─ no ─► DENIED ▼ yes Identity or resource policy has an Allow? ─ no ─► DENIED (implicit) ▼ yes ALLOWED
CaseResult
Policy A allows s3:*, policy B denies s3:DeleteObjectDelete is denied (explicit deny wins)
No policy mentions EC2EC2 actions are denied (implicit deny)
Same account: identity policy allows, bucket policy silentAllowed (same account needs one allow)
Cross-account: identity policy allows but bucket policy of the other account does notDenied: both sides must allow

Useful Conditions

json { "Effect": "Deny", "Action": "*", "Resource": "*", "Condition": { "BoolIfExists": {"aws:MultiFactorAuthPresent": "false"} } }
json { "Effect": "Allow", "Action": "ec2:*", "Resource": "*", "Condition": { "StringEquals": {"aws:RequestedRegion": ["ap-south-1", "eu-west-1"]}, "IpAddress": {"aws:SourceIp": "203.0.113.0/24"} } }
Condition keyUse
aws:MultiFactorAuthPresentRequire MFA for sensitive actions
aws:SourceIp, aws:SourceVpceLimit by network or VPC endpoint
aws:RequestedRegionAllow only certain Regions
aws:PrincipalTag, aws:ResourceTagAttribute-based access control (ABAC): allow when tags match
aws:PrincipalOrgIDAllow only principals in your AWS Organization
aws:SecureTransportRequire HTTPS

Users, Passwords and Keys

  • Set a password policy (length, rotation if required) and MFA for every human user
  • Use groups to attach permissions to many users at once
  • Access keys: create only when needed, two per user at most, rotate, delete unused. Check the credential report
  • For humans prefer IAM Identity Center (single sign-on) over many IAM users
  • Use IAM Access Analyzer to find resources shared outside your account and to generate least-privilege policies from CloudTrail activity
bash aws iam generate-credential-report && aws iam get-credential-report --query Content --output text | base64 -d | head aws iam list-access-keys --user-name alice aws iam get-account-password-policy aws accessanalyzer list-analyzers

Least Privilege in Practice

  1. Start with no access, add what is needed
  2. Use AWS managed policies to start, then replace with narrow custom policies
  3. Scope by resource ARN and condition, not just action
  4. Review with Access Analyzer and the last accessed information in IAM, remove unused permissions
  5. Separate duties: developers, admins, auditors
  6. Give break-glass admin access only through an audited, MFA-protected role
Avoid: "Action": "*", "Resource": "*" for anything except a temporary lab. It is the same as handing over the whole account.

Practice Tasks

  1. Create a group Developers, attach ReadOnlyAccess, add a user, and test that the user cannot create an EC2 instance
  2. Write a policy that lets a role read only the prefix reports/ of one bucket
  3. Create a role for EC2 with S3 read access and attach it to an instance, then run aws s3 ls on the instance without keys
  4. Write a policy that denies everything unless MFA is present
  5. Create a role in a second account and assume it with aws sts assume-role

Conclusion

IAM controls access with users, groups, roles and policies. Everything is denied by default, an explicit deny always wins, and roles give temporary credentials so no keys are stored. Use least privilege, MFA, conditions, Access Analyzer and roles for every AWS service and application.

Quick Summary: users/groups/roles/policies; JSON structure + ARNs; policy types; roles + trust policy + instance profile; evaluation order; conditions (MFA, Region, tags); keys + credential report; least privilege.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators