kubectl on Amazon EKS says the server asked for credentials
Your error
error validating data: failed to download openapi: the server has asked for the client to provide credentials; if you choose to ignore these errors, turn validation off with --validate=false2 more lines it can showFix it fast
Most common cause, 1 of 4The IAM role that runs kubectl has no access entry
Create an access entry for the role, written in the form arn:aws:iam::<account>:role/<name>, then attach an access policy to it.
aws eks create-access-entry --cluster-name my-cluster \
--principal-arn arn:aws:iam::111122223333:role/my-jenkins-role --type STANDARD
aws eks associate-access-policy --cluster-name my-cluster \
--principal-arn arn:aws:iam::111122223333:role/my-jenkins-role \
--access-scope type=cluster \
--policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSEditPolicyShort answer
"The server has asked for the client to provide credentials" is Kubernetes wording for HTTP 401. On Amazon EKS it means the IAM principal behind kubectl, often a Jenkins or CI role, maps to no Kubernetes user. Run aws sts get-caller-identity, then create an EKS access entry (or aws-auth mapping) for that ARN on Kubernetes 1.34 to 1.37 clusters.
Which cause do you have?
Run these lines inside the failing job, as the same user and with the same environment. The first prints who kubectl will sign in as. The second shows how the cluster maps IAM to Kubernetes, and the third lists the principals it already knows.
aws sts get-caller-identity --query Arn --output text
aws eks describe-cluster --name my-cluster --query cluster.accessConfig
aws eks list-access-entries --cluster-name my-clusterThen find the line you see in this list and open its fix:
- 1The IAM role that runs kubectl has no access entry
authenticationMode is API or API_AND_CONFIG_MAP, and the role named in the get-caller-identity output is absent from list-access-entries - 2kubectl authenticates as some other principal, not the granted role
get-caller-identity prints an ARN you did not expect, such as the EC2 instance role instead of the deploy role, or a user from another account - 3The cluster only reads the aws-auth ConfigMap, and the role is not in it
describe-cluster shows authenticationMode CONFIG_MAP, and create-access-entry is refused for the cluster - 4The IAM role was deleted and created again under the same name
The role ARN is listed in list-access-entries, yet the job still gets 401 after someone rebuilt the role (for example by redeploying an IaC stack)
What does the error look like?
error validating data: failed to download openapi: the server has asked for the client to provide credentials; if you choose to ignore these errors, turn validation off with --validate=falseerror: You must be logged in to the server (the server has asked for the client to provide credentials)error: You must be logged in to the server (Unauthorized)
Cause 1 of 4
The IAM role that runs kubectl has no access entry
You seeauthenticationMode is API or API_AND_CONFIG_MAP, and the role named in the get-caller-identity output is absent from list-access-entries
Check
kubectl reports the server has asked for the client to provide credentials because the cluster cannot turn the calling IAM role into a Kubernetes identity. AWS's troubleshooting page names a missing access entry, or one without groups or an access policy, as the reason. CI roles are the usual gap: the person who built the cluster has access, the Jenkins role does not.
aws eks list-access-entries --cluster-name my-cluster --output text | grep my-jenkins-roleFix
Create an access entry for the role, written in the form arn:aws:iam::<account>:role/<name>, then attach an access policy to it. Pick the smallest policy that covers your deploys, and use namespace scope when the pipeline only touches a few namespaces.
aws eks create-access-entry --cluster-name my-cluster \
--principal-arn arn:aws:iam::111122223333:role/my-jenkins-role --type STANDARD
aws eks associate-access-policy --cluster-name my-cluster \
--principal-arn arn:aws:iam::111122223333:role/my-jenkins-role \
--access-scope type=cluster \
--policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSEditPolicyVerify
The role now shows in the access entry list, and a read call from the job returns objects instead of a 401.
kubectl get svcConfirmed by docs.aws.amazon.com
Cause 2 of 4
kubectl authenticates as some other principal, not the granted role
You seeget-caller-identity prints an ARN you did not expect, such as the EC2 instance role instead of the deploy role, or a user from another account
Check
The kubeconfig that aws eks update-kubeconfig writes calls aws eks get-token, and that command uses the default AWS credential chain unless a role is named. A kubeconfig copied from a laptop, or a job missing its AWS_PROFILE, ends up sending a principal the cluster has never seen.
grep -A12 'exec:' ~/.kube/configFix
Write the kubeconfig inside the job itself and name the role that has cluster access with --role-arn. Every token kubectl asks for is then issued for that role, whatever credentials the agent machine starts with.
aws eks update-kubeconfig --region us-east-1 --name my-cluster --role-arn arn:aws:iam::111122223333:role/my-deploy-roleVerify
The exec block in the kubeconfig now lists the role ARN, and kubectl apply gets past validation with no openapi download error.
kubectl apply -f deploy.yamlConfirmed by docs.aws.amazon.com
Cause 3 of 4
The cluster only reads the aws-auth ConfigMap, and the role is not in it
You seedescribe-cluster shows authenticationMode CONFIG_MAP, and create-access-entry is refused for the cluster
Check
Older clusters authenticate only through the aws-auth ConfigMap. AWS's troubleshooting guide says that in this mode a principal without an entry there, or with an entry that maps to no bound group, gets the same unauthorized reply.
eksctl get iamidentitymapping --cluster my-clusterFix
Switch the cluster to API_AND_CONFIG_MAP so access entries work while the existing ConfigMap keeps working. Wait for the cluster to return to Active, then add the access entry from the first cause. AWS notes the change cannot be undone back to a mode without the API.
aws eks update-cluster-config --name my-cluster --access-config authenticationMode=API_AND_CONFIG_MAPVerify
describe-cluster now reports API_AND_CONFIG_MAP and create-access-entry succeeds.
aws eks describe-cluster --name my-cluster --query cluster.accessConfig.authenticationModeConfirmed by docs.aws.amazon.com
Cause 4 of 4
The IAM role was deleted and created again under the same name
You seeThe role ARN is listed in list-access-entries, yet the job still gets 401 after someone rebuilt the role (for example by redeploying an IaC stack)
Check
EKS stores the hidden role ID with each access entry, not only the ARN. A recreated role has a new ID, which get-caller-identity shows as UserId, so the old entry no longer matches even though the ARN text is identical.
aws sts get-caller-identity --query UserId --output textFix
Remove the stale entry and add it back so EKS records the new role ID. Then repeat the associate-access-policy step from the first cause.
aws eks delete-access-entry --cluster-name my-cluster \
--principal-arn arn:aws:iam::111122223333:role/my-jenkins-role
aws eks create-access-entry --cluster-name my-cluster \
--principal-arn arn:aws:iam::111122223333:role/my-jenkins-role --type STANDARDVerify
Once the access policy is associated again, the pipeline's kubectl call goes through.
kubectl get svcConfirmed by docs.aws.amazon.com
How do I stop it coming back?
- Create the CI role's access entry in the same Terraform or CloudFormation stack as the role, so a rebuilt role always gets a fresh entry.
- Start every deploy job with aws sts get-caller-identity in the log, so a wrong identity is visible before kubectl runs.
- Generate the kubeconfig inside the job with --role-arn instead of storing a copied kubeconfig as a Jenkins secret.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro, Raheeb, Loade Driver.