Intro

Basic Authentication

When implementing basic authentication using a file containing usernames and passwords or token, we need to pass the basic-auth-file or token-auth-file to the kube-apiserver and restart it.

Untitled

If the kube-apiserver is running as a service, update the service config and restart it. On the other hand, if the kube-apiserver is deployed as a pod through KubeAdmin, update the pod definition file which will automatically recreate the new pod.

Untitled

The user can then authenticate to the kube-apiserver in the curl command as shown below.

Untitled

In case of static token file, the authentication in the curl command happens as a bearer token.

Untitled

We need to use volume mounting to store the password file in a location on the host and pass it to the kube-apiserver pod (in case of KubeAdmin setup)

apiVersion: v1
kind: Pod
metadata:
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
      - --authorization-mode=Node,RBAC
      <content-hidden>
    - --basic-auth-file=/tmp/users/user-details.csv
    image: k8s.gcr.io/kube-apiserver-amd64:v1.11.3
    name: kube-apiserver
    volumeMounts:
    - mountPath: /tmp/users
      name: usr-details
      readOnly: true
  volumes:
  - hostPath:
      path: /tmp/users
      type: DirectoryOrCreate
    name: usr-details

<aside> ⛔ Managing user identities using a plaintext file is not the recommended way.

</aside>