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, andaws-cliinstalled locally.- Terraform (optional, for the examples provided).
Step 1: Set Up Environment Variables
First, set the following environment variables. These will be used throughout the 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 theServiceAccount.SERVICEACCOUNT_NAME: The name of the KubernetesServiceAccount.
Step 2: Create a Projected Token Signing Keypair
The projected Service Account tokens require a signing keypair.-
Clone the
amazon-eks-pod-identity-webhookrepository to get a helper script for creating the keys document: -
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).
Create and Upload OIDC Documents
-
Generate the
keys.jsondocument using the Go tool from theamazon-eks-pod-identity-webhookrepository. This command should be run from within the cloned repository directory. -
Create the OIDC discovery document, named
openid-configuration: -
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.
-
Generate a patch file from a template. First, encode the private key:
Note: The
tr -d '\n'is used for portability between GNU and BSDbase64. -
Create the patch file,
machineconfig-patch.yaml: -
Apply the patch to your Talos configuration and update your cluster. For example, using
talosctl: -
Export your
kubeconfigandtalosconfigfor 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
-
Add the Jetstack Helm repository:
-
Install the
cert-managerHelm chart:
amazon-eks-pod-identity-webhook.
Install amazon-eks-pod-identity-webhook
-
Add the
jkroepkeHelm repository: -
Install the
amazon-eks-pod-identity-webhookHelm chart:
Step 7: Test AWS S3 Access
Finally, deploy a Pod with the configured Service Account to test access to AWS S3.-
Create a manifest for the
ServiceAccountand a testPod. The command below uses aheredocto createtest-pod.yamland substitute the shell variables. -
Apply the manifest:
-
Exec into the
aws-cliPod.and test access by listing S3 buckets:This command should list the S3 buckets in your AWS account, confirming that IRSA is correctly configured.