Skip to content

Instantly share code, notes, and snippets.

@CermakM
Created October 9, 2019 13:23
Show Gist options
  • Save CermakM/ad343a1dece01757e6a8719b9a956cce to your computer and use it in GitHub Desktop.
Save CermakM/ad343a1dece01757e6a8719b9a956cce to your computer and use it in GitHub Desktop.
Fish script to lookup kubernetes subjects based on RBAC
# Lookup kubernetes subjects based on RBAC
# Usage:
# rbac-lookup # to list all subjects to a rolebinding or clusterrolebinding
# rbac-lookup builder # list all {role,clusterrole}bindings where builder is a subject
function rbac-lookup
if test "$argv"
kubectl get rolebindings,clusterrolebindings \
--all-namespaces \
-o custom-columns=(string join0 'KIND:kind,NAMESPACE:metadata.namespace,NAME:metadata.name,SUBJECT:subjects[?(@.name=="'"$argv"'")].name') | grep -v '<none>'
else
kubectl get rolebindings,clusterrolebindings \
--all-namespaces \
-o custom-columns='KIND:kind,NAMESPACE:metadata.namespace,NAME:metadata.name,SUBJECT:subjects[].name'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment