Created
August 22, 2022 13:28
-
-
Save darox/1d49d2d7d59d9c5f1893ab16425e65b4 to your computer and use it in GitHub Desktop.
Kubernetes Certificate Expiry Check
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 | |
users=() | |
certs=() | |
for user in $(kubectl config view --raw --output json | jq -r '.users[] | "\(.name)"'); do | |
users+=($user) | |
done | |
for cert in $(kubectl config view --raw --output json | jq -r '.users[] | "\(.user."client-certificate-data")"'); do | |
certs+=($cert) | |
done | |
x=0 | |
echo "" | |
while [ $x -lt ${#users[@]} ] | |
do | |
name=${users[x]} | |
date=$(echo ${certs[x]} | base64 -d | openssl x509 -text -out - | grep "Not After" | cut -d ":" -f2-) | |
echo "Certificate of $name will expire on $date" | |
x+=1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment