fix: ensure CA certificate and key are created only if they do not exist

This commit is contained in:
2026-03-24 07:42:37 +01:00
parent 5a840f6577
commit 47efc09d18

View File

@@ -9,7 +9,9 @@ CA_DIR="${CA_DIR:-./ca}"
CA_NAME="${CA_NAME:-Azurite Emulator CA}" CA_NAME="${CA_NAME:-Azurite Emulator CA}"
STORAGE_ACCOUNT_NAME="${STORAGE_ACCOUNT_NAME:-azuritelocal}" STORAGE_ACCOUNT_NAME="${STORAGE_ACCOUNT_NAME:-azuritelocal}"
mkdir -p "$CA_DIR" mkdir -p "$CA_DIR"
openssl req \ if [[ ! -f "${CA_DIR}/ca_cert.pem" || ! -f "${CA_DIR}/ca_key.pem" ]]; then
echo "Creating CA certificate and key..."
openssl req \
-x509 -noenc -text \ -x509 -noenc -text \
-newkey rsa:4096 \ -newkey rsa:4096 \
-keyout "${CA_DIR}/ca_key.pem" \ -keyout "${CA_DIR}/ca_key.pem" \
@@ -17,8 +19,9 @@ openssl req \
-days 3650 \ -days 3650 \
-subj "/CN=$CA_NAME" \ -subj "/CN=$CA_NAME" \
-addext "basicConstraints=critical,CA:TRUE,pathlen:0" -addext "basicConstraints=critical,CA:TRUE,pathlen:0"
HASH=$(openssl x509 -in "${CA_DIR}/ca_cert.pem" -noout -hash 2>/dev/null) HASH=$(openssl x509 -in "${CA_DIR}/ca_cert.pem" -noout -hash 2>/dev/null)
ln -sf $(basename "${CA_DIR}/ca_cert.pem") "${CA_DIR}/$HASH.0" # Check it ln -sf ca_cert.pem "${CA_DIR}/$HASH.0" # Check it
fi
ALTNAMES=() ALTNAMES=()
for endpoint in blob queue table; do for endpoint in blob queue table; do
ALTNAMES+=("DNS:${STORAGE_ACCOUNT_NAME}.${endpoint}.core.windows.net") ALTNAMES+=("DNS:${STORAGE_ACCOUNT_NAME}.${endpoint}.core.windows.net")