Help improve this page
To contribute to this user guide, choose the Edit this page on GitHub link that is located in the right pane of every page.
Grant IAM users access to Kubernetes with a ConfigMap
Important
The aws-auth ConfigMap  is deprecated. For the recommended method to manage access to Kubernetes APIs, see Grant IAM users access to Kubernetes with EKS access entries.
Access to your cluster using IAM principals is enabled by the AWS IAM Authenticator for Kubernetesaws-auth
      ConfigMap. For all aws-auth
      ConfigMap settings, see Full Configuration Format
Add IAM principals to your Amazon EKS cluster
When you create an Amazon EKS cluster, the IAM principal 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 principal doesn’t appear in any visible configuration, so make sure to keep track of which principal originally created the cluster. To grant additional IAM principals the ability to interact with your cluster, 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.
Note
For more information about Kubernetes role-based access control (RBAC) configuration, see Using RBAC Authorization
- 
            Determine which credentials kubectlis using to access your cluster. On your computer, you can see which credentialskubectluses with the following command. Replace~/.kube/configwith the path to yourkubeconfigfile if you don’t use the default path.cat ~/.kube/configAn example output is as follows. [...] contexts: - context: cluster: my-cluster.region-code.eksctl.io user: admin@my-cluster.region-code.eksctl.io name: admin@my-cluster.region-code.eksctl.io current-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 other IAM principals. IAM best practices recommend that you grant permissions to roles instead of users. You can see which other principals currently have access to your cluster with the following command:kubectl describe -n kube-system configmap/aws-authAn example output is as follows. Name: aws-auth Namespace: kube-system Labels: <none> Annotations: <none> Data ==== mapRoles: ---- - groups: - system:bootstrappers - system:nodes rolearn: arn:aws:iam::111122223333:role/my-node-role username: system:node:{{EC2PrivateDNSName}} BinaryData ==== Events: <none> The previous example is a default aws-authConfigMap. Only the node instance role has access to the cluster.
- 
            Make sure that you have existing Kubernetes rolesandrolebindingsorclusterrolesandclusterrolebindingsthat you can map IAM principals to. For more information about these resources, see Using RBAC Authorizationin the Kubernetes documentation. - 
                  View your existing Kubernetes rolesorclusterroles.Rolesare scoped to anamespace, butclusterrolesare scoped to the cluster.kubectl get roles -Akubectl get clusterroles
- 
                  View the details of any roleorclusterrolereturned in the previous output and confirm that it has the permissions (rules) that you want your IAM principals to have in your cluster.Replace role-namewith arolename returned in the output from the previous command. Replacekube-systemwith the namespace of therole.kubectl describe role role-name -n kube-systemReplace cluster-role-namewith aclusterrolename returned in the output from the previous command.kubectl describe clusterrole cluster-role-name
- 
                  View your existing Kubernetes rolebindingsorclusterrolebindings.Rolebindingsare scoped to anamespace, butclusterrolebindingsare scoped to the cluster.kubectl get rolebindings -Akubectl get clusterrolebindings
- 
                  View the details of any rolebindingorclusterrolebindingand confirm that it has aroleorclusterrolefrom the previous step listed as aroleRefand a group name listed forsubjects.Replace role-binding-namewith arolebindingname returned in the output from the previous command. Replacekube-systemwith thenamespaceof therolebinding.kubectl describe rolebinding role-binding-name -n kube-systemAn example output is as follows. apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: eks-console-dashboard-restricted-access-role-binding namespace: default subjects: - kind: Group name: eks-console-dashboard-restricted-access-group apiGroup: rbac.authorization.k8s.io roleRef: kind: Role name: eks-console-dashboard-restricted-access-role apiGroup: rbac.authorization.k8s.ioReplace cluster-role-binding-namewith aclusterrolebindingname returned in the output from the previous command.kubectl describe clusterrolebinding cluster-role-binding-nameAn example output is as follows. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: eks-console-dashboard-full-access-binding subjects: - kind: Group name: eks-console-dashboard-full-access-group apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: eks-console-dashboard-full-access-clusterrole apiGroup: rbac.authorization.k8s.io
 
- 
                  
- 
            Edit the aws-authConfigMap. You can use a tool such aseksctlto update theConfigMapor you can update it manually by editing it.ImportantWe recommend using eksctl, or another tool, to edit theConfigMap. For information about other tools you can use, see Use tools to make changes to the aws-authConfigMapin the Amazon EKS best practices guides. An improperly formatted aws-authConfigMapcan cause you to lose access to your cluster.- 
                  View steps to edit configmap with eksctl. 
- 
                  View steps to edit configmap manually. 
 
- 
                  
Edit Configmap with Eksctl
- 
               You need version 0.215.0or later of theeksctlcommand line tool installed on your device or AWS CloudShell. To install or updateeksctl, see Installationin the eksctldocumentation.
- 
               View the current mappings in the ConfigMap. Replacemy-clusterwith the name of your cluster. Replaceregion-codewith the AWS Region that your cluster is in.eksctl get iamidentitymapping --cluster my-cluster --region=region-codeAn example output is as follows. ARN USERNAME GROUPS ACCOUNT arn:aws:iam::111122223333:role/eksctl-my-cluster-my-nodegroup-NodeInstanceRole-1XLS7754U3ZPA system:node:{{EC2PrivateDNSName}} system:bootstrappers,system:nodes
- 
               Add a mapping for a role. Replace my-rolewith your role name. Replaceeks-console-dashboard-full-access-groupwith the name of the group specified in your KubernetesRoleBindingorClusterRoleBindingobject. Replace111122223333with your account ID. You can replaceadminwith any name you choose.eksctl create iamidentitymapping --cluster my-cluster --region=region-code \ --arn arn:aws:iam::111122223333:role/my-role --username admin --group eks-console-dashboard-full-access-group \ --no-duplicate-arnsImportantThe role ARN can’t include a path such as role/my-team/developers/my-role. The format of the ARN must bearn:aws:iam::. In this example,111122223333:role/my-rolemy-team/developers/needs to be removed.An example output is as follows. [...] 2022-05-09 14:51:20 [ℹ] adding identity "{arn-aws}iam::111122223333:role/my-role" to auth ConfigMap
- 
               Add a mapping for a user. IAM best practices recommend that you grant permissions to roles instead of users. Replace my-userwith your user name. Replaceeks-console-dashboard-restricted-access-groupwith the name of the group specified in your KubernetesRoleBindingorClusterRoleBindingobject. Replace111122223333with your account ID. You can replacemy-userwith any name you choose.eksctl create iamidentitymapping --cluster my-cluster --region=region-code \ --arn arn:aws:iam::111122223333:user/my-user --username my-user --group eks-console-dashboard-restricted-access-group \ --no-duplicate-arnsAn example output is as follows. [...] 2022-05-09 14:53:48 [ℹ] adding identity "arn:aws:iam::111122223333:user/my-user" to auth ConfigMap
- 
               View the mappings in the ConfigMapagain.eksctl get iamidentitymapping --cluster my-cluster --region=region-codeAn example output is as follows. ARN USERNAME GROUPS ACCOUNT arn:aws:iam::111122223333:role/eksctl-my-cluster-my-nodegroup-NodeInstanceRole-1XLS7754U3ZPA system:node:{{EC2PrivateDNSName}} system:bootstrappers,system:nodes arn:aws:iam::111122223333:role/admin my-role eks-console-dashboard-full-access-group arn:aws:iam::111122223333:user/my-user my-user eks-console-dashboard-restricted-access-group
Edit Configmap manually
- 
               Open the ConfigMapfor editing.kubectl edit -n kube-system configmap/aws-authNoteIf 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 principals to the ConfigMap. An IAM group isn’t an IAM principal, so it can’t be added 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. For example, you can’t specify an ARN such as arn:aws:iam::. The ARN needs to be111122223333:role/my-team/developers/role-namearn:aws:iam::instead.111122223333:role/role-name
- 
                           username: The user name within Kubernetes to map to the IAM role. 
- 
                           groups: The group or list of Kubernetes groups to map the role to. The group can be a default group, or a group specified in a clusterrolebindingorrolebinding. For more information, see Default roles and role bindingsin the Kubernetes documentation. 
 
- 
                           
- 
                     To add an IAM user: IAM best practices recommend that you grant permissions to roles instead of users. Add the user details to the mapUserssection of theConfigMap, 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: The group, or list of Kubernetes groups to map the user to. The group can be a default group, or a group specified in a clusterrolebindingorrolebinding. For more information, see Default roles and role bindingsin the Kubernetes documentation. 
 
- 
                           
 
- 
                     
- 
               For example, the following YAML block contains: - 
                     A mapRolessection that maps the IAM node instance to Kubernetes groups so that nodes can register themselves with the cluster and themy-console-viewer-roleIAM role that is mapped to a Kubernetes group that can view all Kubernetes resources for all clusters. For a list of the IAM and Kubernetes group permissions required for themy-console-viewer-roleIAM role, see Required permissions.
- 
                     A mapUserssection that maps theadminIAM user from the default AWS account to thesystem:mastersKubernetes group and themy-useruser from a different AWS account that is mapped to a Kubernetes group that can view Kubernetes resources for a specific namespace. For a list of the IAM and Kubernetes group permissions required for themy-userIAM user, see Required permissions.Add or remove lines as necessary and replace all example values with your own 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: | - groups: - system:bootstrappers - system:nodes rolearn: arn:aws:iam::111122223333:role/my-role username: system:node:{{EC2PrivateDNSName}} - groups: - eks-console-dashboard-full-access-group rolearn: arn:aws:iam::111122223333:role/my-console-viewer-role username: my-console-viewer-role mapUsers: | - groups: - system:masters userarn: arn:aws:iam::111122223333:user/admin username: admin - groups: - eks-console-dashboard-restricted-access-group userarn: arn:aws:iam::444455556666:user/my-user username: my-user
 
- 
                     
- 
               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 principals. If you’ve launched self-managed nodes and haven’t applied the aws-auth
         ConfigMap to your cluster, you can do so with the following procedure.
- 
            Check to see if you’ve 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 https://s3.us-west-2.amazonaws.com/amazon-eks/cloudformation/2020-10-29/aws-auth-cm.yaml
- 
                  In the aws-auth-cm.yamlfile, set therolearnto the Amazon Resource Name (ARN) of the IAM role associated with your nodes. You can do this with a text editor, or by replacingmy-node-instance-roleand running the following command:sed -i.bak -e 's|<ARN of instance role (not instance profile)>|my-node-instance-role|' aws-auth-cm.yamlDon’t modify any other lines in this file. ImportantThe role ARN can’t include a path such as role/my-team/developers/my-role. The format of the ARN must bearn:aws:iam::. In this example,111122223333:role/my-rolemy-team/developers/needs to be removed.You 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.yamlNoteIf you receive any authorization or resource type errors, see Unauthorized or access denied (kubectl) in the troubleshooting topic. 
 
- 
                  
- 
            Watch the status of your nodes and wait for them to reach the Readystatus.kubectl get nodes --watchEnter Ctrl+Cto return to a shell prompt.