2

I am having trouble trying to understand the Kubernetes authentication model, specially what "users" are.

Suppose I am on a computer, which is inside a kubernetes cluster. I want to do a request to the API server, using kubectl.

So: - I need to have the public key from the api-server HTTPS port. So let's assume that is provided to me. - Then, in my requeste, there's a need for me to populate the "user" field?

As per this part of the documentation, the user field is a method: https://kubernetes.io/docs/admin/authentication/#authentication-strategies

But then here https://kubernetes.io/docs/admin/accessing-the-api/#authorization we read that actually kubernetes has no concept of a user.

So:

  • What/where do I even put in the user field?
  • If, since I control the client request content, couldn't I simply enter any username there? Couldn't I just try guess any username repeatedly until I find one with the authorisation for what I want?

Thanks.

testTester
  • 2,371
  • 3
  • 18
  • 22

2 Answers2

3

The user to be used depends on the kubeconfig for you to use (e.g. ~/.kube/config) and the current context. For example if your ~/.kube/config is below, kubernetes-admin is the user.

apiVersion: v1
kind: Config
current-context: kubernetes-admin@kubernetes
preferences: {}

contexts:
  - context:       <---- Current context to identify which cluster, user, and namespace (*) to use.
      cluster: kubernetes
      user: kubernetes-admin   <----- user for the context
    name: kubernetes-admin@kubernetes

clusters:
  - cluster:
      certificate-authority-data: REDACTED
      server: https://172.31.4.117:6443 
    name: kubernetes

users:
  - name: kubernetes-admin <----
    user:
      client-certificate-data: REDACTED
      client-key-data: REDACTED

You can add users. Please refer to Use Case 1: Create User With Limited Namespace Access in Configure RBAC In Your Kubernetes Cluster. This "User" is not "service account".


References

mon
  • 18,789
  • 22
  • 112
  • 205
1

we read that actually kubernetes has no concept of a user.

Not quite... β€œit does not have a user object nor does it store usernames or other information about users in its object store.”

For example, if you provided a client certificate, kubernetes would verify the signature on the certificate, then extract your identity from the certificate subject.

If you provided an OpenID Connect bearer token, kubernetes would verify the signature on the token and extract your username and group membership from the signed token.

There are other methods the kubernetes server can use to verify your credentials (webhook call outs, passing your request through an authenticating proxy, etc)

What/where do I even put in the user field?

In the kubeconfig file used by kubectl, it stores information about the server that will be contacted, and the user credentials to provide. You have the ability to provide a client x509 certificate, or a bearer token, or a basic auth username/password. Which one you choose depends on the authentication method configured in your server.

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#define-clusters-users-and-contexts gives a good walk through of setting up a kubeconfig file. You get to define user stanzas with a name you choose (just to reference it by locally) and credentials to send to the server. The name you choose locally has no bearing on the server, it only pays attention to the credentials you specify.

Jordan Liggitt
  • 16,933
  • 2
  • 56
  • 44
  • Thank you. I've read the step-by-step in the link above and compared with the one that I have my own, seems to make sense. But I still have one question, the tutorial create this file, with the users and contexts, all in the same node. I am not sure how this would happen using multiple computers. Eg: suppose we had 2 machines, the one of the administrator creating the rules, and the other one of a new user we just want start giving access to the node. How could I, as admin, add this user to the master, and then what should the user in his local environment do to set up his config file? – testTester Mar 03 '18 at 02:13