<h1>Question</h1>

<p>There is a way to create a service account and get token as in <a href="https://stackoverflow.com/questions/42170380/how-to-add-users-to-kubernetes-kubectl">How to Add Users to Kubernetes (kubectl)?</a> but is there a way to get or create a token for a normal user?</p>

<h1>Background</h1>

<p>Followed <a href="https://docs.bitnami.com/kubernetes/how-to/configure-rbac-in-your-kubernetes-cluster/" rel="noreferrer">Configure RBAC In Your Kubernetes Cluster</a> and created a normal user.</p>

<p>Bind a cluster role to the user as below (not sure this is correct, appreciate suggestions). I would like to create a token for the user and use it to access the dashboard but do not know how to do.</p>

<pre><code>kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: kube-system
  name: dashboard-admin-role
rules:
- apiGroups: ["*"]
  resources: ["*"]
  verbs: ["get", "list", "watch"]

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: dashboard-admin-rolebinding
  namespace: office
subjects:
- kind: User
  name: myuser
  apiGroup: "rbac.authorization.k8s.io"
roleRef:
  kind: ClusterRole
  name: dashboard-admin-role
  apiGroup: "rbac.authorization.k8s.io"
</code></pre>

<p><a href="https://kubernetes.io/docs/admin/authentication/#service-account-tokens" rel="noreferrer">API requests are tied to either a normal user or a service account, or are treated as anonymous requests</a>.</p>

<ul>
<li>Normal users are assumed to be managed by an outside, independent service (private keys, third parties like Google Accounts, even a file with a list of usernames and passwords). Kubernetes does not have objects which represent normal user accounts.</li>
<li>Service accounts are users managed by the Kubernetes API, bound to specific namespaces. Service accounts are tied to a set of credentials stored as Secrets. Service account bearer tokens are perfectly valid to use outside the cluster and can be used to create identities for long standing jobs that wish to talk to the Kubernetes API. To manually create a service account, simply use the <code>kubectl create serviceaccount ACCOUNT_NAME</code> command. This creates a service account in the current namespace and an associated secret that holds the public CA of the API server and a signed JSON Web Token (JWT).</li>
</ul>

<p>So you can create a serviceaccount and then <a href="https://kubernetes.io/docs/admin/authentication/#putting-a-bearer-token-in-a-request" rel="noreferrer">use that token to authenticate the requests to the API</a>.</p>

<p>Something similar to this example</p>

<pre><code>$ kubectl create serviceaccount jenkins
serviceaccount "jenkins" created
$ kubectl get serviceaccounts jenkins -o yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  # ...
secrets:
- name: jenkins-token-1yvwg
</code></pre>

<p>And then fetch the token</p>

<pre><code>$ kubectl get secret jenkins-token-1yvwg -o yaml
apiVersion: v1
data:
  ca.crt: (APISERVER'S CA BASE64 ENCODED)
  namespace: ZGVmYXVsdA==
  token: (BEARER TOKEN BASE64 ENCODED)
kind: Secret
metadata:
  # ...
type: kubernetes.io/service-account-token
</code></pre>
