#!/bin/bash # Generate TLS certificates for the webhook # This creates a self-signed CA and certificate for the webhook service set -e NAMESPACE="irsa-system" SERVICE_NAME="irsa-webhook" SECRET_NAME="irsa-webhook-certs" WEBHOOK_CONFIG_NAME="irsa-webhook" # Create temporary directory for certificate generation CERT_DIR=$(mktemp -d) trap "rm -rf ${CERT_DIR}" EXIT echo "Generating certificates in ${CERT_DIR}..." # Generate CA private key openssl genrsa -out ${CERT_DIR}/ca.key 2048 # Generate CA certificate openssl req -x509 -new -nodes -key ${CERT_DIR}/ca.key \ -subj "/CN=IRSA Webhook CA" \ -days 3650 \ -out ${CERT_DIR}/ca.crt # Generate webhook private key openssl genrsa -out ${CERT_DIR}/tls.key 2048 # Create certificate signing request cat > ${CERT_DIR}/csr.conf < .ca-bundle.txt # Update MutatingWebhookConfiguration with CA bundle if kubectl get mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} &> /dev/null; then kubectl patch mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} \ --type='json' \ -p="[{'op': 'replace', 'path': '/webhooks/0/clientConfig/caBundle', 'value':'${CA_BUNDLE}'}]" echo "MutatingWebhookConfiguration ${WEBHOOK_CONFIG_NAME} updated with CA bundle" else echo "MutatingWebhookConfiguration not found yet. CA bundle saved to .ca-bundle.txt" fi echo "" echo "Setup complete! CA Bundle saved to .ca-bundle.txt"