When two applications share an EKS node, they rarely need the same AWS permissions. EKS Pod Identity ties an IAM role to a Kubernetes service account in one namespace. A supported AWS SDK can pick up short-lived credentials from the Pod Identity Agent without storing AWS access keys in a Kubernetes Secret.
Prepare an isolated workload
Use an existing test EKS cluster with compatible Linux EC2 nodes and the Pod Identity Agent. EKS Auto Mode supplies the agent capability. The regular agent is not available for Fargate pods, so use a supported identity mechanism for those workloads. Your operator identity needs permissions to manage Pod Identity associations and to pass the selected IAM role, and your Kubernetes identity needs access to manage the test workload.
For a same-account example, create an IAM role that trusts pods.eks.amazonaws.com with sts:AssumeRole and sts:TagSession. Scope the role’s permissions to the workload’s exact AWS actions and resources. The trust policy below restricts the example to one cluster and one Kubernetes service account with Pod Identity session tags enabled. Replace the account, Region, and cluster in the ARN.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "pods.eks.amazonaws.com"},
"Action": ["sts:AssumeRole", "sts:TagSession"],
"Condition": {
"ArnEquals": {
"aws:SourceArn": "arn:aws:eks:us-east-1:111122223333:cluster/staging"
},
"StringEquals": {
"aws:RequestTag/kubernetes-namespace": "reports",
"aws:RequestTag/kubernetes-service-account": "report-reader"
}
}
}]
}
Bind the role to a service account
Use a Kubernetes context that points to the same cluster as the AWS CLI command. If the namespace and service account do not yet exist in your staging cluster, create them before creating the association.
kubectl create namespace reports
kubectl -n reports create serviceaccount report-reader
aws eks create-pod-identity-association \
--region us-east-1 --cluster-name staging \
--namespace reports --service-account report-reader \
--role-arn arn:aws:iam::111122223333:role/staging-report-reader \
--query 'association.associationId' --output text
In the staging deployment template, set spec.template.spec.serviceAccountName to report-reader. Apply the change and wait for new pods to roll out. Give association changes time to propagate. Existing pods do not receive the injected credential configuration retroactively.
Verify from inside a new pod
If the container has a current AWS CLI, run the following command. Otherwise, query the caller identity through the same supported SDK credential chain that the workload uses. The assumed-role ARN should name staging-report-reader. Next, exercise the specific read-only call that the workload needs. An identity check alone does not prove it has access to its intended resource.
kubectl -n reports exec deploy/report-worker -- \
aws sts get-caller-identity --query Arn --output text
If you see the wrong identity, confirm the pod’s service account, agent health on its node, and SDK version. Check for environment credentials or another provider that takes precedence. If the role is correct but a call fails, look at permissions for the specific action and resource. Restrict pod access to the EC2 Instance Metadata Service where appropriate, because the Pod Identity association alone does not prevent use of node credentials.
Remove the lab association
When finished, remove any staging workloads that depend on the role. Delete the association by its returned ID, then remove lab-only IAM and Kubernetes resources. Do not delete a shared agent or cluster add-on. An existing cluster and its EC2 worker nodes continue to incur their normal AWS charges.
See the AWS docs for worker and credential requirements, role trust and session tags, and associating a service account.







Leave a Reply