Created
March 26, 2025 05:12
-
-
Save shivanshs9/fc49b5e73861a6482bd6c347b4fdfd5b to your computer and use it in GitHub Desktop.
Search all k8s secrets in a given namespace (both key/value)
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
function k8s_search_secret | |
if test (count $argv) -lt 2 | |
echo "Usage: k8s_search_secret <namespace> <search_term>" | |
return 1 | |
end | |
set NAMESPACE $argv[1] | |
set SEARCH_TERM $argv[2] | |
# Get all secrets in the namespace and decode them | |
kubectl get secrets -n $NAMESPACE -o json | jq -r ' | |
[.items[] | | |
{"name": .metadata.name, "data": .data} | | |
select(.data != null) | | |
.name as $secret_name | | |
.data | to_entries[] | | |
{"secret": $secret_name, "key": .key, "value": (try (.value | @base64d) catch "INVALID_UTF8")}] | |
| .[] | select((.key | test($search; "i")) or (.value | test($search; "i"))) | |
' --arg search "$SEARCH_TERM" | yq -o csv | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment