AWS Builder Center
Secure EKS CI/CD: Least-Privilege IAM Patterns (OIDC, IRSA, Pod Identity)

Secure EKS CI/CD: Least-Privilege IAM Patterns (OIDC, IRSA, Pod Identity)

Stop using static AWS keys in your Kubernetes deployments. This guide provides a practical, step-by-step blueprint for enforcing least-privilege IAM in Amazon EKS pipelines using GitHub Actions OIDC, EKS Access Entries, and workload identity (IRSA/Pod Identity) to eliminate credential leaks and minimize blast radius.

Cloud Architect

1. Introduction

Most teams running Amazon EKS get the cluster right and the pipeline wrong.
The typical setup looks like this: a CI/CD job authenticates to AWS with a static access key stored as a secret, that key belongs to an IAM role with  AdministratorAccess  "to keep things simple," and the same identity is used to build, push, deploy, and — often — debug production directly. Inside the cluster, the story repeats: one broad  cluster-admin  binding services every pipeline run, and application pods quietly inherit the EC2 node's IAM role because nobody scoped a service account.
The risk isn't hypothetical. A leaked GitHub secret, a compromised third-party GitHub Action, or a misconfigured workflow trigger becomes a direct path to account-wide access the moment the pipeline's identity is over-permissioned. Compliance frameworks (SOC 2, ISO 27001, PCI-DSS) increasingly ask auditors to demonstrate least privilege explicitly — "we trust the pipeline" isn't an answer that survives a real audit.
This article covers a practical, implementable pattern for least-privilege IAM across the full delivery path: pipeline identity, cluster identity, and workload identity — with working examples for GitHub Actions and EKS.

2. Core Principles

Least privilege in the EKS context has three layers, not one:
  1. Pipeline identity — the credential your CI/CD system uses to talk to AWS (build, push, deploy).
  1. Cluster identity — how that pipeline identity is authorized inside Kubernetes (RBAC), separate from what it can do in AWS.
  1. Workload identity — the credential a running pod uses to call AWS services at runtime, which should have nothing to do with the pipeline's permissions.
Conflating these three is the root cause of almost every over-privileged EKS setup. A pipeline that can deploy an application should not automatically be able to read that application's S3 bucket, and an application pod should never inherit the broad permissions the node's EC2 instance profile carries.
IAM Roles for Service Accounts (IRSA) is the mechanism that keeps layer 3 honest. It binds an IAM role to a specific Kubernetes service account via OIDC federation, so only pods using that exact service account can obtain that role's temporary credentials — instead of every pod on a node sharing the node's instance profile. (EKS Pod Identity, covered in the checklist below, is the newer alternative to IRSA and is worth evaluating for new clusters — see the decision table in Section 6.)
Pipeline identity and application identity must stay separate. The role your GitHub Actions workflow assumes to run  kubectl apply  should never be the same role — or even the same IAM policy shape — as the role your payment service uses to read from DynamoDB at 2am. They have different blast radii, different audit requirements, and different lifecycles.

3.Recommended Architecture Pattern

eks architecture diagram

The pattern rests on two separate role families that never overlap:
Role
Used by
Assumed via
Scope
eks-pipeline-deploy-role
CI/CD workflow
GitHub OIDC → STS
Deploy to one namespace, in one cluster
app-runtime-role (per service account)
Running pod
IRSA / Pod Identity
Only the AWS resources that pod needs
If you're on Jenkins or Azure DevOps instead of GitHub Actions, the shape is identical — swap the OIDC provider URL and audience claim; both support workload-identity federation to AWS the same way.

4. Step-by-Step Implementation

4.1 Register the OIDC provider (one-time, per Git provider)

bash
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com \
--thumbprint-list <github-oidc-thumbprint>

4.2 Create the pipeline deploy role with a scoped trust policy

Restrict  sub  to the exact repository and branch — never use a wildcard here for anything touching production:
json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:your-org/your-repo:ref:refs/heads/main"
}
}
}
]
}
Attach a permission policy scoped to exactly what a deploy step does — not a managed "power user" policy:
json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PushImage",
"Effect": "Allow",
"Action": ["ecr:GetAuthorizationToken", "ecr:PutImage", "ecr:BatchCheckLayerAvailability", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload"],
"Resource": "arn:aws:ecr:us-east-1:123456789012:repository/frontend-app"
},
{
"Sid": "DescribeTargetClusterOnly",
"Effect": "Allow",
"Action": "eks:DescribeCluster",
"Resource": "arn:aws:eks:us-east-1:123456789012:cluster/prod-cluster"
}
]
}

4.3 Use the role in the GitHub Actions workflow

yaml
permissions:
contents: read
id-token: write # required to request the OIDC token — grants nothing on AWS by itself

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/eks-pipeline-deploy-role
aws-region: us-east-1

- run: aws eks update-kubeconfig --name prod-cluster
- run: kubectl apply -f k8s/frontend/ -n frontend

4.4 Map the pipeline role to Kubernetes RBAC via an EKS Access Entry

Prefer the EKS Access Entry API over hand-editing the  aws-auth  ConfigMap — it's the current AWS-recommended approach and removes a common source of "accidentally locked myself out of the cluster" incidents:
bash
aws eks create-access-entry \
--cluster-name prod-cluster \
--principal-arn arn:aws:iam::123456789012:role/eks-pipeline-deploy-role \
--kubernetes-groups ci-frontend-deployer
yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: deployment-writer
namespace: frontend
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["pods", "services", "configmaps"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ci-frontend-deployer-binding
namespace: frontend
subjects:
- kind: Group
name: ci-frontend-deployer
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: deployment-writer
apiGroup: rbac.authorization.k8s.io
Notice this is a  Role  +  RoleBinding , namespace-scoped — not a  ClusterRole . The pipeline can touch  frontend , nothing else.

4.5 Give the application its own runtime identity (IRSA)

bash
eksctl create iamserviceaccount \
--cluster prod-cluster \
--namespace frontend \
--name frontend-app-sa \
--attach-policy-arn arn:aws:iam::123456789012:policy/FrontendS3ReadOnly \
--approve
yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: frontend-app-sa
namespace: frontend
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/frontend-app-runtime-role
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
namespace: frontend
spec:
template:
spec:
serviceAccountName: frontend-app-sa # NOT default
containers:
- name: frontend
image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/frontend-app:latest

4.6 Network policies and Pod Security Standards — short version

Two additional guardrails close the gap that IAM alone can't cover:
  • Default-deny NetworkPolicy per namespace, explicitly allowing only the traffic each service needs. Kubernetes allows all pod-to-pod traffic by default — Calico or Cilium enforce the deny.
  • Pod Security Standards at  restricted , enforced via the built-in Pod Security Admission controller or an admission tool like Kyverno/OPA Gatekeeper — blocks root containers, host filesystem mounts, and privilege escalation regardless of what a developer's manifest says.
bash
kubectl label namespace frontend \
pod-security.kubernetes.io/enforce=restricted
Also block pod access to the EC2 instance metadata service (IMDS) for workloads that don't need node-role credentials, so a compromised pod can't fall back to the broader node IAM role:
bash
aws ec2 modify-instance-metadata-options \
--instance-id <node-instance-id> \
--http-tokens required \
--http-put-response-hop-limit 1

5. Common Mistakes to Avoid

  •  cluster-admin  bound to the pipeline's identity. If a workflow only deploys to  frontend , it should be structurally incapable of touching  kube-system  or any other namespace.
  • Long-lived access keys anywhere in the pipeline. If you find  AWS_ACCESS_KEY_ID  in a GitHub secret today, migrating to OIDC is the single highest-leverage fix available.
  • One role for build + deploy + runtime. Each has a different blast radius. A compromised build step (e.g., a malicious npm package) should not be able to touch the cluster at all if the build role has no  eks:*  permissions.
  • Trust policies without a  sub  or  aud  condition. A federated role trusted by "any GitHub repository" is functionally public — anyone with an Actions workflow anywhere can assume it.
  • Sharing one IRSA role across multiple unrelated service accounts. It's tempting for convenience, but it means a bug in one service can reach another service's AWS resources.
  • Reusing the default Kubernetes service account. Every pod that talks to AWS needs its own named service account with its own IRSA/Pod Identity role — never the namespace default.

6. Real-World Checklist / Decision Table

Situation
Recommended approach
New cluster, EC2-backed nodes, simple workload set
Start with EKS Pod Identity — no OIDC provider to manage, simpler association API
Mixed Fargate + EC2 nodes in the same cluster
IRSA for Fargate pods, Pod Identity for EC2 pods — both coexist without conflict
Multiple clusters need the same application role
Pod Identity (create a new association per cluster — no trust-policy edits needed)
AWS Load Balancer Controller / ExternalDNS / Cluster Autoscaler
Give each its own dedicated IRSA/Pod Identity role with a tightly scoped managed or custom policy — never reuse an application's role
Need cross-account resource access from a pod
IRSA (sts:AssumeRoleWithWebIdentity directly) or Pod Identity with role chaining
Auditing "who can do what" on the cluster
kubectl auth can-i --list --as=<principal> per role, cross-referenced against CloudTrail for the equivalent IAM role's API activity
Verifying no pipeline role is over-scoped
Run IAM Access Analyzer's policy-generation feature against CloudTrail activity for that role, and remove anything unused
Confirming node role isn't a backdoor
Check IMDSv2 hop limit = 1 on node launch templates; test that a pod without IRSA/Pod Identity can't reach 169.254.169.254 for credentials

7. Conclusion and Next Steps

Least privilege on EKS isn't one setting — it's keeping three identities (pipeline, cluster RBAC, and workload) intentionally separate, and reviewing each of them on a schedule rather than once at setup time. The pattern above — OIDC-federated pipeline roles, namespace-scoped RBAC via EKS Access Entries, and IRSA/Pod Identity for runtime credentials — covers the full path without adding real operational overhead once it's in place.
None of this needs a big-bang migration. Start with the pipeline: if a static AWS key is sitting in a CI secret today, replace it with OIDC this week. Then audit what your pods are actually running as, and give the ones still inheriting the node role their own scoped identity.
Try this pattern in your next pipeline, and see what you find when you actually look at what your CI role can do versus what it uses.
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