Skip to content

Lesson 04 — Service Accounts & IAM Roles for Service Accounts (IRSA)

By the end of this lesson, you will be able to:

  • Understand Kubernetes Service Accounts
  • Differentiate User Accounts from Service Accounts
  • Learn how Pods authenticate to the Kubernetes API
  • Understand IAM Roles for Service Accounts (IRSA)
  • Learn how Amazon EKS integrates with AWS IAM
  • Identify common Service Account security risks
  • Apply enterprise best practices for workload identity

Applications running inside Kubernetes often need to communicate with:

  • Kubernetes API Server
  • Amazon S3
  • Amazon DynamoDB
  • Amazon SQS
  • Amazon SNS
  • AWS Secrets Manager
  • Amazon ECR
  • AWS KMS

The question is:

How should an application authenticate securely without storing AWS Access Keys inside the container?

Years ago, developers commonly stored AWS credentials inside:

  • Source code
  • Configuration files
  • Environment variables
  • Docker images

Today, this is considered a major security risk.

Modern Kubernetes environments solve this problem using:

  • Kubernetes Service Accounts
  • IAM Roles for Service Accounts (IRSA)

A Service Account is a Kubernetes identity used by applications and Pods.

Unlike a human user, a Service Account is designed specifically for workloads running inside the cluster.

Examples include:

  • Web applications
  • APIs
  • CI/CD pipelines
  • Monitoring tools
  • Security agents
  • Operators
  • Controllers

Every Pod can use a Service Account to authenticate to the Kubernetes API.


User Account Service Account
Human identity Application identity
Used by administrators Used by Pods
AWS IAM / OIDC / Certificates Kubernetes Service Account
Interactive login Automatic authentication
Managed externally Managed inside Kubernetes

Think of a Service Account as the digital identity of a workload.


Application Pod
Service Account
Authentication Token
Kubernetes API Server

The Pod automatically presents its Service Account identity whenever it communicates with the Kubernetes API.


Every Namespace automatically includes a Service Account called:

default

If a Pod does not specify a Service Account, Kubernetes automatically assigns the default Service Account.

Namespace
├── default Service Account
Pod
Uses default identity

Using the default Service Account in production is generally discouraged.


Enterprise applications typically use dedicated Service Accounts.

Example:

Namespace
├── payment-service
├── customer-service
├── inventory-service
└── monitoring-service

Each application receives its own identity.

This improves:

  • Security
  • Auditing
  • Permission management
  • Least privilege implementation

Authentication flow:

Application
Service Account
Token Mounted
API Server
Authenticated

The API Server verifies the Service Account token before processing requests.


Modern Kubernetes automatically creates short-lived Service Account Tokens.

These tokens are:

  • Automatically generated
  • Automatically rotated
  • Cryptographically signed
  • Mounted inside the Pod

Unlike older Kubernetes versions, long-lived tokens are no longer recommended.


Authentication identifies the Service Account.

RBAC determines what it can do.

Application
Service Account
RBAC
Permissions
API Access

Without RBAC, a Service Account has very limited access.


Payment API

Payment Service Account

RoleBinding

Payment Role

Read Secrets

Read ConfigMaps

Create Jobs

The application receives only the permissions defined by its Role.


Applications often require access to AWS services.

Examples:

Application
Amazon S3
Store Images
--------------------
Application
Secrets Manager
Retrieve Password
--------------------
Application
Amazon SQS
Send Messages

The challenge is granting AWS permissions securely.


Older applications stored AWS credentials inside Pods.

Application
AWS Access Key
AWS Secret Key
Amazon S3

Problems:

  • Hardcoded credentials
  • Credential theft
  • Difficult rotation
  • Shared secrets
  • High risk of compromise

This approach should never be used in production.


IAM Roles for Service Accounts (IRSA) allows Kubernetes workloads to assume AWS IAM Roles without storing AWS credentials.

Instead of embedding access keys inside containers, Pods receive temporary credentials from AWS.

IRSA is the recommended authentication mechanism for Amazon EKS.


Application Pod
Service Account
OIDC Provider
AWS STS
Temporary Credentials
IAM Role
Amazon S3

No static AWS credentials are stored inside the container.


Pod Starts
Uses Service Account
OIDC Token Generated
AWS STS Validates Token
IAM Role Assumed
Temporary Credentials Issued
Application Accesses AWS

Everything happens automatically.


IRSA relies on four major components.

Amazon EKS
OIDC Provider
IAM Role
Kubernetes Service Account

Together they establish a trusted relationship between Kubernetes and AWS IAM.


Amazon EKS creates an OpenID Connect (OIDC) identity provider.

The OIDC provider allows AWS IAM to trust identities issued by the Kubernetes cluster.

Amazon EKS
OIDC Provider
AWS IAM

Without OIDC, IRSA cannot function.


AWS STS issues temporary credentials after validating the Service Account identity.

Application
OIDC Token
AWS STS
Temporary Credentials

Benefits include:

  • Automatic expiration
  • Reduced credential theft risk
  • No long-lived access keys
  • Improved auditing

An image processing application uploads files to Amazon S3.

Architecture:

Image Processor
Service Account
IAM Role
AWS STS
Temporary Credentials
Amazon S3

Permissions:

  • Upload objects
  • Read objects
  • No bucket deletion
  • No IAM permissions
  • No EC2 permissions

The application only receives the permissions required for its task.


IRSA provides:

  • No hardcoded AWS credentials
  • Automatic credential rotation
  • Temporary credentials
  • Fine-grained IAM permissions
  • Improved auditing
  • Better compliance
  • Least privilege access
  • Secure workload identity

These benefits make IRSA the preferred identity solution for Amazon EKS.


Cloud Security Engineers commonly identify:

  • Using the default Service Account
  • Overprivileged Service Accounts
  • Shared Service Accounts across applications
  • Long-lived tokens
  • Wildcard RBAC permissions
  • Pods with cluster-admin privileges
  • Missing IAM restrictions
  • Hardcoded AWS credentials
  • Insecure token storage
  • Unused Service Accounts

Compromised Service Accounts can allow attackers to move laterally within the cluster.


Amazon EKS
├── Payment Namespace
│ └── Payment Service Account
│ └── Payment IAM Role
├── Customer Namespace
│ └── Customer Service Account
│ └── Customer IAM Role
├── Inventory Namespace
│ └── Inventory Service Account
│ └── Inventory IAM Role
└── Monitoring Namespace
└── Monitoring Service Account
└── CloudWatch IAM Role

Each workload has its own identity and permissions.


Security teams should monitor:

  • New Service Account creation
  • Deleted Service Accounts
  • Token usage
  • IAM Role assumptions
  • Failed STS requests
  • Unusual AWS API calls
  • Privilege escalation attempts
  • RoleBinding changes
  • ClusterRoleBinding changes
  • Cross-namespace Service Account usage

Continuous monitoring helps detect compromised workloads.


A development team stores AWS Access Keys inside a Docker image.

The image is accidentally pushed to a public container registry.

An attacker extracts the credentials and:

  • Reads confidential data from Amazon S3.
  • Launches EC2 instances for cryptocurrency mining.
  • Enumerates IAM users and roles.
  • Attempts privilege escalation.

If the application had used IRSA:

  • No AWS credentials would have existed inside the image.
  • Temporary credentials would have expired automatically.
  • IAM permissions would have been tightly scoped.
  • The attack impact would have been significantly reduced.

As a Kubernetes Security Engineer:

  • Create dedicated Service Accounts for every application.
  • Never use the default Service Account in production.
  • Implement IAM Roles for Service Accounts (IRSA).
  • Follow the Principle of Least Privilege.
  • Use temporary AWS credentials.
  • Rotate Kubernetes tokens automatically.
  • Monitor Service Account activity.
  • Restrict RBAC permissions.
  • Audit IAM Role usage regularly.
  • Remove unused Service Accounts promptly.

Workload identity is just as important as user identity in a secure Kubernetes environment.


After completing this lesson, you should understand:

  • What Kubernetes Service Accounts are
  • How workloads authenticate to the Kubernetes API
  • How RBAC authorizes Service Accounts
  • Why IAM Roles for Service Accounts (IRSA) are essential in Amazon EKS
  • The role of OIDC and AWS STS
  • Common Service Account security risks
  • Enterprise best practices for workload identity

Service Accounts and IRSA provide a secure, scalable, and cloud-native approach to authenticating workloads without exposing long-lived AWS credentials.


What is the primary purpose of a Kubernetes Service Account?

  • A. Authenticate human users
  • B. Provide an identity for applications and Pods
  • C. Create Worker Nodes
  • D. Schedule Pods

Answer: B


What Service Account is automatically assigned to a Pod if none is specified?

  • A. admin
  • B. system
  • C. default
  • D. cluster-admin

Answer: C


What is the primary purpose of IAM Roles for Service Accounts (IRSA)?

  • A. Improve Pod scheduling
  • B. Securely grant AWS permissions to Kubernetes workloads without storing AWS credentials
  • C. Replace Kubernetes RBAC
  • D. Encrypt Kubernetes Secrets

Answer: B


Which AWS service issues temporary credentials when using IRSA?

  • A. Amazon EC2
  • B. AWS Security Token Service (STS)
  • C. Amazon CloudWatch
  • D. Amazon Route 53

Answer: B


Which of the following is considered an enterprise best practice?

  • A. Use the default Service Account for all production workloads.
  • B. Store AWS Access Keys inside Docker images.
  • C. Create dedicated Service Accounts with least privilege IAM Roles.
  • D. Share one IAM Role across every application.

Answer: C


Learn how Kubernetes Secrets securely store and manage sensitive information such as passwords, API keys, certificates, and tokens, and understand enterprise best practices for protecting secrets in Amazon EKS.

➡️ Next Lesson: Lesson 05 — Kubernetes Secrets