Core IAM Concepts and Components
AWS IAM has several interconnected components that work together to provide comprehensive access control.
Users, Groups, and Roles
Users are permanent identities representing a person or application with unique credentials. Groups are collections of users sharing the same permissions, making management efficient at scale. Roles are temporary identity containers without long-term credentials, designed for temporary access and cross-account delegation.
Users can be assigned to groups. Roles can be assumed by users or services. Policies attach to users, groups, or roles to grant permissions.
Policies and Permissions
Policies are JSON documents that define permissions, specifying allowed or denied actions on resources. The principle of least privilege means users and applications have only minimum permissions necessary for their tasks.
ARNs (Amazon Resource Names) uniquely identify AWS resources in a standardized format. Managed policies are created by AWS or your organization. Inline policies are directly embedded in users, groups, or roles.
Additional Security Components
Multi-factor authentication (MFA) adds extra security requiring additional verification beyond passwords. Trust policies define which principals can assume a role. Permission policies define what actions those principals can perform once they assume the role.
IAM Policies and Permission Structures
IAM policies control access through JSON documents containing statements. Each statement specifies four key elements.
Policy Evaluation Logic
Each statement includes:
- Effect (Allow or Deny)
- Action (specific AWS API calls)
- Resource (which resources)
- Condition (optional context requirements)
By default, all requests are denied (implicit deny). You must explicitly allow access. Explicit denies always override allows. The most restrictive policy wins in conflicts.
Action and Resource Specification
Specify exact actions using service prefix notation. S3 uses s3:GetObject. EC2 uses ec2:RunInstances. Wildcard characters (*) can be used but should be avoided in production due to security risks.
Advanced Policy Features
Condition blocks add context-based restrictions:
- Restrict access by IP address
- Require encryption
- Limit by date or time
- Require MFA
Service control policies (SCPs) operate at organization level limiting permissions across accounts. Resource-based policies attach to individual resources like S3 buckets defining which principals access them. Identity-based policies attach to principals. Resource-based policies attach to resources.
Roles, Temporary Credentials, and Cross-Account Access
IAM Roles grant temporary access to AWS resources without requiring long-term credentials. A role has a trust policy defining who can assume it and permission policies defining what they can do.
How Roles Work
When a user or service assumes a role, AWS provides temporary security credentials (access key ID, secret access key, and session token). These credentials expire automatically, typically after one hour. This temporary approach reduces security risk because credentials don't need manual rotation.
Service Roles
Service roles let AWS services access other resources securely. An EC2 instance with an IAM role can access S3 buckets without storing credentials on the instance. Lambda functions execute with roles granting only necessary permissions. ECS tasks use roles for service access.
Cross-Account Access
Cross-account roles enable secure access between AWS accounts without sharing credentials. The trust relationship specifies which external account principals can assume the role, typically by account ID. This is common in multi-account organizations isolating development, staging, and production.
Federation allows external identities from corporate directories, SAML providers, or OpenID Connect to assume roles. The SecurityToken service (STS) manages temporary credential creation and underlies all role assumption operations.
IAM Best Practices and Security Considerations
Following IAM best practices builds secure AWS applications and maintains compliance.
Fundamental Best Practices
Never use the AWS root account for daily operations. Create individual IAM users with limited permissions for each person needing access. Enable MFA for all human users, especially the root account.
Regularly audit and remove unused users, groups, and roles. Implement the principle of least privilege consistently by granting only necessary permissions. Use managed policies whenever possible as they benefit from AWS updates.
Credential and Audit Management
Rotate access keys regularly, typically every 90 days. Delete old keys immediately. Store sensitive credentials in AWS Secrets Manager or Parameter Store rather than hardcoding them in applications.
Enable CloudTrail logging to audit all IAM actions and detect suspicious activity. Use resource-based policies on S3 buckets, SQS queues, and other resources. Implement password policies requiring strong passwords and expiration.
Advanced Security Measures
Use tags to organize IAM resources. Apply permission boundaries defining maximum permissions a principal can have. Review and update policies regularly as requirements change. Use IAM Access Analyzer to identify unused permissions.
IAM in Application Development and Testing
Understanding IAM is crucial for developers creating secure AWS applications.
Credential Management for Applications
Applications running in EC2 instances should use instance profiles with attached roles rather than embedding credentials. Lambda functions execute with appropriate execution roles granting only necessary permissions. For local development and testing, use temporary credentials from STS or AWS CLI profiles with limited permissions.
Never embed production credentials in code. Database services like RDS can use IAM database authentication, generating temporary credentials rather than storing passwords.
Testing and Validation
Create specific test IAM users and roles with restricted permissions mirroring production constraints. Integration tests should validate permission boundaries by attempting operations that should fail. Confirm they are properly denied.
Distributed Systems and DevOps
API Gateway can use IAM authorization to control access to REST or HTTP APIs. Microservices benefit from service-to-service IAM authorization where each service assumes a role with only needed permissions.
Enable CloudTrail and CloudWatch Logs to track API calls and identify permission-related failures. Create dedicated deployment roles for CI/CD pipelines separate from developer roles. Understanding IAM error messages like AccessDenied is essential for efficient debugging during development.
