Last active
September 16, 2019 09:18
-
-
Save sallyom/370ca9fcd152cffde4e46a6268ed7b99 to your computer and use it in GitHub Desktop.
append router-ca to kubeconfig
This file contains 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
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
#################################################################################### | |
# This is no longer required, only the idp.sh is required to configure htpasswd idp | |
# HOWEVER, if your install fails and cluster is functional enough to configure | |
# idp and/or login with kubeadmin, you'll need to run this to avoid x509 error | |
#################################################################################### | |
# get encoded data | |
oc get secret router-ca -n openshift-ingress-operator -o yaml | grep tls.crt | awk -F ': ' '{print $2}' > /tmp/router-ca.enc | |
cat "$KUBECONFIG" | grep certificate-authority-data | head -1 | awk -F ': ' '{print $2}' > /tmp/cluster-ca.enc | |
# decode data | |
base64 --decode /tmp/router-ca.enc > /tmp/router-ca.decoded | |
base64 --decode /tmp/cluster-ca.enc > /tmp/cluster-ca.decoded | |
# append router-ca to cluster-ca | |
cat /tmp/router-ca.decoded /tmp/cluster-ca.decoded > /tmp/bundle.decoded | |
#encode new bundle | |
base64 -w 0 /tmp/bundle.decoded > /tmp/bundle.encoded | |
#replace certificate-authority-data in kubeconfig with new encoded bundle | |
export BUNDLE=$(cat /tmp/bundle.encoded) | |
sed -i.bak "s|certificate-authority-data.*|certificate-authority-data: $BUNDLE|g" "$KUBECONFIG" | |
Here is another way to add the CA cert, using only oc
and one base64 -d
oc -n openshift-ingress-operator extract secret/router-ca --to=. --keys=tls.crt
oc config view --minify -o go-template='{{index .clusters 0 "cluster" "certificate-authority-data" }}' --raw=true | base64 -d > current-ca.crt
cat tls.crt >> current-ca.crt
for cluster in $( oc config get-clusters | grep -v NAME ) ; do
oc config set-cluster "$cluster" --certificate-authority=current-ca.crt --embed-certs=true
done
@richm awesome, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool Thanks 👍