IAM security best practices ensure that AWS accounts, users, roles, and permissions follow least privilege, strong authentication, and continuous monitoring. IAM controls access to every AWS resource. A single weak policy, compromised credential, or over-privileged role can lead to total account takeover. Strong IAM security forms the foundation of AWS DevSecOps.
Understanding IAM Security
IAM (Identity and Access Management) controls:
• who can access AWS
• which services they can use
• which actions they can perform
• which resources they can operate on
IAM security enforces tight privilege boundaries, identity isolation, and continuous validation of access.
Key IAM Security Principles
Least Privilege
Users, roles, applications, and services should only have the minimum permissions needed. No wildcard actions or overly broad policies.
Zero Trust Access
Never trust identities by default. Enforce MFA, validate identity, and restrict permissions by context, conditions, and network boundaries.
Attribute-Based Access Control
Use conditions based on:
• IP
• organizationId
• tags
• identity type
This tightens access based on real context.
Credential Hygiene
Avoid long-lived access keys. Prefer IAM roles, temporary credentials, and session tokens.
Continuous Monitoring
IAM activity must be logged, evaluated, and monitored for anomalies.
Core IAM Best Practices
Enforce MFA Everywhere
Enable MFA on all:
• IAM users
• root account
• break-glass accounts
Mandatory for administrative roles.
Disable Root Account Access
Root account should never be used for daily tasks. Lock it down with:
• MFA
• strong password
• no access keys
Root account must remain unused.
Enforce Strong Identity Boundaries
Use role-based access instead of user-based access. Assign permissions to roles, then attach roles to users or services.
Use IAM Roles Instead of Access Keys
Applications should never use hardcoded credentials. Instead use:
• IAM roles
• instance profiles
• Lambda execution roles
• ECS task roles
• EKS IRSA roles
This eliminates secret exposure.
Enforce Short-Lived Credentials
Use:
• AWS STS assume-role
• session tokens
• IAM Identity Center short-lived tokens
Short-lived credentials reduce impact of compromise.
Avoid Wildcard Permissions
Never use:
Action: "*"
Resource: "*"
Replace with explicit API actions.
Enforce Resource-Level Permissions
Always specify:
• resources
• ARNs
• identity tags
Avoid granting permissions across all resources.
Use Permission Boundaries
Boundaries limit what a role can grant or use. Useful for delegating IAM creation safely.
Enforce Tag-Based Access
Use tags to restrict access based on:
• department
• project
• owner
Supports least privilege.
Secure Cross-Account Access
Cross-account roles must use:
• external IDs
• explicit resource ARNs
• trust policy restrictions
Never allow open trust relationships.
IAM Policy Best Practices
Structured IAM Policies
Use managed or custom policies with:
• explicit actions
• strict resource ARNs
• condition statements
Deny-By-Default Approach
Use explicit “Deny” to block risky actions:
• deleting CloudTrail
• disabling Config
• using root user
• public S3 access
Use Condition Keys
Enforce:
aws:MultiFactorAuthPresent
aws:SourceIp
aws:username
aws:PrincipalArn
aws:CalledVia
aws:PrincipalType
Conditions add contextual security.
Limit IAM Policy Size
Keep policies small for readability. Break into multiple managed policies if required.
Monitoring and Auditing IAM
Effective IAM security requires real-time monitoring.
Use CloudTrail
Log every IAM API call:
• iam:CreateUser
• iam:UpdateAssumeRolePolicy
• kms:Decrypt
• sts:AssumeRole
CloudTrail must be enabled for all accounts.
Enable IAM Access Analyzer
Detects:
• public resources
• cross-account access
• external principals
• insecure trust policies
Immediate identification of risky exposure.
Use AWS Config
Enable Config rules such as:
• restricted-ssh
• iam-user-mfa-enabled
• iam-policy-blocked-wildcard
• root-account-mfa-enabled
Enable GuardDuty
Detects anomalous IAM behavior:
• credential compromise
• unauthorized API calls
• impossible travel
• privilege escalation
IAM attacks must be caught in real time.
IAM Hardening Techniques
Enforce SCPs (Service Control Policies)
Apply at AWS Organizations level:
• deny root user
• deny public S3 buckets
• deny delete CloudTrail
• deny full wildcard IAM
• deny IAM PassRole misuse
SCPs are the strongest guardrail.
IAM Policy Validation
Run:
• Access Analyzer policy checker
• IAM policy simulator
This ensures policies behave safely.
Restrict PassRole
Misuse of PassRole can escalate privileges. Restrict roles that allow:
iam:PassRole
Explicitly list allowed ARNs.
Use Boundary Policies
Delegated administrators cannot grant permissions beyond their boundaries.
Enforce Maximum Session Duration
Control how long assumed roles remain active.
Full-Length Practical Section
Hands-on exercises to build real IAM security automation.
Practical 1: Enable MFA on All IAM Users
Check users:
aws iam list-users
Check MFA:
aws iam list-mfa-devices --user-name <username>
Fix non-compliant accounts.
Practical 2: Disable Root Access Keys
Check root keys:
aws iam get-account-summary
Delete them:
aws iam delete-access-key --access-key-id <key>
Practical 3: Create Least Privileged IAM Policy
Example: allow only S3 read:
{
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::mybucket/*"],
"Effect": "Allow"
}
Attach to role, not user.
Practical 4: Enforce Conditional Policies
Require MFA:
"Condition": {
"Bool": {"aws:MultiFactorAuthPresent": "true"}
}
Test login without MFA.
Practical 5: Implement STS Assume Role
Create role and assume:
aws sts assume-role --role-arn <arn> --role-session-name test
Verify short-lived credentials.
Practical 6: Detect IAM Misconfigurations With Access Analyzer
aws accessanalyzer create-analyzer --analyzer-name account-analyzer
View findings:
aws accessanalyzer list-findings
Practical 7: Use AWS Config to Check IAM Compliance
Enable rules:
aws configservice put-config-rule --config-rule file://iam-mfa.json
Use to detect non-compliant identities.
Practical 8: Detect Wildcard IAM Policies
Scan with tools:
checkov -d .
terrascan scan -d .
kics scan -p .
Fix wildcard permissions.
Practical 9: Restrict PassRole Permissions
Define safe IAM policy:
"iam:PassRole": [
"arn:aws:iam::<account>:role/allowed-role"
]
Test misuse — should fail.
Practical 10: Create SCP to Deny Admin Escalation
Example SCP:
{
"Effect": "Deny",
"Action": ["iam:CreatePolicy", "iam:PutRolePolicy"],
"Resource": "*"
}
Apply at AWS Org root.
Practical 11: Build a Strong AssumeRole Trust Policy
Use:
"Condition": {
"StringEquals": {"sts:ExternalId": "my-id"}
}
Test cross-account role assumption.
Practical 12: Monitor Suspicious IAM API Calls
Track with CloudTrail:
• CreateAccessKey
• PutUserPolicy
• PassRole
• AttachRolePolicy
Inspect events for anomalies.
Practical 13: Rotate IAM Access Keys Automatically
Use Lambda to:
• detect old keys
• disable
• delete
• notify user
Practical 14: Enforce IAM Identity Center
Replace IAM users with Identity Center (SSO).
Integrate with corporate identity provider.
Practical 15: Deploy IAM Credential Report Automation
Generate daily:
aws iam generate-credential-report
aws iam get-credential-report
Track:
• key age
• MFA status
• password age
Practical 16: Use IAM Access Advisor
Find unused permissions:
aws iam get-access-advisor --user-name <user>
Remove extra privileges.
Practical 17: Implement IAM Permission Boundaries
Assign boundaries:
aws iam put-user-permissions-boundary
Use for delegated IAM administration.
Practical 18: Enforce Least Privileged Roles For Lambda
Scan Lambda policies:
aws lambda get-policy
Remove broad privileges.
Practical 19: Control EKS IAM Access With IRSA
Create OIDC provider.
Assign per-pod IAM roles.
Eliminate node-role overprivilege.
Practical 20: Build Full IAM Security Architecture
Architecture includes:
• MFA everywhere
• root access locked
• least privilege
• STS-based access
• short-lived credentials
• Access Analyzer findings
• IAM Identity Center
• CloudTrail logging
• Config IAM rules
• GuardDuty monitoring
• IAM role separation
• OPA or custom IAM policies
• SCP guardrails
• automated key rotation
• SIEM integrations
This forms a complete AWS IAM security posture.
Intel Dump
• IAM security depends on MFA, least privilege, role-based access, and continuous monitoring
• Avoid access keys, prefer IAM roles
• Deny wildcards, enforce conditions, apply permission boundaries
• Use Config, GuardDuty, Access Analyzer, CloudTrail for auditing
• Secure cross-account trust and PassRole
• Practicals include MFA, key removal, assume-role, OPA, IAM scans, SCPs, IRSA, and full IAM governance architecture