Overview
The IAM Module creates AWS IAM roles and policies for Artos application workloads running in EKS. Using IAM Roles for Service Accounts (IRSA), Kubernetes pods can securely access AWS services without hardcoded credentials. The module provisions separate roles for the backend application, Celery workers, and the AWS Load Balancer Controller, each with specific permissions tailored to their operational needs.Key Features
- OIDC-Based Authentication: Kubernetes service accounts assume IAM roles via OpenID Connect
- No Hardcoded Credentials: Temporary credentials automatically provided and rotated
- Least Privilege Access: Each component has only the permissions it needs
- Secure Credential Management: Access to Secrets Manager with KMS encryption
- CloudWatch Integration: Logging and metrics publication for observability
IAM Roles for Service Accounts (IRSA)
What is IRSA?
IAM Roles for Service Accounts (IRSA) is an AWS feature that allows Kubernetes service accounts to assume AWS IAM roles. This eliminates the need to store AWS credentials in your application code or Kubernetes secrets. How It Works:- EKS cluster has an OIDC identity provider
- Kubernetes service account is annotated with an IAM role ARN
- When a pod uses this service account, AWS STS provides temporary credentials
- Pod can make AWS API calls using these credentials
- Credentials automatically expire and rotate
- Security: No long-lived credentials stored in cluster
- Auditability: All AWS API calls logged in CloudTrail
- Isolation: Each workload has separate IAM permissions
- Automatic Rotation: Credentials refresh automatically
Core IAM Roles
1. Application Service Account Role
Purpose: Main backend API server that handles user requests, business logic, and data operations. Kubernetes Service Account:system:serviceaccount:default:app-service-account
AWS Permissions:
S3 Access
- Store and retrieve uploaded documents
- Save processed files and artifacts
- Manage user-generated content
- Access application assets and templates
Secrets Manager Access
- Retrieve database credentials
- Access API keys for third-party services
- Load application configuration secrets
- Get encryption keys for sensitive data
KMS Decryption
- Decrypt Secrets Manager secrets encrypted with KMS
- Access S3 objects encrypted with customer-managed keys
- Read encrypted configuration data
KMS Condition: The
ViaService condition ensures the KMS key can only be used by Secrets Manager and S3, not directly by the application. This adds an extra security layer.RDS IAM Authentication
- Connect to RDS PostgreSQL using IAM authentication
- Eliminate database password management
- Automatic credential rotation via IAM
Amazon Bedrock Access
- Generate AI-powered responses
- Process natural language queries
- Summarize documents
- Classify and analyze content
CloudWatch Logs
- Send application logs to CloudWatch
- Create structured log streams
- Enable centralized log aggregation
CloudWatch Metrics
- Publish custom application metrics
- Monitor business KPIs
- Track performance indicators
- Enable automated alerting
2. Celery Service Account Role
Purpose: Asynchronous task workers for background job processing, scheduled tasks, and long-running operations running within the Artos platform. Kubernetes Service Account:system:serviceaccount:default:celery-service-account
AWS Permissions: Same as Application Service Account
The Celery workers require identical permissions to the main application because they:
- Process documents stored in S3
- Access the same secrets for database and API connectivity
- Use Bedrock for AI processing in background jobs
- Write logs and metrics to CloudWatch
- Connect to RDS for data operations
3. AWS Load Balancer Controller Role
Purpose: Kubernetes controller that manages AWS Application Load Balancers (ALBs) and Network Load Balancers (NLBs) for Ingress resources. Kubernetes Service Account:system:serviceaccount:kube-system:aws-load-balancer-controller
AWS Permissions: Comprehensive Elastic Load Balancing and EC2 permissions
Key Capabilities:
Load Balancer Management
- Create and delete ALBs and NLBs
- Modify load balancer attributes
- Configure listeners and rules
- Manage SSL/TLS certificates
Target Group Operations
- Create target groups for Kubernetes services
- Register and deregister pod IPs as targets
- Configure health checks
- Manage target group attributes
Security Group Management
- Create security groups for load balancers
- Modify ingress/egress rules
- Tag resources for cluster association
Network Discovery
- Describe VPCs, subnets, and availability zones
- Query ENIs and instance metadata
- Discover ACM certificates for HTTPS
- You create a Kubernetes Ingress resource
- Load Balancer Controller detects the Ingress
- Controller creates an ALB in your VPC
- ALB routes traffic to Kubernetes service endpoints
- Controller updates target groups as pods scale
Module Configuration
Basic Configuration
Configuration with Multiple Secrets
For our deployment strategy only one set of secrets should be necessary.
Security Best Practices
1. Principle of Least Privilege
Each IAM role grants only the minimum permissions required for its workload. Example Custom Policy:2. Resource-Level Restrictions
Where possible, restrict permissions to specific resources rather than using wildcards. Good - Specific Resources:3. KMS Key Conditions
Always useViaService conditions with KMS permissions to ensure keys can only be used by specific AWS services.
4. Secrets Manager Naming Conventions
Use consistent naming patterns for secrets to enable prefix-based permissions. Recommended Structure:Troubleshooting
Pod Cannot Assume IAM Role
Symptoms: Application logs showUnable to locate credentials or AccessDenied errors.
Troubleshooting Steps:
- Verify Service Account Annotation:
- Check Pod Environment Variables:
- Verify IAM Trust Relationship:
- Test IAM Role Assumption:
Access Denied to AWS Service
Symptoms:AccessDenied or UnauthorizedOperation errors when accessing specific AWS services.
Solutions:
- Verify IAM Policy Permissions:
- Check Resource ARNs Match: Ensure S3 bucket ARNs, Secrets Manager ARNs, and KMS key ARNs in your IAM policy match the actual resources.
- Test Permissions from Pod:
KMS Decryption Errors
Symptoms:KMS.DisabledException or AccessDeniedException when accessing encrypted secrets.
Solutions:
- Verify KMS Key Policy: Ensure the KMS key policy allows the IAM role to decrypt:
- Check ViaService Condition:
Ensure KMS permissions include the correct
ViaServicecondition for Secrets Manager or S3.
Related Modules
- EKS Module - Provides OIDC provider for IAM role authentication
- S3 Module - S3 buckets that application roles access
- RDS Module - Database cluster for IAM authentication
- Bastion Module - Bastion host with IAM role for EKS management
Module Maintenance: This module is compatible with Terraform 1.0+ and AWS Provider 5.x. All IAM roles use OIDC authentication via the EKS cluster’s identity provider. Ensure the EKS module is deployed first to generate the OIDC provider.