Skip to content

Instantly share code, notes, and snippets.

@daxmc99
Created November 8, 2024 03:55
Show Gist options
  • Save daxmc99/e1504a9e7f386273cdf3e29d7ac602b0 to your computer and use it in GitHub Desktop.
Save daxmc99/e1504a9e7f386273cdf3e29d7ac602b0 to your computer and use it in GitHub Desktop.
one liner to list all roles & clusterroles that have secret access
kubectl get roles,clusterroles -o json | jq -c '
.items[]
| select(.rules != null) # Exclude entries with null rules
| select(.rules[].resources[] == "secrets") # Only resources with "secrets" access
| {name: .metadata.name, kind: .kind, namespace: .metadata.namespace, verbs: (.rules[].verbs | unique)}' \
| jq -s 'unique_by(.name, .kind, .namespace)' # Deduplicate based on name, kind, and namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment