- https://www.javierinthecloud.com/enable-an-iam-user-or-iam-role-to-access-an-eks-cluster/
- Type: tutorial
- Source: Javier in the Cloud · Javier Carrera · Nov 2023
TL;DR
Only the IAM principal that created an EKS cluster has admin access; to let others in, map their IAM ARN to a Kubernetes group with eksctl create iamidentitymapping.
Summary
Other IAM principals see “doesn’t have access to Kubernetes objects” or Unauthorized from kubectl. EKS authenticates through the IAM authenticator, which reads mappings in the aws-auth ConfigMap in kube-system. The cluster creator is implicitly system:masters outside that ConfigMap, so it can repair a broken ConfigMap. The article uses eksctl instead of editing the ConfigMap by hand and binds new principals to a read-only ClusterRole.
Key takeaways
- Find the creator via CloudTrail (or authenticator logs in CloudWatch) and use it to run
aws eks update-kubeconfig. - Inspect mappings with
eksctl get iamidentitymappingorkubectl -n kube-system get configmaps aws-auth -o yaml. - Create RBAC: a
cluster-viewerClusterRole (get/list) bound to acluster-viewer-group. - Grant access with
eksctl create iamidentitymapping --arn <arn> --username ... --group .... - Role ARNs cannot contain paths:
role/a/b/rdsaccessbecomesrole/rdsaccess. - No overwrite: delete the mapping with
eksctl delete iamidentitymapping, then recreate it. - Prefer federation over IAM users for people; groups need not pre-exist.
Tools and concepts
| Item | Role in the page |
|---|---|
| EKS | Managed Kubernetes and its aws-auth mapping |
| IAM | Users and roles being granted access |
| Kubernetes | RBAC ClusterRole and bindings |
| AWS | CloudTrail, CloudWatch, CLI |
When to use
- When a teammate or CI role cannot access an EKS cluster.
- When you need the aws-auth mapping steps.
- When explaining the cluster-creator-is-admin gotcha.
Caveats
- Needs
eksctl0.40.0 or later to manage clusters it did not create; newer EKS access entries may supersedeaws-auth.
EKS IAM Kubernetes AWS Security Cross-Account Access in the AWS Management Console Hacking an AWS hosted Kubernetes backed product, and failing