Skip to main content
This guide explains how to implement IAM Roles for Service Accounts (IRSA) for a Kubernetes cluster on Talos Linux. This allows Pods to access AWS services using temporary IAM credentials, similar to how EKS clusters in AWS function. While this example uses AWS S3 and Terraform, the general principles can be applied to any S3-compatible object store and adapted for other infrastructure-as-code tools or a manual setup. For the purpose of this guide, we will create a generic, read-only IRSA Role to test access to S3 from Talos Linux after the IRSA setup is complete. Administrators will need to create their own IAM Roles that target the specific AWS services they need to access from their Kubernetes Pods.

Prerequisites

Before you begin, you will need:
  • A Kubernetes cluster running on Talos Linux.
  • An AWS account with permissions to create S3 buckets, IAM roles, and OIDC providers.
  • git, ssh-keygen, go, kubectl, helm, and aws-cli installed locally.
  • Terraform (optional, for the examples provided).
This guide is based on the official instructions for setting up the Amazon EKS Pod Identity Webhook in a self-hosted environment.

Step 1: Set Up Environment Variables

First, set the following environment variables. These will be used throughout the guide.
Below is a description of each environment variable used in this guide.

OIDC Hosting Variables

  • AWS_ACCOUNT: Your 12-digit AWS account ID. Need help finding it?
  • AWS_REGION: The AWS region where you will create resources. Need help choosing one?
  • S3_BUCKET: A globally unique name for the S3 bucket that will host the OIDC discovery documents.
  • ISSUER_HOSTPATH: The public URL of the OIDC issuer (for example, https://${S3_BUCKET}.s3.amazonaws.com).

Token Signing Key Variables

  • PKCS_KEY: The PKCS#8-formatted public key file.
  • PRIV_KEY: The private key file (RSA) used for signing.
  • PUB_KEY: The public key file (RSA) corresponding to the private key.

IRSA Test Variables

  • NAMESPACE: The Kubernetes namespace for the ServiceAccount.
  • SERVICEACCOUNT_NAME: The name of the Kubernetes ServiceAccount.

Step 2: Create a Projected Token Signing Keypair

The projected Service Account tokens require a signing keypair.
  1. Clone the amazon-eks-pod-identity-webhook repository to get a helper script for creating the keys document:
  2. Generate an RSA keypair. These files will be used in later steps.

Step 3: Create OIDC Discovery Endpoint

An OIDC discovery endpoint consists of a public S3 bucket containing the JSON Web Key Set (JWKS) and an OpenID provider configuration document.

Create a Public S3 Bucket

The following Terraform example creates a publicly readable S3 bucket. You will need to provide the bucket name you defined in the $S3_BUCKET environment variable to Terraform (e.g., via a .tfvars file or command-line flag).
After creating the S3 bucket, you will create and upload the OIDC discovery documents.

Create and Upload OIDC Documents

  1. Generate the keys.json document using the Go tool from the amazon-eks-pod-identity-webhook repository. This command should be run from within the cloned repository directory.
  2. Create the OIDC discovery document, named openid-configuration:
  3. Upload both files to your public S3 bucket:

Step 4: Create OIDC Provider and S3 Read-Only IAM Role in AWS

Next, create the IAM OIDC identity provider in AWS and an IAM role that your Kubernetes Service Account can assume. The following Terraform example creates these resources. It assumes you are passing the environment variables you set earlier as Terraform variables (e.g., s3_bucket_name, aws_account_id, etc.).
Note: For the purpose of this guide, we are attaching the managed AmazonS3ReadOnlyAccess policy to demonstrate IRSA functionality. In a production environment, you should create and attach a custom IAM policy with the least privileges necessary for your specific application’s needs.

Step 5: Configure Talos machineconfig

Patch your Talos machineconfig to use the new Service Account issuer and signing key.
  1. Generate a patch file from a template. First, encode the private key:
    Note: The tr -d '\n' is used for portability between GNU and BSD base64.
  2. Create the patch file, machineconfig-patch.yaml:
  3. Apply the patch to your Talos configuration and update your cluster. For example, using talosctl:
  4. Export your kubeconfig and talosconfig for the updated cluster.

Step 6: Install Required Kubernetes Components

Two components are required on the cluster: cert-manager and amazon-eks-pod-identity-webhook.

Install cert-manager

  1. Add the Jetstack Helm repository:
  2. Install the cert-manager Helm chart:
Next, install the amazon-eks-pod-identity-webhook.

Install amazon-eks-pod-identity-webhook

  1. Add the jkroepke Helm repository:
  2. Install the amazon-eks-pod-identity-webhook Helm chart:

Step 7: Test AWS S3 Access

Finally, deploy a Pod with the configured Service Account to test access to AWS S3.
  1. Create a manifest for the ServiceAccount and a test Pod. The command below uses a heredoc to create test-pod.yaml and substitute the shell variables.
  2. Apply the manifest:
  3. Exec into the aws-cli Pod.and test access by listing S3 buckets:
    This command should list the S3 buckets in your AWS account, confirming that IRSA is correctly configured.