Skip to content

Instantly share code, notes, and snippets.

@darox
Created August 22, 2022 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darox/1d49d2d7d59d9c5f1893ab16425e65b4 to your computer and use it in GitHub Desktop.
Save darox/1d49d2d7d59d9c5f1893ab16425e65b4 to your computer and use it in GitHub Desktop.
Kubernetes Certificate Expiry Check
#!/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