
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | #!/usr/bin/env bash |
| 2 | # Certificates for the example's two nodes, into DIR (README.md): |
| 3 | # |
| 4 | # examples/cluster/make-certs.sh DIR |
| 5 | # |
| 6 | # - ca.pem / ca.key: the cluster's authority; |
| 7 | # - a.pem / a.key: node a.cluster.example; |
| 8 | # - b.pem / b.key: node b.cluster.example. |
| 9 | # A node is both a TLS server and a TLS client (mutual TLS), so each |
| 10 | # certificate is for both, and names its node in its subjectAltName: the |
| 11 | # name the other nodes check. FOR TRYING THE EXAMPLE ONLY: a real cluster's |
| 12 | # keys come from its own authority, and stay secret. |
| 13 | set -euo pipefail |
| 14 | dir=${1:?usage: make-certs.sh DIR} |
| 15 | mkdir -p "$dir" |
| 16 | cd "$dir" |
| 17 | |
| 18 | key() { openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "$1" 2>/dev/null; } |
| 19 | |
| 20 | key ca.key |
| 21 | openssl req -x509 -new -key ca.key -subj "/CN=cluster example CA" -days 30 -out ca.pem \ |
| 22 | -addext "basicConstraints=critical,CA:TRUE" \ |
| 23 | -addext "keyUsage=critical,keyCertSign,cRLSign" |
| 24 | |
| 25 | for n in a b; do |
| 26 | key "$n.key" |
| 27 | openssl req -new -key "$n.key" -subj "/CN=$n.cluster.example" -out "$n.csr" |
| 28 | cat > "$n.ext" <<EXT |
| 29 | basicConstraints=critical,CA:FALSE |
| 30 | keyUsage=critical,digitalSignature,keyEncipherment |
| 31 | extendedKeyUsage=serverAuth,clientAuth |
| 32 | subjectAltName=DNS:$n.cluster.example |
| 33 | EXT |
| 34 | openssl x509 -req -in "$n.csr" -CA ca.pem -CAkey ca.key -CAcreateserial \ |
| 35 | -extfile "$n.ext" -days 30 -out "$n.pem" 2>/dev/null |
| 36 | rm -f "$n.csr" "$n.ext" |
| 37 | done |
| 38 | rm -f ca.srl |
| 39 | chmod 600 ./*.key |
| 40 | echo "certificates for a.cluster.example and b.cluster.example in $PWD" |