Skip to content

Instantly share code, notes, and snippets.

@bastjan
Last active September 7, 2021 07:46
Show Gist options
  • Save bastjan/d4e81d9112093caaf60338f86ab54e2a to your computer and use it in GitHub Desktop.
Save bastjan/d4e81d9112093caaf60338f86ab54e2a to your computer and use it in GitHub Desktop.
Find clusterroles with permissions to create/edit namespaces
#!/bin/bash
set -euo pipefail
kubectl --as=cluster-admin get clusterrole -ojson | jq '[ .items[]
| select(
.rules[]?
| select(
(.apiGroups[]? == "" or .apiGroups[]? == "*")
and
(.resources[]? == "namespaces" or .resources[]? == "*")
and
(.verbs[]? == "create" or .verbs[]? == "update" or .verbs[]? == "patch" or .verbs[]? == "*")
)
> 0
)
| .metadata.name
] | unique'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment