EKS Unauthorized? Fix kubectl Access to Your AWS Cluster

EKS Unauthorized? Fix kubectl Access to Your AWS Cluster

You have just created an Amazon EKS cluster, or you have just joined a team that has one, and you run your first kubectl command. Instead of a list of pods, you get a single line that stops you cold: error: You must be logged in to the server (Unauthorized). The cluster exists. Your AWS credentials work. You can see the cluster in the console. But kubectl says you are not logged in, and nothing you try changes the message.

This error is the most common first experience people have with EKS, and it is confusing because it looks like a password problem when it is actually an identity mapping problem. kubectl is not failing to authenticate you to AWS. It is failing because AWS authenticated you successfully, and then the cluster could not find your identity on its list of people who are allowed in. The fix is to put your identity on that list, and this guide shows you how to do it, step by step, using the current recommended method. It also shows you how to diagnose the problem in minutes instead of an afternoon, because the same error has several different causes, and each one has a different fix.

This guide assumes you have a cluster already and that you can run the AWS CLI. If you are still setting up your first cluster, start with our AWS EKS tutorial, which walks through the happy path from cluster creation to your first deployment. This article picks up where that tutorial leaves off, at the moment the happy path breaks. If your error is an AWS access denied message rather than a Kubernetes unauthorized message, see our AWS access denied errors fix guide, which covers the IAM permission side of the problem.

What the Unauthorized Error Actually Means

The first thing to understand is that “Unauthorized” on EKS means something specific, and it is not what the words suggest. In Kubernetes, an unauthenticated request is one where the API server could not work out who you are. An unauthorized request, in the HTTP sense, is one where the server knows who you are and refuses you. EKS blurs that distinction in its error message, and the result is that people debug the wrong layer. The kubectl error says “You must be logged in to the server (Unauthorized)”, which is HTTP 401, and on EKS it means the API server could not map your AWS identity to any Kubernetes user. It is an authentication failure, not a permission failure, and no amount of Kubernetes RBAC work will fix it.

The distinction matters because EKS has a sibling error that looks similar and means something different. If kubectl returns Forbidden, HTTP 403, then the cluster knew who you are and decided you may not do that thing. That is a Kubernetes RBAC problem, and the fix is a RoleBinding or a ClusterRoleBinding that grants your identity the permission it needs. If kubectl returns could not get token: AccessDenied, then the AWS CLI could not even produce a token, which means your AWS credentials are missing, expired, or lack the eks:DescribeCluster permission needed to fetch the cluster details. That is an AWS credentials problem, and the fix is in your AWS configuration, not in the cluster. Three errors, three layers, three different fixes, and the first step in every case is to read the exact message and match it to the right layer.

There is a second distinction that causes as much confusion as the first. The IAM principal that created the cluster gets implicit administrator access. Nobody else does. That is the whole of the default access model: one identity in, everyone else out, until someone who is already in adds them. If a Terraform module or a continuous integration role created the cluster, then no human is mapped at all, and the first person to try kubectl will hit the Unauthorized error even though they have full AWS administrator permissions. AWS permissions and Kubernetes permissions are separate systems, and holding one does not grant the other. That separation is deliberate, and it is the reason this error exists at all.

How EKS Authentication Works

Understanding the fix requires understanding the chain of events behind a single kubectl command, and the chain has four links. First, kubectl reads your kubeconfig, which for EKS contains an exec plugin that calls the AWS CLI to get a token. The AWS CLI signs a request to the AWS Security Token Service, STS, using your current AWS credentials, and STS returns a token that proves you are who you claim to be. That token is a pre-signed URL, and it is valid for a short time, usually fifteen minutes. If IAM users, roles, and credentials are new to you, our AWS IAM tutorial for beginners explains the identity model this whole chain depends on.

Second, kubectl sends that token to the EKS API server. Third, the API server validates the token against STS, learns which IAM principal you are, and then has to answer a second question: which Kubernetes username and groups does this IAM principal correspond to? That mapping comes from one of two places. The current method is EKS access entries, which are stored in the EKS API and managed with the AWS CLI or the console. The legacy method is the aws-auth ConfigMap in the kube-system namespace, which maps IAM roles and users to Kubernetes usernames and groups. If your principal appears in neither list, there is no Kubernetes username to authorise, and the request is rejected as unauthenticated. That is the Unauthorized error.

Fourth, once the mapping exists, Kubernetes RBAC takes over and decides what your mapped username and groups are allowed to do. That is the layer where Forbidden errors come from, and it is a separate step from the mapping. The practical consequence is a debugging order: first confirm your AWS identity, then confirm the mapping exists, then worry about RBAC. Most people start at RBAC and waste an hour. Start at the identity.

The access entry method is the one AWS now recommends, and the aws-auth ConfigMap is deprecated in its favour. Access entries are managed through the EKS API, which means you can fix a broken kubectl without having a working kubectl, because every repair runs through the AWS CLI or the console. That is a real advantage over the ConfigMap, which could only be edited by someone who already had cluster access, and which, if misconfigured, could lock everyone out, including the cluster creator. The ConfigMap is still in use on many older clusters, so this guide covers both, but if your cluster supports access entries, use them.

Step 1: Confirm Who You Actually Are

The single most useful command in this whole guide is aws sts get-caller-identity. Run it in the same shell where kubectl fails, and it tells you exactly which AWS identity your current credentials resolve to: the account, the user or role name, and the full ARN. Read that ARN carefully, because it is the identity the cluster needs to see, and it is very often not the identity you think you are using. A common case is a role assumption: you believe you are using your IAM user, but your shell has assumed a role, and the ARN says assumed-role instead of user. Another common case is a profile switch: your AWS CLI is using a different profile from the one you intended, and the ARN belongs to a different account entirely.

The ARN also has a subtlety that causes a specific, recurring mistake. When you assume a role, get-caller-identity returns an ARN that starts with arn:aws:sts:: and contains assumed-role/RoleName/session-name. The aws-auth ConfigMap does not want that string. It wants the underlying role ARN, which starts with arn:aws:iam:: and looks like arn:aws:iam::111122223333:role/DeveloperRole. Copying the assumed-role ARN into the ConfigMap is the most common self-inflicted version of this error, and it fails silently: the mapping exists, but it never matches, because the authenticator compares the role ARN, not the session ARN. Access entries have the same rule in a different form: you create the entry for the IAM role ARN, not for a session.

# Who does AWS think you are, in this shell, right now?
aws sts get-caller-identity

# Example output for an assumed role
# {
#   "UserId": "AROAEXAMPLE:session-name",
#   "Account": "111122223333",
#   "Arn": "arn:aws:sts::111122223333:assumed-role/DeveloperRole/session-name"
# }
# The role ARN to use in the mapping is:
# arn:aws:iam::111122223333:role/DeveloperRole

# Which AWS profile and region is the CLI using?
aws configure list

# Check whether your identity can even describe the cluster
aws eks describe-cluster --name my-cluster --query cluster.status

Next, check which credentials kubectl is really using. Run kubectl config view --minify --raw and look at the exec block for the current context. It should show the AWS CLI being called with the right cluster name and region, and any environment variables that set the AWS profile. If the exec block sets a profile with an env section, that profile overrides whatever your shell has configured, and it is a common source of surprise. If the exec block points at a different cluster from the one you think you are using, you have found the problem: you are authenticating correctly, to the wrong cluster, where your identity is not mapped.

Step 2: Check Your kubeconfig and the Cluster

Before you change any access configuration, rule out the two mechanical failures that produce the same error message. The first is a stale or wrong kubeconfig. Regenerate it with aws eks update-kubeconfig --name my-cluster --region us-east-1, replacing the cluster name and region with your own, and then try kubectl again. This command rewrites the context for that cluster with the current endpoint and certificate authority data, and it fixes the cases where the cluster was recreated, the endpoint changed, or the kubeconfig was copied from another machine with an expired token baked in. If you manage several clusters, use the --alias flag to give each context a clear name, so you can tell them apart later.

# Regenerate the kubeconfig for your cluster
aws eks update-kubeconfig --name my-cluster --region us-east-1

# Confirm kubectl is talking to the right cluster
kubectl config current-context
kubectl config view --minify --raw

# Check the cluster authentication mode
aws eks describe-cluster --name my-cluster \
  --query cluster.accessConfig.authenticationMode

The second mechanical check is the cluster authentication mode, which decides which access mechanism your cluster uses. EKS clusters have an authentication mode, and the value tells you where to look for the mapping. If the mode is API, the cluster uses access entries only, and the aws-auth ConfigMap is ignored. If the mode is API_AND_CONFIG_MAP, both work, and the cluster checks access entries first and then the ConfigMap. If the mode is CONFIG_MAP, the cluster uses the ConfigMap only, and access entries will not help you. Knowing the mode before you start saves you from creating an access entry on a cluster that ignores access entries, or editing a ConfigMap on a cluster that ignores the ConfigMap. New clusters default to API mode, and older clusters are usually still on CONFIG_MAP or API_AND_CONFIG_MAP, which is why the mode is worth checking rather than assuming.

Also check the kubectl version against the cluster version. kubectl is supported within one minor version either side of the cluster version, so kubectl 1.37 works with clusters running 1.36, 1.37, and 1.38, but a kubectl that is several versions behind can produce authentication errors that look like access problems. Run kubectl version and compare the client version with the cluster version from aws eks describe-cluster. If they are far apart, update kubectl first, because no access fix will help a client the API server cannot understand.

Step 3: Fix It with EKS Access Entries

On a cluster whose authentication mode allows access entries, this is the fix, and it takes three AWS CLI commands. You need AWS permissions to manage access entries, which is a separate permission from cluster access: the IAM policy must allow eks:CreateAccessEntry and eks:AssociateAccessPolicy on the cluster. If you do not have those permissions, the person who created the cluster, or whoever holds AWS administrator rights, needs to run these commands for you. That is the normal shape of the fix: the cluster creator grants access, and the person who was locked out tries again.

The first command creates the access entry for your IAM identity. Use the IAM role or user ARN, not the assumed-role session ARN, and use the type STANDARD, which is the type for a normal human or service identity. The second command associates an access policy with the entry, and the policy decides what the identity may do inside the cluster. For a person who needs full administrative access, the AWS-managed policy is AmazonEKSClusterAdminPolicy, and its ARN is arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy. For a narrower role, such as a developer who should only work in one namespace, use a more limited policy and scope it to that namespace. Each IAM identity can have only one access entry, so if an entry already exists for your ARN, you need to update it rather than create a second one.

# Step 1: list the existing access entries and see if yours is there
aws eks list-access-entries --cluster-name my-cluster

# Step 2: create an access entry for your IAM role or user
aws eks create-access-entry --cluster-name my-cluster \
  --principal-arn arn:aws:iam::111122223333:role/DeveloperRole \
  --type STANDARD

# Step 3: associate the cluster admin access policy, cluster-wide
aws eks associate-access-policy --cluster-name my-cluster \
  --principal-arn arn:aws:iam::111122223333:role/DeveloperRole \
  --access-scope type=cluster \
  --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy

# Step 4: test it
kubectl get pods -A

If the fix worked, kubectl returns a list of pods immediately, with no delay and no further configuration. Access entries take effect quickly, and there is no propagation wait worth worrying about. If kubectl still returns Unauthorized, re-run aws sts get-caller-identity and compare the ARN character by character with the ARN in the access entry. A single wrong digit in the account number, or a role name that differs by one character, is enough to keep the error in place, and it is the most common reason the fix appears not to work. Also confirm that the cluster authentication mode allows access entries, because an entry created on a CONFIG_MAP mode cluster is silently ignored.

For a namespace-scoped grant instead of cluster admin, the associate command takes a namespace scope instead of a cluster scope. The command is the same shape, with --access-scope type=namespace,namespaces=my-namespace and a more limited policy ARN, such as the namespace-scoped edit or view policy. Scope narrowly when you can: cluster admin is the right grant for the person who owns the cluster, and it is the wrong grant for a developer who only needs one namespace. The AWS documentation on creating an access entry with an access policy lists the available policies and the exact scope syntax, and it is worth reading before you grant access to a production cluster.

Step 4: The Legacy aws-auth Route and the Terraform Case

On a cluster whose authentication mode is CONFIG_MAP, or API_AND_CONFIG_MAP where you prefer the ConfigMap, the fix is an entry in the aws-auth ConfigMap in the kube-system namespace. The ConfigMap has two sections: mapRoles, which maps IAM roles to Kubernetes usernames and groups, and mapUsers, which does the same for IAM users. To grant cluster admin access, map your role to the username cluster-admin is not the right approach; the standard mapping for full access is to the system:masters group, which is the built-in Kubernetes group that bypasses RBAC checks. The mapping below gives the DeveloperRole the system:masters group, which is the equivalent of cluster admin through the ConfigMap route.

# View the current aws-auth ConfigMap (requires existing cluster access)
kubectl get configmap aws-auth -n kube-system -o yaml

# Add a role mapping with eksctl (the safest way to edit it)
eksctl create iamidentitymapping --cluster my-cluster \
  --arn arn:aws:iam::111122223333:role/DeveloperRole \
  --group system:masters --username developer

# Or edit the ConfigMap directly, with care
kubectl edit configmap aws-auth -n kube-system

There are two warnings that apply to the ConfigMap route and not to access entries, and both are worth taking seriously. The first is that the ConfigMap is deprecated, and AWS recommends access entries for new access grants. If your cluster supports access entries, use them instead, and treat the ConfigMap as a legacy mechanism you maintain, not one you extend. The second is that a bad edit to the ConfigMap can lock everyone out, including the cluster creator. AWS re:Post is explicit about this: do not add the cluster creator to the ConfigMap, because the creator already has implicit access, and an incorrect ConfigMap can remove access for every IAM identity at once. If you must edit the ConfigMap by hand, make a backup of its current contents first, and prefer eksctl’s identity mapping command over a manual edit, because eksctl validates the change before applying it. The AWS re:Post article on resolving the Unauthorized error in Amazon EKS walks through the same steps with the same warnings, and it is the reference to keep open while you work.

The Terraform case deserves its own paragraph, because it is the most common way people end up locked out of a cluster they built themselves. If Terraform or a continuous integration role created the cluster, then that role is the cluster creator, and no human identity is mapped. Since version 20 of the Terraform AWS EKS module, even the cluster creator’s admin access is not granted by default, which means the module’s enable_cluster_creator_admin_permissions setting controls whether the creator can use kubectl at all. The fix is to set that value to true, or to add yourself under the module’s access_entries argument, and then apply. Do not try to fix a Terraform-built cluster by hand-editing the ConfigMap, because the next Terraform apply will overwrite your manual change and the error will return. Fix it in the Terraform configuration, so the fix survives the next apply.

Preventing It Next Time

The Unauthorized error is a symptom of an access process that was never written down, and the lasting fix is to write it down. Every EKS cluster should have a documented list of who has access, at what level, and through which mechanism, and that list should live in the same repository as the cluster configuration, not in one person’s memory. When a new team member joins, their access entry is created as part of onboarding, in the same pull request that adds them to the team. When someone leaves, their access entry is deleted as part of offboarding. When a cluster is created by Terraform, the access entries for the team are part of the same module, so the cluster is never created without its people.

A few practical rules make the process reliable. Prefer access entries over the aws-auth ConfigMap on every cluster that supports them, and migrate older clusters to API_AND_CONFIG_MAP mode so the ConfigMap can be retired gradually. Grant the narrowest access that lets a person do their job: cluster admin for the cluster owners, namespace-scoped edit access for developers, view access for anyone who only needs to look. Avoid long-lived IAM user credentials for cluster access; use roles with temporary credentials, and use SSO where your organisation supports it, because a role assumption is easier to audit and easier to revoke than a static access key. And keep the cluster creator identity intact and documented, because it is the recovery path when every other access mechanism fails. If the creator was a CI role, document which role it is and who can assume it, because that role is the only identity that can repair a cluster nobody can reach.

Finally, test access before you need it. After creating a cluster, have each team member run kubectl get pods from their own machine, with their own credentials, before the cluster carries anything important. Finding out that someone is locked out during an incident is the worst possible time to discover it. Finding out during setup is a five-minute fix. The commands in this guide are the same in both cases, but the pressure is very different, and the team that tests access early is the team that does not page anyone at two in the morning because kubectl says Unauthorized.

Frequently Asked Questions

What does “You must be logged in to the server (Unauthorized)” mean on EKS?

It means the EKS API server authenticated your AWS credentials but could not map your IAM identity to any Kubernetes user. Your identity is not in the cluster’s access entries or its aws-auth ConfigMap. It is an authentication failure, not a permission failure, so the fix is to add your identity to the cluster’s access list, not to change Kubernetes RBAC.

What is the difference between Unauthorized and Forbidden on EKS?

Unauthorized, HTTP 401, means the cluster does not know who you are: your IAM identity is not mapped. Forbidden, HTTP 403, means the cluster knows who you are and refuses the action: your identity is mapped but lacks the Kubernetes RBAC permission. Unauthorized is fixed with access entries or aws-auth. Forbidden is fixed with a RoleBinding or ClusterRoleBinding.

How do I add a user to an EKS cluster?

On a cluster that supports access entries, run aws eks create-access-entry with the user’s IAM ARN, then aws eks associate-access-policy with the access policy they need, such as AmazonEKSClusterAdminPolicy for full admin. On older clusters that use the aws-auth ConfigMap, add the identity with eksctl create iamidentitymapping or by editing the ConfigMap. You need AWS permissions to manage access entries, not kubectl access, to do this.

Why does kubectl fail when my AWS credentials work?

Because AWS permissions and Kubernetes permissions are separate systems. Your AWS credentials prove who you are to AWS, and they let you describe the cluster, but they do not by themselves grant access to the Kubernetes API. The cluster needs a separate mapping, an access entry or an aws-auth entry, that turns your IAM identity into a Kubernetes username. Only the identity that created the cluster gets that mapping automatically.

Can I fix EKS access without a working kubectl?

Yes. Access entries are managed through the AWS CLI and the console, so you can create an entry and associate a policy without any kubectl access at all. That is one of the main advantages of access entries over the aws-auth ConfigMap, which could only be edited by someone who already had cluster access. If you are locked out of a cluster nobody can reach, the cluster creator identity is the recovery path.

Conclusion

The EKS Unauthorized error looks like a login failure and is actually a missing mapping. Your AWS credentials work, the token is valid, and the cluster simply has no record of who you are in Kubernetes terms. The fix follows from that diagnosis: confirm your identity with aws sts get-caller-identity, check the kubeconfig and the cluster authentication mode, and then add your identity with an access entry, or with the aws-auth ConfigMap on older clusters. The whole repair runs through the AWS CLI, which is why you do not need a working kubectl to fix a broken kubectl.

Keep the lesson that comes with the fix. Access to a cluster is part of the cluster’s configuration, not an afterthought, and it belongs in the same repository, the same code review, and the same onboarding checklist as everything else. Create the access entries when you create the cluster, test them before the cluster carries anything important, and grant the narrowest access that lets each person do their job. The next time someone runs kubectl and sees a list of pods instead of an error, that is the process working, and it is worth the five minutes it takes to set up.

Scroll to Top