#!/usr/bin/env bash # Generates a private CA and a mutual-TLS cert/key pair for the Provisioner <-> rn-lab-host-01 # Docker Engine connection (docs/PRODUCTION_NETWORK_SECURITY.md ยง7). The application already # supports this (platform/provisioner/src/docker.js buildClient() has required mTLS since # Phase 1) โ€” this script only ever needed to exist for the CERTIFICATES, not new app code. # # Output goes to $OUT_DIR (default ./out, gitignored) โ€” never into a tracked path. Deploy the # resulting files with the `docker-tls` Ansible role, which places: # rn-lab-host-01: ca.pem, server-cert.pem, server-key.pem -> dockerd's --tlsverify config # rn-platform-01: ca.pem, provisioner-client-cert.pem, provisioner-client-key.pem # -> /etc/rootnode/docker-tls/ (referenced by lab-hosts.yaml) # # Usage: # ./generate-docker-tls.sh [--out-dir DIR] [--lab-host-ip IP] [--lab-host-dns NAME] [--days N] set -euo pipefail OUT_DIR="./out" LAB_HOST_IP="127.0.0.1" LAB_HOST_DNS="rn-lab-host-01.internal" DAYS=825 # ~2.25 years โ€” matches modern browser/OS max cert lifetime conventions; see rotation runbook for cadence while [ $# -gt 0 ]; do case "$1" in --out-dir) OUT_DIR="$2"; shift 2 ;; --lab-host-ip) LAB_HOST_IP="$2"; shift 2 ;; --lab-host-dns) LAB_HOST_DNS="$2"; shift 2 ;; --days) DAYS="$2"; shift 2 ;; *) echo "Unknown argument: $1" >&2; exit 1 ;; esac done mkdir -p "$OUT_DIR" cd "$OUT_DIR" umask 077 # private keys must never be group/world readable, from the moment they're written echo "==> Generating CA" openssl genrsa -out ca-key.pem 4096 openssl req -new -x509 -days "$DAYS" -key ca-key.pem -sha256 -out ca.pem \ -subj "/O=RootNode Academy/CN=RootNode Docker TLS CA" echo "==> Generating server cert for rn-lab-host-01 (dockerd)" openssl genrsa -out server-key.pem 4096 openssl req -subj "/CN=$LAB_HOST_DNS" -sha256 -new -key server-key.pem -out server.csr cat > server-extfile.cnf < Generating client cert for the Provisioner" openssl genrsa -out provisioner-client-key.pem 4096 openssl req -subj "/CN=rootnode-provisioner" -new -key provisioner-client-key.pem -out client.csr cat > client-extfile.cnf < Done. Generated in $OUT_DIR:" ls -la echo echo "Deploy server-{cert,key}.pem + ca.pem to rn-lab-host-01 (docker-tls Ansible role)." echo "Deploy provisioner-client-{cert,key}.pem + ca.pem to rn-platform-01 (same role)." echo "Verify with: ../verify-docker-tls.sh $OUT_DIR "