Last active
September 3, 2019 07:35
-
-
Save linosteenkamp/1da2217ee544bb213f36d5b3a169b43c to your computer and use it in GitHub Desktop.
Extract certificates from kubectl config
This file contains 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 | |
CKD_KEY="client-key-data" | |
CCD_KEY="client-certificate-data" | |
CAD_KEY="certificate-authority-data" | |
json=$(kubectl config view --raw -o json) | |
#- Retrieve Certificates and Keys for all contexts | |
echo "$json" | jq -c '.contexts[].context' | while read line | |
do | |
user=$(echo "$line" | jq '.user') | |
cluster=$(echo "$line" | jq '.cluster') | |
fname=$(echo "$cluster" | sed -e 's/\"//g') | |
echo "$json" | jq ".users[] | select(.name == $user) | .user.\"$CKD_KEY\"" | sed -e 's/\"//g' | base64 -D > "$fname-$CKD_KEY.key" | |
echo "$json" | jq ".users[] | select(.name == $user) | .user.\"$CCD_KEY\"" | sed -e 's/\"//g' | base64 -D > "$fname-$CCD_KEY.pem" | |
echo "$json" | jq ".clusters[] | select(.name == $cluster) | .cluster.\"$CAD_KEY\"" | sed -e 's/\"//g' | base64 -D > "$fname-$CAD_KEY.pem" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment