AWS IRSA

This guide covers creating and configuring IAM roles for Kubernetes workloads running on EKS. IRSA enables your pods to securely access AWS services without managing static credentials.

How IRSA Works

IRSA uses OpenID Connect (OIDC) federation to allow Kubernetes service accounts to assume IAM roles:

  1. EKS exposes an OIDC provider endpoint for your cluster

  2. IAM trusts tokens issued by this OIDC provider

  3. Pods use projected service account tokens to authenticate

  4. AWS STS exchanges these tokens for temporary IAM credentials

This eliminates the need for long-lived access keys and provides fine-grained, pod-level access control.


Prerequisites

  • EKS cluster with OIDC provider configured (enabled by default on new clusters)

  • IAM permissions to create roles and policies

  • Your cluster's OIDC provider URL (found in the EKS console or via aws eks describe-cluster)


Creating an IAM Role

Step 1: Get Your OIDC Provider Information

Step 2: Create the IAM Trust Policy

Create a trust policy that allows the service account to assume the role. Replace the placeholders with your values:

💡 Multiple Service Accounts

To allow multiple service accounts to assume the same role, use StringLike with a wildcard pattern:

Use this carefully - it grants access to all service accounts in the namespace.

Step 3: Create the IAM Role

Step 4: Attach Policies to the Role

Attach the required policies for your application's AWS access:

Step 5: Configure Your Application

Add the role ARN annotation to your ServiceAccount configuration:


Common IAM Policies

AWS Secrets Manager (Read-Only)

For applications using External Secrets to fetch secrets:

S3 Bucket Access

For applications that need to read/write to S3:

SQS Queue Access

For ScaledJobs processing SQS messages:

DynamoDB Table Access

🔒 Least Privilege

Always scope policies to specific resources using ARNs rather than wildcards (*). This limits the blast radius if credentials are compromised.


Terraform Example

If you manage infrastructure with Terraform, here's a complete example:


Troubleshooting

Pod Cannot Assume Role

Error: An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation

  • Verify the trust policy includes the correct OIDC provider ARN

  • Check the service account name and namespace in the trust policy condition match exactly

  • Ensure the aud condition is set to sts.amazonaws.com

  • Verify the ServiceAccount annotation matches the role ARN exactly

Access Denied to AWS Resources

Error: An error occurred (AccessDenied) when calling the <Action> operation

  • Verify the IAM policy is attached to the role

  • Check resource ARNs in the policy match your actual resources

  • Ensure the policy actions include all required permissions

  • Check for any SCPs (Service Control Policies) that might be blocking access

Token Expired or Invalid

Error: ExpiredTokenException or InvalidIdentityToken

  • Ensure the OIDC provider is correctly configured in IAM

  • Verify the EKS cluster OIDC issuer URL matches the IAM OIDC provider

  • Check that the pod's service account token is being projected correctly

Debugging in Argo CD

Check Pod Logs:

  1. Navigate to your application in the Argo CD UI

  2. Expand the application tree to find your Pod

  3. Click on the Pod resource

  4. Select the Logs tab to view container output

  5. Look for AWS SDK errors or authentication failures

Check ServiceAccount Configuration:

  1. In the application tree, click on the ServiceAccount resource

  2. Select the Live Manifest tab

  3. Verify the eks.amazonaws.com/role-arn annotation is present and correct

Check Pod Environment:

  1. Click on the Pod resource

  2. Select the Live Manifest tab

  3. Look for the AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE environment variables (injected automatically)

  4. Verify the projected service account token volume is mounted

Check Events:

  1. Click on the Pod or Deployment resource

  2. Select the Events tab

  3. Look for warnings related to service account tokens or IAM authentication


Best Practices

🔒 Security Recommendations

  • One role per application: Create dedicated roles for each workload to isolate permissions

  • Use specific resource ARNs: Avoid wildcards in resource specifications

  • Namespace scoping: Include the namespace in trust policy conditions

  • Regular audits: Review and remove unused roles and policies

  • Use conditions: Add additional conditions (e.g., source IP, MFA) where appropriate

  • Tag resources: Tag IAM roles with application and team identifiers for cost allocation and auditing


Last updated

Was this helpful?