Last active
December 18, 2017 20:27
-
-
Save Stono/fe83ea90e912f878bf5e49cdd403cbbc to your computer and use it in GitHub Desktop.
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 | |
set -e | |
function get_secret { | |
VAR=".data[\"$1\"]" | |
kubectl -n istio-system get secret istio-ca-secret -o json | jq -r $VAR | base64 --decode | |
} | |
function clean { | |
# Cleanup database | |
rm -f ca/index.txt* | |
rm -f ca/serial.txt | |
# Cleanup old requests | |
rm -f client.csr | |
rm -f 01.pem | |
} | |
mkdir -p ./certs/ca | |
cd certs | |
clean | |
echo "Getting root certificates from istio..." | |
get_secret "ca-cert.pem" > ca/ca-cert.pem | |
get_secret "ca-key.pem" > ca/ca-key.pem | |
echo "Generating CSR..." | |
openssl req -new -newkey rsa:2048 -nodes -config openssl.cnf -subj "/" -outform pem -out client.csr -keyout client.key | |
echo "Signing CSR using CA key..." | |
touch ca/index.txt | |
echo '01' > ca/serial.txt | |
openssl ca -batch -config openssl-ca.cnf -policy signing_policy -out client.pem -infiles client.csr | |
clean | |
echo "Testing key works..." | |
echo "Looking up service ip..." | |
SERVICE_IP=$(kubectl get service -l app=at-consumer-platform | tail -n 1 | awk '{print $4}') | |
echo "Using ip: $SERVICE_IP" | |
docker run --rm -it -v $PWD:/etc/certs byrnedo/alpine-curl -kv https://$SERVICE_IP:80 --key /etc/certs/client.key --cert /etc/certs/client.pem --cacert /etc/certs/ca/ca-cert.pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is about creating a certificate signed by the istio service mesh ca.
My particular use case is that I have a poly cloud setup where we have some older devices (on prem) wanting to connect to the istio service mesh, but I can't run the istio agent on them. As such I wanted to generate some slightly longer lived certificates to use on those devices until such a time as they are properly integrated.
Make sure you do
mkdir certs
, and create these two config files in there first../certs/openssl.cnf =
./certs/openssl-ca.cnf =