Skip to content

fix: generate valid EKS authentication token payload#4779

Open
hwayoungjun wants to merge 1 commit into
kubernetes-client:masterfrom
hwayoungjun:fix/eks-authentication-401
Open

fix: generate valid EKS authentication token payload#4779
hwayoungjun wants to merge 1 commit into
kubernetes-client:masterfrom
hwayoungjun:fix/eks-authentication-401

Conversation

@hwayoungjun
Copy link
Copy Markdown

Description

EKSAuthentication currently URL-encodes the entire presigned STS GetCallerIdentity URL before building the k8s-aws-v1. bearer token.

However, the presigned URL returned by the AWS signer already contains encoded query parameters. Encoding the entire URL again makes the decoded token payload an encoded URL string, rather than the presigned STS URL form used by aws-iam-authenticator and shown in the EKS docs.

For example, the decoded token payload form is:

https://sts.ap-northeast-2.amazonaws.com/?Version=2011-06-15&Action=GetCallerIdentity&X-Amz-Credential=...%2F...

With the extra full-URL encoding step, the decoded payload instead becomes an encoded URL string:

https%3A//sts.ap-northeast-2.amazonaws.com%3FVersion%3D2011-06-15%26Action%3DGetCallerIdentity%26X-Amz-Credential%3D...%252F...

I observed this causing EKS API requests using EKSAuthentication to fail with 401 Unauthorized.

This change builds the EKS bearer token from the presigned STS URL directly. It also sets the STS request path explicitly to /, matching the working presigned URL form verified against EKS:

https://sts...amazonaws.com/?...

Changes

  • Stop URL-encoding the entire presigned STS URL before base64url-encoding it
  • Set the STS request path explicitly to /

References

Validation

I verified this manually against a real EKS cluster by using EKSAuthentication to generate the bearer token and calling CoreV1Api.listNamespace().

The previous token payload failed with 401 Unauthorized, while the updated payload succeeded in listing namespaces.

Build the EKS bearer token from the presigned STS GetCallerIdentity URL
directly instead of URL-encoding the whole presigned URL first. The AWS
signer already returns a URL with encoded query parameters, and encoding
the entire URL again makes the decoded token payload an encoded URL string
rather than the presigned STS URL expected by EKS.

Set the STS request path explicitly to "/" so the generated presigned URL
matches the accepted EKS token payload shape.

This fixes EKSAuthentication requests failing with 401 Unauthorized.
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hwayoungjun
Once this PR has been reviewed and has the lgtm label, please assign brendandburns for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants