Created
January 21, 2021 15:37
-
-
Save patrixgdd/f5942e856b958f6c6d38e25d34b5a645 to your computer and use it in GitHub Desktop.
Extract let's encrypt certificates from kubernetes and upload them to aws iam
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/sh | |
if [ $# -lt 3 ]; | |
then | |
echo "usage: $0 <dns_name> <app_name> <environment>"; | |
exit 1; | |
fi | |
DNS=$1 | |
APP_NAME=$2 | |
ENVIRONMENT=$3 | |
kubectl get secrets -o yaml ${DNS} --namespace=${APP_NAME}-${ENVIRONMENT} | grep -E 'tls.(crt|key)' | while read line; | |
do | |
OUT=$(echo $line | awk -F:\ '{print$1}') | |
echo $line | awk -F:\ '{print$NF}' | base64 -D -i - > ${DNS}-$OUT | |
done | |
CHECK=$(aws iam list-server-certificates | grep -c "\"ServerCertificateName\": \"${DNS}\"") | |
[ ${CHECK} -gt 0 ] && { echo "deleting existing cert for ${DNS}"; aws iam delete-server-certificate --server-certificate-name ${DNS}; } | |
aws iam upload-server-certificate --server-certificate-name ${DNS} --certificate-body file://./${DNS}-tls.crt --private-key file://./${DNS}-tls.key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment