AWS Builder Center
Amazon EKS IAM Roles for Service Accounts (IRSA): Secure Access to AWS Services Without Access Keys

Amazon EKS IAM Roles for Service Accounts (IRSA): Secure Access to AWS Services Without Access Keys

Learn how Amazon EKS pods securely access AWS services using IAM Roles for Service Accounts (IRSA). This step-by-step guide explains Service Accounts, IAM Roles, OIDC, Trust Relationships, AWS STS, and how to eliminate long-term AWS access keys.

Building Reliable Systems in the Cloud | DevOps • Automation • I

Introduction

When deploying applications on Amazon EKS, one common question is:
How can my application access AWS services like Amazon S3, Secrets Manager, DynamoDB, or Amazon SQS without storing AWS access keys inside the pod?
Many teams initially create an IAM user, generate access keys, and store them as Kubernetes Secrets. While this works, it isn't the recommended approach because access keys are long-lived credentials that need to be managed, rotated, and protected.
Amazon EKS provides a better solution called IAM Roles for Service Accounts (IRSA). With IRSA, your application can securely access AWS services using temporary credentials without storing any AWS access keys.
A diagram comparing two ways for Amazon EKS applications to access AWS services: using Kubernetes Secrets with long-lived AWS access keys and using IAM Roles for Service Accounts (IRSA) with temporary credentials.


Why Not Use AWS Access Keys?

A common approach looks like this:
  • Create an IAM User
  • Generate an Access Key and Secret Key
  • Store them as Kubernetes Secrets
  • Mount the Secrets into the application
Although this works, it has several drawbacks:
  • Long-term credentials
  • Manual key rotation
  • Higher security risk
  • Access keys stored inside the cluster
AWS recommends avoiding long-term credentials whenever possible.

What is a Kubernetes Service Account?

A Service Account provides an identity for a pod inside Kubernetes.
It helps Kubernetes identify the application running inside the cluster.
However, a Service Account cannot access AWS services by itself.
Something else is required to provide AWS permissions.

What is IRSA?

IRSA stands for IAM Roles for Service Accounts.
It connects a Kubernetes Service Account with an AWS IAM Role.
Instead of using AWS access keys, the application assumes the IAM Role and receives temporary credentials from AWS STS.
This allows the application to securely access AWS services.

How IRSA Works

The authentication process is simple:
  1. The application starts inside an Amazon EKS Pod.
  1. The Pod uses a Kubernetes Service Account.
  1. The Service Account is associated with an IAM Role.
  1. Amazon EKS verifies the Service Account using the cluster's OIDC provider.
  1. AWS STS validates the request and issues temporary credentials.
  1. The AWS SDK automatically uses these credentials to access AWS services.
The application never stores AWS access keys.

Step 1: Create an IAM Policy

Create an IAM policy with only the permissions your application needs.
Example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}

Step 2: Create an IAM Role

Create a new IAM Role and attach the IAM policy.
This role will later be associated with the Kubernetes Service Account.

Step 3: Configure the Trust Relationship

This is one of the most important steps.
The Trust Relationship tells AWS which Kubernetes Service Account is allowed to assume this IAM Role.
Example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>:sub": "system:serviceaccount:<NAMESPACE>:<SERVICEACOUNT _NAME>",
"oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>:aud": "sts.amazonaws.com"
}
}
}
]
}
Without the Trust Relationship, the pod cannot assume the IAM Role.

Step 4: Create a Kubernetes Service Account

Associate the IAM Role with the Service Account.
apiVersion: v1
kind: ServiceAccount
metadata:
name: app-service-account
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::<ACCOUNT_ID>:role/<ROLE_NAME>
The annotation tells Amazon EKS which IAM Role should be used.

Step 5: Update the Deployment

Use the Service Account in your Deployment.
spec:
serviceAccountName: <SERVICE_ACCOUNT_NAME>
No AWS access keys are required.

Verify the Configuration

Verify that the Service Account has the correct annotation.
kubectl describe serviceaccount <SERVICE_ACCOUNT_NAME>
From inside the pod, run:
aws sts get-caller-identity
If everything is configured correctly, you'll see the IAM Role instead of an IAM User.

AWS Services Commonly Used with IRSA

IRSA can be used with almost every AWS service.
Some common examples are:
  • Amazon S3
  • AWS Secrets Manager
  • Amazon DynamoDB
  • Amazon SQS
  • Amazon SNS
  • AWS Systems Manager Parameter Store
  • AWS KMS
  • Amazon CloudWatch
  • Amazon ECR

Common Mistakes

  • Forgetting to enable the EKS OIDC provider.
  • Missing or incorrect Trust Relationship.
  • Wrong namespace or Service Account name in the Trust Relationship.
  • Incorrect IAM Role annotation.
  • Giving AdministratorAccess to every application.
  • Sharing the same IAM Role across multiple applications.

Best Practices

  • Create a separate IAM Role for each application.
  • Grant only the permissions the application requires.
  • Avoid storing AWS access keys in Kubernetes Secrets.
  • Use temporary credentials through IRSA.
  • Monitor IAM Role usage with AWS CloudTrail.

Conclusion

IAM Roles for Service Accounts (IRSA) is the recommended way to allow applications running on Amazon EKS to securely access AWS services.
Instead of managing long-term AWS access keys, IRSA uses a Kubernetes Service Account, an IAM Role, the Amazon EKS OIDC provider, and AWS STS to provide temporary credentials automatically.
This approach improves security, simplifies credential management, and follows AWS security best practices.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article