Welcome to the Linux Foundation Forum!

How to determine which username and group I have in a cluster using kubectl

Authentication section of k8s documentation is talking about:

When enabled, requests that are not rejected by other configured authentication methods are treated as anonymous requests, and given a username of system:anonymous and a group of system:unauthenticated.

since there are different ways to identify myself when interacting with the API, it's not always clear how it recognised me - I mean as which username and which group it thinks I belong to. Is there any way to see that via kubectl?

Comments

  • serewicz
    serewicz Posts: 942

    Hello,

    I would guess you'd have to turn on auditing to know, even then its probably not easy to get to. If you use webhooks to an outside service you could at least see the traffic, or using gatekeeper/OPA and you could see the details from the other side.
    But kube-apiserver keeps checking until you are allowed in or it runs out of places to check. And it doesn't tell you much on what allowed you in. Other than Auditing I don't think so. Every API call is unique, so there isnt a "session" to look at.

    Regards,

  • Thank you @serewicz. Yes, I understand that there is no session as such, but when I have started to use kubectl from one machine, provided that the environment in which it is running remains stable, I will be consistently recognised as the same user having the same groups. Just wanted to understand how a troubleshooting workflow would look like if I'm expecting that I'm user X with one set of groups, but in fact I'm being recognised as user Y with another set of groups. Due to the fact that user identity can be taken from many different places, user may expect that it's taken from, say, config file, but there is an environment variable that he is not aware of which instructs kubectl to use some other identity.

    Checked your suggestion with auditing and indeed, this information is shown. So it provides some way of doing this.

  • serewicz
    serewicz Posts: 942

    Hello,

    I may not understand, when you log in from two different machines you are seeing different group membership? As in the output of the Linux id command shows different values?

    If you mean your RBAC roles, or context settings are different than there may have been a context different in each terminal session. If you run grep current-context $HOME/.kube/config in both sessions is the value the same?

    Also is the output of kubectl config get-contexts the same?

    Regards,

Categories

Upcoming Training