#!/bin/sh set -e mkdir -p /certs cd /certs if [ -f ca.key ] && [ -f ca.crt ] && [ -f lb.crt ] && [ -f api.crt ] && [ -f openbao.crt ]; then mkdir -p /postgres-certs cp ca.crt postgres.crt postgres.key /postgres-certs/ chmod 600 /postgres-certs/postgres.key chown -R 70:70 /postgres-certs 2>/dev/null || true exit 0 fi openssl genrsa -out ca.key 4096 >/dev/null 2>&1 openssl req -x509 -new -key ca.key -sha256 -days 3650 -subj "/CN=MTUSI Lab7 Root CA" -out ca.crt >/dev/null 2>&1 make_leaf() { name="$1" cn="$2" san="$3" openssl genrsa -out "$name.key" 2048 >/dev/null 2>&1 openssl req -new -key "$name.key" -subj "/CN=$cn" -out "$name.csr" >/dev/null 2>&1 cat > "$name.ext" </dev/null 2>&1 rm -f "$name.csr" "$name.ext" } make_leaf public localhost "DNS:localhost,DNS:nginx,DNS:lb.lab.local" serverAuth make_leaf lb lb.lab.local "DNS:lb.lab.local,URI:spiffe://lab7/lb" clientAuth make_leaf api api.lab.local "DNS:api,DNS:api.lab.local" serverAuth,clientAuth make_leaf openbao openbao.lab.local "DNS:openbao,DNS:openbao.lab.local" serverAuth make_leaf minio minio.lab.local "DNS:minio,DNS:minio.lab.local" serverAuth mkdir -p minio-certs cp minio.crt minio-certs/public.crt cp minio.key minio-certs/private.key chmod 600 ca.key public.key lb.key api.key openbao.key