IAM Operations: Users, Roles, Policies, Permission Boundaries, Access Analyzer and Credential Hygiene
IAM Building Blocks
| Item | Meaning |
|---|---|
| Root user | Account owner with unlimited power. Enable MFA, no access keys, use only for the few tasks that need it, store credentials safely |
| IAM user | Long-term identity with password and/or access keys. Prefer Identity Center for humans |
| Group | Collection of users to attach policies to. Cannot contain groups and cannot be a principal |
| Role | Identity assumed temporarily by users, services, or other accounts. Has a trust policy (who can assume) and permission policies (what it can do). Gives short-term credentials through STS |
| Instance profile | Container that passes a role to an EC2 instance |
| Policy | JSON document of permissions |
Policy Types
| Policy type | Attached to | Purpose |
|---|---|---|
| Identity-based | Users, groups, roles | Grant permissions. Managed (AWS or customer) or inline |
| Resource-based | Resource (S3 bucket, KMS key, SQS queue, Lambda, role trust policy) | Grant access to principals, including cross-account |
| Permission boundary | User or role | Maximum permissions the identity can have (does not grant by itself) |
| Service control policy (SCP) | Organization root, OU or account | Guardrail for accounts. Does not grant. Does not affect the management account or service-linked roles |
| Session policy | Passed during AssumeRole | Further restricts that session |
| Resource control policy (RCP) | Organization | Guardrail on resources in member accounts |
| VPC endpoint policy | Endpoint | Restricts what can be used through the endpoint |
Policy Structure
json
{
"Version": "2012-10-17",
"Statement": [
{"Sid": "ReadOpsBucket", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::ops-reports", "arn:aws:s3:::ops-reports/*"],
"Condition": {"IpAddress": {"aws:SourceIp": "203.0.113.0/24"}, "Bool": {"aws:MultiFactorAuthPresent": "true"}}},
{"Sid": "DenyDeleteProd", "Effect": "Deny", "Action": "ec2:TerminateInstances", "Resource": "*",
"Condition": {"StringEquals": {"aws:ResourceTag/env": "prod"}}}
]}
- Elements:
Effect,Action/NotAction,Resource/NotResource,Principal(resource policies),Condition - Useful condition keys:
aws:SourceIp,aws:RequestedRegion,aws:PrincipalOrgID,aws:MultiFactorAuthPresent,aws:SecureTransport,aws:ResourceTag/<k>,aws:PrincipalTag/<k>,aws:SourceVpce - Attribute-based access control (ABAC): allow actions when the principal tag matches the resource tag, so permissions scale with tags
Policy Evaluation Logic
- By default everything is implicitly denied
- An explicit Deny anywhere (identity, resource, SCP, boundary, session) always wins
- Otherwise there must be an Allow in identity or resource policy and it must pass the guardrails (SCP, permission boundary, session policy)
- Same account: identity policy or resource policy allow is enough (unless a guardrail blocks)
- Cross-account: both the identity policy in the caller account and the resource policy in the owning account must allow (for roles: the role's trust policy plus the caller's permission to call
sts:AssumeRole)
Remember Explicit Deny > Allow > implicit Deny. SCPs and permission boundaries only limit. They never grant permissions on their own.
Roles and STS
bash
aws sts get-caller-identity
aws sts assume-role --role-arn arn:aws:iam::222222222222:role/OpsAdmin --role-session-name alice-ops --serial-number arn:aws:iam::111111111111:mfa/alice --token-code 123456 --duration-seconds 3600
aws iam create-role --role-name AppRole --assume-role-policy-document file://trust.json
aws iam attach-role-policy --role-name AppRole --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::111111111111:role/AppRole --action-names s3:GetObject --resource-arns arn:aws:s3:::ops-reports/a.csv
json
{"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Principal": {"Service": "ec2.amazonaws.com"}, "Action": "sts:AssumeRole"}]}
- Service roles (EC2, Lambda, ECS tasks) provide credentials automatically. Service-linked roles are created by services and cannot be edited
- Cross-account role: trust policy names the other account (add
ExternalIdfor third parties,aws:PrincipalOrgIDfor your org) - Role chaining limits the session to 1 hour. Session duration is 1 hour by default, up to the role's maximum (up to 12 hours)
- **
iam:PassRole** is needed to give a role to a service. Restrict it to the specific roles and services
Human Access: IAM Identity Center
- IAM Identity Center (successor to AWS SSO) gives workforce users single sign-on to many accounts using permission sets (policies applied as roles in each account), with a built-in directory or an external IdP (Entra ID, Okta) via SAML/SCIM
- Short-lived credentials, central MFA,
aws sso login - Prefer it to creating IAM users in every account
Credential Hygiene
| Practice | Detail |
|---|---|
| MFA for root and all humans | Virtual, FIDO2/passkeys or hardware. Require in policies for sensitive actions |
| Rotate or remove access keys | aws iam list-access-keys, get-access-key-last-used. Delete unused keys |
| Credential report | aws iam generate-credential-report then get-credential-report lists users with password age, MFA, key age |
| Password policy | Length, rotation, reuse prevention |
| No credentials in code | Use roles, Secrets Manager, environment injection. Scan repositories (git-secrets, GuardDuty/CodeGuru) |
| Leaked key response | Deactivate the key, review CloudTrail for use, rotate, check for new users/roles/resources, apply the AWS-opened support case guidance |
| Least privilege | Start from AWS managed job-function policies, then narrow using Access Analyzer policy generation from CloudTrail activity |
bash
aws iam generate-credential-report && aws iam get-credential-report --query Content --output text | base64 -d | head
aws iam list-users --query 'Users[].UserName'
aws iam get-account-summary --query 'SummaryMap.[AccountMFAEnabled,AccountAccessKeysPresent]'
aws iam update-access-key --user-name bob --access-key-id AKIA... --status Inactive
IAM Access Analyzer and Advisor
- External access analyzer: finds resources shared outside your account or organization (S3, IAM roles, KMS, Lambda, SQS, Secrets Manager...)
- Unused access analyzer: finds unused roles, users, keys and permissions
- Policy validation and custom policy checks for CI pipelines. Policy generation from CloudTrail
- IAM last accessed information (Access Advisor) shows which services a principal used, to trim permissions
Troubleshooting AccessDenied
- Read the error: it names the principal, action and resource and often the kind of policy that denied it
- Check identity policies attached to the principal and groups, then resource policy
- Look for explicit Deny, SCP, permission boundary, session policy, VPC endpoint policy
- Check conditions: MFA, source IP, region, tags, time,
aws:SourceVpce - For KMS: both the key policy (or grants) and IAM must allow
- Use the IAM policy simulator and CloudTrail (
errorCode,errorMessage) to confirm - For
UnauthorizedOperation, decode the message withaws sts decode-authorization-message
| Error | Meaning |
|---|---|
AccessDenied on AssumeRole | Trust policy does not include the caller, or caller lacks sts:AssumeRole, or MFA/ExternalId condition fails |
not authorized to perform iam:PassRole | Add iam:PassRole for that role ARN |
ExpiredToken | Session credentials expired, refresh |
InvalidClientTokenId / SignatureDoesNotMatch | Wrong, deleted or mistyped keys, or clock skew |
explicit deny in a service control policy | SCP blocks. Ask the organization admin |
Practice Tasks
- Create a role for EC2 with S3 read access and use it from an instance without keys
- Write a cross-account role and assume it from the CLI with MFA
- Add a permission boundary and prove it blocks
iam:CreateUser - Run the credential report and list keys older than 90 days
- Generate a least-privilege policy using Access Analyzer from CloudTrail
Conclusion
Use roles and Identity Center instead of long-lived keys, understand policy types and the evaluation rule (explicit deny wins, guardrails only limit, cross-account needs both sides), protect root and humans with MFA, review credentials and external access regularly, and troubleshoot AccessDenied with the error text, simulator and CloudTrail.
Quick Summary: building blocks; policy types; structure; evaluation; roles; Identity Center; hygiene; Access Analyzer; troubleshooting.

