πŸš€ DevOps & SRE Certification Program πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 πŸ” Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

AWS Tutorial: How to Give AWS Permissions to Pods in EKS?

Here’s a comprehensive tutorial on how to assign AWS permissions to Pods running in Amazon EKS, covering:

  • The problem it solves
  • All available options
  • Pros and cons of each method
  • A comparison table
  • Implementation guide for the recommended ones (IRSA and Pod Identity)


🧩 Problem Statement

In Kubernetes (EKS), your Pods often need to access AWS resources like:

  • S3 buckets to read/write files
  • DynamoDB to store session data
  • VPC Lattice for service networking
  • CloudWatch for logging

But how do we securely give AWS IAM permissions to a Pod?


πŸ” The Core Challenge

Unlike EC2 instances, Pods don’t have IAM roles by default. So, we need a secure way to assign IAM permissions to Pods.


βœ… Available Options

Option No.MethodRecommendedFine-GrainedSecureRequires OIDCNotes
1IAM Roles for Service Accounts (IRSA)βœ… Yesβœ… Yesβœ… Yesβœ… YesWidely used
2EKS Pod Identity (Agent-based)βœ… Yesβœ… Yesβœ… Yes❌ NoNewer method
3EC2 Instance IAM Role❌ No❌ No❌ No❌ NoAll Pods share role
4AWS Credentials in Secrets/Env Vars❌ Noβœ… Yes❌ No❌ NoInsecure
5Custom Identity Proxy/Sidecar Relay⚠️ Maybeβœ… Yesβœ… Yes❌ NoComplex, flexible

πŸ”Ž Option 1: IAM Roles for Service Accounts (IRSA)

πŸ”§ How it works:

  • You associate an IAM Role with a Kubernetes Service Account.
  • EKS uses OIDC (OpenID Connect) to let your Pod assume that IAM role.

πŸ›  Prerequisites:

  • EKS Cluster with OIDC provider enabled
  • IAM Role with trust relationship
  • Annotated Kubernetes ServiceAccount

βœ… Pros:

  • Secure & fine-grained
  • Widely supported in production
  • Works with eksctl, Terraform, AWS CLI

❌ Cons:

  • Requires OIDC setup
  • Slightly more steps

πŸ“˜ IRSA Setup Guide:

  1. Enable OIDC for your cluster (only once): eksctl utils associate-iam-oidc-provider --cluster <cluster-name> --approve
  2. Create IAM policy (example for S3 access): aws iam create-policy \ --policy-name MyAppS3Access \ --policy-document file://s3-policy.json
  3. Create IAM role for ServiceAccount: eksctl create iamserviceaccount \ --cluster <cluster-name> \ --namespace <namespace> \ --name <sa-name> \ --attach-policy-arn arn:aws:iam::<account-id>:policy/MyAppS3Access \ --approve
  4. Use the ServiceAccount in your deployment: serviceAccountName: <sa-name>

πŸ”Ž Option 2: EKS Pod Identity

πŸ”§ How it works:

  • Amazon EKS runs a Pod Identity Agent on each node.
  • Your Pod’s ServiceAccount is annotated with an IAM role.
  • The agent helps the Pod assume that IAM role β€” no OIDC needed.

βœ… Pros:

  • No need to set up OIDC
  • Easier for beginners
  • Native integration, evolving fast

❌ Cons:

  • Requires Pod Identity Agent (minor extra setup)
  • Newer, evolving feature

πŸ“˜ Pod Identity Setup Guide:

  1. Install Pod Identity Agent: eksctl enable pod-identity --cluster <cluster-name>
  2. Create IAM policy: aws iam create-policy \ --policy-name MyAppS3Access \ --policy-document file://s3-policy.json
  3. Create IAM role and bind to service account: eksctl create iamidentitymapping \ --cluster <cluster-name> \ --service-name <sa-name> \ --namespace <namespace> \ --arn arn:aws:iam::<account-id>:role/MyAppS3Access
  4. Annotate your ServiceAccount: kubectl annotate serviceaccount <sa-name> \ eks.amazonaws.com/role-arn=arn:aws:iam::<account-id>:role/MyAppS3Access \ -n <namespace>

πŸ”Ž Option 3: EC2 IAM Role for Node

πŸ›  How it works:

  • Attach the IAM role directly to EC2 instance/node.
  • All Pods on that node share the same permissions.

❌ Why it’s bad:

  • Not secure for multi-tenant or microservice workloads.
  • No fine-grained control β€” violates least privilege.

πŸ”Ž Option 4: Hardcoded AWS Credentials

πŸ›  How it works:

  • Manually inject AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY into the pod.

❌ Why it’s risky:

  • Credentials can leak
  • Hard to rotate and audit
  • Breaks cloud-native best practices

πŸ”Ž Option 5: Custom Sidecar Token Relay

πŸ›  How it works:

  • You run a sidecar container (e.g., Vault Agent, identity proxy) alongside your app.
  • The sidecar securely handles IAM calls or credential fetching.

βœ… When useful:

  • Complex enterprise setups with custom identity management
  • Using Vault for dynamic credential delivery

πŸ“Š Final Comparison Table

Feature / MethodIRSAPod IdentityEC2 RoleEnv VarsSidecar Proxy
Secureβœ…βœ…βŒβŒβœ…
Granular per-Pod IAM Rolesβœ…βœ…βŒβœ…βœ…
OIDC Requiredβœ…βŒβŒβŒβŒ
Easy to Set Up⚠️ Mediumβœ… Easyβœ…βœ…βŒ Complex
Production-readyβœ…βœ… (new)❌❌⚠️ Yes if done right
AWS-recommendedβœ…βœ…βŒβŒβŒ

πŸš€ Conclusion: What Should You Use?

If you’re…Use this method
Starting fresh in 2024+βœ… Pod Identity
Existing setup using IRSAβœ… Stick with IRSA
Insecure or legacy app❌ Avoid Env/EC2 roles
Complex identity control needed⚠️ Sidecar/Proxy + Vault

Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x