Kubectl command to return a list of all user accounts from Kubernetes

11/11/2021

I am looking to output a comma separated list of all user accounts from Kubernetes.

I understand that one can return a list of namespaces, pods, and so on from Kubernetes using the 'kubectl get namespace' and 'kubectl get pods' command. However, is there an equivalent for returning a list of Kubernetes users?

Currently, I can see a list of all of the user account and their respective names, emails, and IDs from within Kubernetes via our management platform Rancher but, the problem is, I can't seem to find a way to return a comma-separated list of these users via the command line through Kubectl or Powershell.

-- Kerbol
kubectl
kubernetes
rancher

1 Answer

11/11/2021

This really depends on your k8s setup and rbac modal.

I would suggest that you look at the objects talked about here https://kubernetes.io/docs/reference/access-authn-authz/rbac/

In the end, the commands you probably want are.

kubectl get clusterroles.rbac.authorization.k8s.io --all-namespaces
kubectl get roles.rbac.authorization.k8s.io --all-namespaces
-- Josh Beauregard
Source: StackOverflow