#!/usr/bin/env bash # Makes a private certificate authority and a server certificate signed by it, # in ./certs next to this script: # # certs/ca.crt give this to clients (sslrootcert=certs/ca.crt) # certs/ca.key keep it private; it signs new server certificates # certs/server.crt the server's certificate (--pg-cert, --rdb-cert) # certs/server.key the server's private key (--pg-key, --rdb-key) # # usage: ./make-certs.sh [extra host name or IP ...] # The certificate always names localhost, 127.0.0.1 and rasterizeddb (the # Compose service name). Add the names clients use to reach the server: # ./make-certs.sh db.example.com 10.0.0.5 # # Needs openssl. Refuses to overwrite an existing certs/ directory. set -euo pipefail cd "$(dirname "$0")" DIR=certs DAYS="${DAYS:-825}" if [ -e "$DIR" ]; then echo "$DIR/ already exists; move it away to make new certificates." >&2 exit 1 fi command -v openssl >/dev/null || { echo "openssl is not installed." >&2; exit 1; } san="DNS:localhost,IP:127.0.0.1,DNS:rasterizeddb" for name in "$@"; do if [[ "$name" =~ ^[0-9.]+$ || "$name" == *:* ]]; then san="$san,IP:$name" else san="$san,DNS:$name" fi done mkdir -m 700 "$DIR" umask 077 # Own configuration files, so the result does not depend on the system's # openssl.cnf. cat > "$DIR/ca.cnf" <<'EOF' [req] prompt = no distinguished_name = dn x509_extensions = v3_ca [dn] CN = RasterizedDB local CA [v3_ca] basicConstraints = critical, CA:TRUE keyUsage = critical, keyCertSign, cRLSign subjectKeyIdentifier = hash EOF cat > "$DIR/server.cnf" <<'EOF' [req] prompt = no distinguished_name = dn [dn] CN = rasterizeddb EOF cat > "$DIR/server.ext" <