Skip to content

Instantly share code, notes, and snippets.

@mrsimonemms
Last active December 8, 2024 12:19
Show Gist options
  • Save mrsimonemms/9286989ff14a35d890d1386581e058f3 to your computer and use it in GitHub Desktop.
Save mrsimonemms/9286989ff14a35d890d1386581e058f3 to your computer and use it in GitHub Desktop.
Extract TLS secrets from Kubernetes
#!/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