Skip to content

K8S user impersonation #2355

Closed
Closed

Description

@Dimpison

Describe the bug
This k8s client doesn't allow impersonating another user/SA in a cluster. kubectl binary allows doing this via --as flag or adding the following entity to kubeconfig: users.user.as. Even adding the entity to kubeconfig,

Client Version
1.1.0

Server Version
1.30.10

To Reproduce
Steps to reproduce the behavior:
Run the following code.

import * as k8s from "@kubernetes/client-node";
const kubeconfigPath = "/path/to/kube/config;
const kubeConfig = new k8s.KubeConfig();
kubeConfig.loadFromFile(kubeconfigPath);
console.log(kubeConfig.getCurrentUser());

The above code snippet doesn't show the users.user.as field even if it's added to the kubeconfig. As well as the client ignores the field when making a request to K8S API.

Kubeconfig snippet example:

- name: sudo user
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - eks
      - get-token
      - --cluster-name=cluste-name
      command: aws
    as: sudo-user

Expected behavior
It's expected that as field is available and can be used to impersonate user in k8s cluster.

Example Code

import * as k8s from "@kubernetes/client-node";
const kubeconfigPath = "/path/to/kube/config;
const kubeConfig = new k8s.KubeConfig();
kubeConfig.loadFromFile(kubeconfigPath);
console.log(kubeConfig.getCurrentUser());

Environment (please complete the following information):

  • OS: [e.g. Windows, Linux]: MacOS
  • Node.js version [eg. 20] - 20
  • Cloud runtime [e.g. Azure Functions, Lambda] - local run

Additional context
Link to k8s doc https://kubernetes.io/docs/reference/access-authn-authz/authentication/#user-impersonation
Link to kubeconfig api reference https://kubernetes.io/docs/reference/config-api/kubeconfig.v1/#AuthInfo

Activity

  1. Soubi8 commented on Apr 4, 2025

    @Soubi8

    This is really important and has to be addressed

  2. brendandburns commented on Apr 4, 2025

    @brendandburns
    Contributor

    Happy to review PRs if you want to add this.

  3. added a commit that references this issue on Apr 15, 2025
  4. cjihrig commented on Apr 15, 2025

    @cjihrig
    Contributor

    @Dimpison can you give the changes in #2373 a try.

  5. Dimpison commented on Apr 19, 2025

    @Dimpison
    Author

    The issue and PR are being discussed in more detail in the PR (for visibility).

  6. added a commit that references this issue on Apr 19, 2025
  7. cjihrig commented on Apr 25, 2025

    @cjihrig
    Contributor

    Closed by #2373

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions