Created
October 9, 2019 13:23
-
-
Save CermakM/ad343a1dece01757e6a8719b9a956cce to your computer and use it in GitHub Desktop.
Fish script to lookup kubernetes subjects based on RBAC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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