There is a way to create a service account and get token as in How to Add Users to Kubernetes (kubectl)? but is there a way to get or create a token for a normal user?
Followed Configure RBAC In Your Kubernetes Cluster and created a normal user.
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.
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"
kubectl create serviceaccount ACCOUNT_NAME
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).So you can create a serviceaccount and then use that token to authenticate the requests to the API.
Something similar to this example
$ kubectl create serviceaccount jenkins
serviceaccount "jenkins" created
$ kubectl get serviceaccounts jenkins -o yaml
apiVersion: v1
kind: ServiceAccount
metadata:
# ...
secrets:
- name: jenkins-token-1yvwg
And then fetch the token
$ 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