#!/usr/bin/env bash # Certificates for the example's two nodes, into DIR (README.md): # # examples/cluster/make-certs.sh DIR # # - ca.pem / ca.key: the cluster's authority; # - a.pem / a.key: node a.cluster.example; # - b.pem / b.key: node b.cluster.example. # A node is both a TLS server and a TLS client (mutual TLS), so each # certificate is for both, and names its node in its subjectAltName: the # name the other nodes check. FOR TRYING THE EXAMPLE ONLY: a real cluster's # keys come from its own authority, and stay secret. set -euo pipefail dir=${1:?usage: make-certs.sh DIR} mkdir -p "$dir" cd "$dir" key() { openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "$1" 2>/dev/null; } key ca.key openssl req -x509 -new -key ca.key -subj "/CN=cluster example CA" -days 30 -out ca.pem \ -addext "basicConstraints=critical,CA:TRUE" \ -addext "keyUsage=critical,keyCertSign,cRLSign" for n in a b; do key "$n.key" openssl req -new -key "$n.key" -subj "/CN=$n.cluster.example" -out "$n.csr" cat > "$n.ext" </dev/null rm -f "$n.csr" "$n.ext" done rm -f ca.srl chmod 600 ./*.key echo "certificates for a.cluster.example and b.cluster.example in $PWD"