AWS IAM in Kubernetes (EKS)
Introduction
Table of Contents
The Problem with Static AWS Credentials
Why Static Credentials Are Dangerous
Risk
Impact
IAM Roles for Service Accounts (IRSA)
How It Works
IRSA Setup and Configuration
Prerequisites
Step 1: Create EKS Cluster with OIDC Enabled
Enable OIDC on an Existing Cluster
Step 2: Create an IAM Policy
Step 3: Create IAM Role with Trust Policy
Step 4: Create Annotated Kubernetes Service Account
Step 5: Deploy Your Application
EKS Pod Identity (The Modern Approach)
Key Differences from IRSA
Aspect
IRSA
EKS Pod Identity
EKS Pod Identity Setup
Step 1: Enable EKS Pod Identity Agent Add-on
Step 2: Create an IAM Role with Pod Identity Trust Policy
Step 3: Create Pod Identity Association
Step 4: Create Kubernetes Service Account (No Annotation Needed)
Step 5: Deploy Your Application
IRSA vs EKS Pod Identity Comparison
Detailed Comparison
Feature
IRSA
EKS Pod Identity
Application Code Integration
Go
Python
Node.js / TypeScript
IAM Policy Best Practices
Principle of Least Privilege
Condition Keys for IRSA
Resource-Based Policies (S3 Bucket Policy)
Common Service-Specific Policies
Cross-Account Access
Setup Cross-Account Access
Multi-Cluster and Multi-Environment Patterns
Pattern: One Role Per Service Per Environment
Managing with Terraform
Security Best Practices
1. Never Use StringLike with Wildcards in Trust Policies
StringLike with Wildcards in Trust Policies2. Enable CloudTrail for IAM Role Activity
3. Use AWS IAM Access Analyzer
4. Restrict the OIDC Audience
5. Set Maximum Session Duration Appropriately
6. Use AWS Secrets Manager Instead of Kubernetes Secrets for Sensitive Values
Troubleshooting
WebIdentityErr: Failed to Retrieve Credentials
AccessDenied When Calling AWS Service
IRSA: Role Not Being Assumed (No Annotation Effect)
EKS Pod Identity: Credentials Not Available
Validate IAM Permissions (Without Deploying)
What I Learned
Summary
Last updated