16

Is there a way with kubectl to find out which clusterroles or roles are bound to the service account?

karthikeayan
  • 4,291
  • 7
  • 37
  • 75

1 Answers1

31

You could do something like:

kubectl get rolebindings,clusterrolebindings \
  --all-namespaces  \
  -o custom-columns='KIND:kind,NAMESPACE:metadata.namespace,NAME:metadata.name,SERVICE_ACCOUNTS:subjects[?(@.kind=="ServiceAccount")].name' | grep "<SERVICE_ACCOUNT_NAME>"

Replace the grep with then name of the service account you are looking for.

Esteban Garcia
  • 2,171
  • 16
  • 24