Skip to content

Instantly share code, notes, and snippets.

@incfly
Created June 3, 2019 22:41
Show Gist options
  • Save incfly/5439e156867fa634197a72a3180fb91e to your computer and use it in GitHub Desktop.
Save incfly/5439e156867fa634197a72a3180fb91e to your computer and use it in GitHub Desktop.
Check Istio Root Certificate Valiness.
#!/bin/bash
rootcert() {
echo "Fetching root cert from istio-system namespace..."
kubectl get secret -n istio-system istio-ca-secret -o yaml | awk '/ca-cert/ {print $2}' | base64 --decode > ca.cert
if [[ ! -f ./ca.cert ]]; then
echo "failed to get cacert, check the istio installation namespace."
return
fi
rootDate=$(openssl x509 -in ca.cert -noout -enddate | cut -f2 -d'=')
rootSec=$(date -d "${rootDate}" '+%s')
nowSec=`date '+%s'`
remainDays=$(echo "(${rootSec} - ${nowSec}) / (3600 * 24)" | bc)
cat << EOF
Your Root Cert will expire after
${rootDate}
Current time is
$(date)
===YOU HAVE ${remainDays} DAYS BEFORE THE ROOT CERT EXPIRED!=====
EOF
}
rootcert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment