Your current user or role does not have access to Kubernetes objects on this EKS cluster
Once you’ve deployed an EKS cluster, and try to view this in the AWS Console, sometimes you may see the following message in your console:
"Your current user or role does not have access to Kubernetes objects on this EKS Cluster"
This happen because your AWS user account doesn't have access to the Kubernetes control plane. This because of when you create an Amazon EKS cluster, the IAM user or role who is created the the cluster is automatically granted system:masters permissions in the cluster's RBAC configuration. But if you acc ess the Amazon EKS console with IAM users or roles that aren't part of aws-auth ConfigMap you can't see the overview details for the cluster. To fix this, you need to add the IAM user or role to the aws-auth ConfigMap.
Grab User ARN
First you need to grab the User ARN which you want to add from the Identity and Access Management (IAM) page.
User ARN looks like this:
1 | arn:aws:iam::xxxxxxxxx:user/<user-name> |
Update aws-auth ConfigMap
Now you need to update the aws-auth ConfigMap with the User ARN you grabbed from the previous step. To do this, you need to run the following command:
1
kubectl edit configmap -n kube-system aws-auth
1 | kubectl edit configmap -n kube-system aws-auth |
This will open the aws-auth ConfigMap in your default text editor. Add the following line to the end of the file, replacing
1 | mapUsers: | |
For the root user, you can use the following command to add the root user to the aws-auth ConfigMap:
1 | mapUsers: | |
Warning: system:masters will give admin access to the cluster.
Save the file and exit the editor. The aws-auth ConfigMap is updated with the new IAM user or role. After a minute or so, once you revisit the EKS Cluster page in the AWS console, you will see all the relevant details.
Restrict access
If you want to give only read access to the cluster, it's ideal to create a Kubernetes cluster-role that allows read-only (get and list) access to the resources in the cluster.
Create a file named read-only.yaml with the following content:
1 | --- |
Then apply the above yaml file to the cluster using the following command:
1 | kubectl apply -f read-only.yaml |
Next, you have to bind the cluste-role with a group. To do it you need to create a file named read-only-role-binding.yaml with the following content:
1 | --- |
Then apply the above yaml file to the cluster using the following command:
1 | kubectl apply -f read-only-role-binding.yaml |
Finally, you have to add the IAM user or role to the aws-auth ConfigMap.
1 | mapUsers: | |