Last active
December 8, 2024 12:19
-
-
Save mrsimonemms/9286989ff14a35d890d1386581e058f3 to your computer and use it in GitHub Desktop.
Extract TLS secrets from Kubernetes
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
#!/bin/bash | |
### | |
# Run curl -fsSL https://gist.githubusercontent.com/mrsimonemms/9286989ff14a35d890d1386581e058f3/raw/f59d1613062154c6ad6fca81a7a12d30291da6d3/secrets.json | bash | |
### | |
set -e | |
SAVE_TO="${SAVE_TO:-./tmp/secrets}" | |
mkdir -p "${SAVE_TO}" | |
secrets=$(kubectl get secrets --all-namespaces -o json | jq -r '.items[] | select(.type == "kubernetes.io/tls") | . | @base64 ') | |
for i in $secrets; do | |
filename="$(echo ${i} | base64 -d | jq -r '"\(.metadata.name).\(.metadata.namespace).json"')" | |
filepath="${SAVE_TO}/${filename}" | |
echo ${i} | base64 -d | jq -r 'del(.metadata.uid) | del(.metadata.resourceVersion) | del(.metadata.creationTimestamp)' > "${filepath}" | |
echo "Saved ${filepath}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment