Enabling IAM user and role access to your cluster
Access to your cluster using AWS IAM entities is enabled by the AWS IAM
Authenticator for Kubernetesaws-auth
ConfigMap. For all aws-auth
ConfigMap settings, see Full Configuration Format
Add IAM users or roles to your Amazon EKS cluster
When you create an Amazon EKS cluster, the AWS Identity and Access Management (IAM) entity user or role, such as a federated user that creates the cluster, is automatically granted system:masters permissions
in the cluster's role-based access control (RBAC) configuration in the Amazon EKS control plane. This IAM entity doesn't appear in any visible configuration, so make sure to keep track of which IAM entity originally created the cluster. To grant additional AWS users or roles the ability
to interact with your cluster, you must edit the aws-auth ConfigMap within Kubernetes and create a Kubernetes rolebinding or clusterrolebinding with the name of a group that you specify in the aws-auth
ConfigMap.
For more information about different IAM identities, see Identities (Users, Groups, and
Roles) in the IAM User Guide. For more
information on Kubernetes role-based access control (RBAC) configuration, see
Using RBAC Authorization
To add an IAM user or role to an Amazon EKS cluster
-
Determine which credentials
kubectlis using to access your cluster. On your computer, you can see which credentialskubectluses with the following command. Replacewith the path to your~/.kube/configkubeconfigfile if you don't use the default path.cat~/.kube/configOutput
... contexts: - context: cluster:my-cluster.region-code.eksctl.iouser:admin@my-cluster.region-code.eksctl.ioname:admin@my-cluster.region-code.eksctl.iocurrent-context:admin@my-cluster.region-code.eksctl.io...In the previous example output the credentials for a user named
adminare configured for a cluster namedmy-cluster. If this is the user that created the cluster, then it already has access to your cluster. If it's not the user that created the cluster, then you need to complete the remaining steps to enable cluster access for the user, if you haven't already. -
Ensure that you have an existing Kubernetes
roleorclusterrolewith the permissions (rules) that you want your IAM users to have access to in your cluster and that you have an existing Kubernetesrolebindingorclusterrolebindingthat binds a Kubernetesgroupto theroleorclusterrole. For more information, see Using RBAC Authorizationin the Kubernetes documentation. You can view all of your existing roles,clusterroles,rolebindings, andclusterrolebindingsusing the following commands.kubectl get roles --all-namespaceskubectl get clusterroleskubectl get rolebindings --all-namespaceskubectl get clusterrolebindingsYou can then view the details of any of the resources using the following command. You can replace
rolewithclusterrole,rolebinding, orclusterrolebinding, replacerole-namewith the resource name (from the previous output), and replacekube-systemwith the namespace of the resource (from the previous output).kubectl describerolerole-name-nkube-system -
(Optional) Create a
clusterroleandclusterrolebindingorroleandrolebindingto enable IAM users to view nodes and workloads in the AWS Management Console.-
You can enable users to view Kubernetes resources for:
-
The cluster – This manifest creates a
clusterroleandclusterrolebinding. The group name in the file iseks-console-dashboard-full-access-group, which is the group that your IAM user or role needs to be mapped to in theaws-authConfigMap. You can change the name of thegroupbefore applying it to your cluster, if desired, and then map your IAM user or role to that group in theConfigMap.curl -o eks-console-full-access.yaml https://amazon-eks.s3.us-west-2.amazonaws.com/docs/eks-console-full-access.yaml -
A specific namespace – This manifest creates a
roleandrolebinding. The namespace in this file isdefault, so if you want to specify a different namespace, edit the file before applying it to your cluster. The group name in the file iseks-console-dashboard-restricted-access-group, which is the group that your IAM user or role needs to be mapped to in theaws-authConfigMap. You can change the name of the group before applying it to your cluster, if desired, and then map your IAM user or role to that group in theConfigMap.curl -o eks-console-restricted-access.yaml https://amazon-eks.s3.us-west-2.amazonaws.com/docs/eks-console-restricted-access.yaml
-
-
Apply the appropriate manifest using one of the following commands.
kubectl apply -f eks-console-full-access.yamlkubectl apply -f eks-console-restricted-access.yaml
-
-
Edit the
aws-authConfigMap.-
Open the
ConfigMapfor editing.kubectl edit -n kube-system configmap/aws-authNote If you receive an error stating "
Error from server (NotFound): configmaps "aws-auth" not found", then use the procedure in Apply the aws-auth ConfigMap to your cluster to apply the stockConfigMap. -
Add your IAM users, roles, or AWS accounts to the
ConfigMap. You cannot add IAM groups to theConfigMap.-
To add an IAM role (for example, for federated users): Add the role details to the
mapRolessection of theConfigMap, underdata. Add this section if it does not already exist in the file. Each entry supports the following parameters:-
rolearn: The ARN of the IAM role to add. This value can't include a path. The format of the value you provide must be
arn:aws:iam::. For more information, see aws-auth ConfigMap does not grant access to the cluster.111122223333:role/role-name -
username: The user name within Kubernetes to map to the IAM role.
-
groups: A list of groups within Kubernetes to which the role is mapped. For more information, see Default Roles and Role Bindings
in the Kubernetes documentation.
-
-
To add an IAM user: Add the user details to the
mapUserssection of the ConfigMap, underdata. Add this section if it does not already exist in the file. Each entry supports the following parameters:-
userarn: The ARN of the IAM user to add.
-
username: The user name within Kubernetes to map to the IAM user.
-
groups: A list of groups within Kubernetes to which the user is mapped to. For more information, see Default Roles and Role Bindings
in the Kubernetes documentation.
-
For example, the block below contains:
-
A
mapRolessection that adds the node instance role so that nodes can register themselves with the cluster. -
A
mapUserssection with the AWS usersadminfrom the default AWS account, and two operations users from a different AWS account. Theadminuser is added to thesystem:mastersKubernetes group.The operations users are added to Kubernetes groups that are used by the
roleandrolebindingandclusterroleandclusterrolebindingcreated by the manifests in the previous step, but you can replace them with whatever group you like. To enable users to view nodes and workloads in the AWS Management Console, they must have the mapping in the following example and theroleandrolebindingor theclusterroleandclusterrolebindingcreated by the manifests in the previous step.
Replace all
with your own values.example-values# Please edit the object below. Lines beginning with a '#' will be ignored, # and an empty file will abort the edit. If an error occurs while saving this file will be # reopened with the relevant failures. # apiVersion: v1 data: mapRoles: | - rolearn:arn:aws:iam::111122223333:role/eksctl-my-cluster-nodegroup-standard-wo-NodeInstanceRole-1WP3NUE3O6UCFusername:system:node:{{EC2PrivateDNSName}}groups: -system:bootstrappers-system:nodesmapUsers: | - userarn:arn:aws:iam::111122223333:user/adminusername:admingroups: -system:masters- userarn:arn:aws:iam::444455556666:user/ops-userusername:ops-usergroups: -eks-console-dashboard-full-access-group- userarn:arn:aws:iam::444455556666:user/ops-user2username:ops-user2groups: -eks-console-dashboard-restricted-access-group -
-
Save the file and exit your text editor.
-
Apply the aws-auth ConfigMap to
your cluster
The aws-auth
ConfigMap is automatically created and applied to your cluster when you
create a managed node group or when you create a node group using
eksctl. It is initially created to allow nodes to join your
cluster, but you also use this ConfigMap to add role-based access
control (RBAC) access to IAM users and roles. If you have not launched
self-managed nodes and applied the aws-auth
ConfigMap to your cluster, you can do so with the following
procedure.
To apply the aws-authConfigMap to your cluster
-
Check to see if you have already applied the
aws-authConfigMap.kubectl describe configmap -n kube-system aws-authIf you receive an error stating "
Error from server (NotFound): configmaps "aws-auth" not found", then proceed with the following steps to apply the stockConfigMap. -
Download, edit, and apply the AWS authenticator configuration map.
-
Download the configuration map.
curl -o aws-auth-cm.yaml https://amazon-eks.s3.us-west-2.amazonaws.com/cloudformation/2020-10-29/aws-auth-cm.yaml -
Open the file with a text editor. Replace
with the Amazon Resource Name (ARN) of the IAM role associated with your nodes, and save the file. Do not modify any other lines in this file.<ARN of instance role (not instance profile)>Important The role ARN cannot include a path. The format of the role ARN must be
arn:aws:iam::. For more information, see aws-auth ConfigMap does not grant access to the cluster.111122223333:role/role-nameapiVersion: v1 kind: ConfigMap metadata: name: aws-auth namespace: kube-system data: mapRoles: | - rolearn:<ARN of instance role (not instance profile)>username: system:node:{{EC2PrivateDNSName}} groups: - system:bootstrappers - system:nodesYou can inspect the AWS CloudFormation stack outputs for your node groups and look for the following values:
-
InstanceRoleARN – For node groups that were created with
eksctl -
NodeInstanceRole – For node groups that were created with Amazon EKS vended AWS CloudFormation templates in the AWS Management Console
-
-
Apply the configuration. This command may take a few minutes to finish.
kubectl apply -f aws-auth-cm.yamlNote If you receive any authorization or resource type errors, see Unauthorized or access denied (kubectl) in the troubleshooting section.
-
-
Watch the status of your nodes and wait for them to reach the
Readystatus.kubectl get nodes --watch

