#!/usr/bin/env bash # # gen-tls.sh — generate a self-signed TLS cert + key for the OpenBao listener, # if one is not already present. Never overwrites existing files, so to use a # CA-signed cert (e.g. issued by your Smallstep CA over ACME) just drop tls.crt + # tls.key into the target dir instead and this becomes a no-op. # # Usage: bash gen-tls.sh [TLS_DIR] (default ./tls) # Env: OPENBAO_TLS_SANS comma SAN list, e.g. "DNS:vault.lan,IP:10.0.0.10,IP:127.0.0.1" # OPENBAO_TLS_DAYS validity in days (default 825 — the max browsers accept) set -euo pipefail DIR="${1:-./tls}" SANS="${OPENBAO_TLS_SANS:-DNS:localhost,IP:127.0.0.1}" DAYS="${OPENBAO_TLS_DAYS:-825}" mkdir -p "$DIR" if [[ -f "$DIR/tls.crt" && -f "$DIR/tls.key" ]]; then echo "[gen-tls] TLS material already present in $DIR — leaving it alone." exit 0 fi command -v openssl >/dev/null 2>&1 || { echo "[gen-tls] openssl not found" >&2; exit 1; } # ECDSA P-256 self-signed cert. The SAN must include every address the tape host # (and CLI) use to reach the vault, or their TLS verification fails. openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \ -keyout "$DIR/tls.key" -out "$DIR/tls.crt" -days "$DAYS" \ -subj "/CN=openbao" -addext "subjectAltName=${SANS}" chmod 600 "$DIR/tls.key" chmod 644 "$DIR/tls.crt" echo "[gen-tls] Generated self-signed OpenBao cert in $DIR" echo "[gen-tls] SANs: ${SANS} validity: ${DAYS}d" echo "[gen-tls] Give $DIR/tls.crt to the Kanrisha daemon as" echo "[gen-tls] [encryption.openbao].ca_cert (so it trusts this listener)."