Skip to content

Instantly share code, notes, and snippets.

@dlbewley
Last active September 29, 2023 23:17
Show Gist options
  • Save dlbewley/639bc786e3eb595362bf807225570abf to your computer and use it in GitHub Desktop.
Save dlbewley/639bc786e3eb595362bf807225570abf to your computer and use it in GitHub Desktop.
Extract OpenShift CA Certificates from Install Generated Kubeconfig

After installing OpenShift you'll find a number of certificate authorities which are used to issue ingress, api certs. Even in a test environment you will want to configure your clients to trust them. This script will extract certs from the kubeconfig into files containing a single cert so you can more easily do so.

#!/bin/sh
cat $KUBECONFIG \
| yq e '.clusters[0].cluster."certificate-authority-data"' \
| base64 -d > kubeconfig-ca-data.pem
split -p "-----BEGIN CERTIFICATE-----" kubeconfig-ca-data.pem cert-
for c in cert-??; do
subject=`openssl x509 -in $c -noout -subject | sed 's/^.*CN[[:space:]]*=[[:space:]]*\(.*\)/\1/'`
echo $subject
mv $c "${subject}.pem"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment