@@ -30,46 +30,47 @@ spec:
3030{{- if eq .Values.app.spire.enabled true }}
3131 initContainers :
3232 - name : init-ca-truststore
33- image : registry.redhat.io/ubi9/openjdk-17 :latest
33+ image : registry.redhat.io/openshift4/ose-tools-rhel9 :latest
3434 imagePullPolicy : IfNotPresent
3535 command :
3636 - /bin/bash
3737 - -c
3838 - |
3939 set -e
40- echo "Converting CA bundle to Java truststore..."
40+ echo "Converting CA bundle to PKCS12 truststore using openssl ..."
4141
4242 # Validate password is provided
4343 if [ -z "$TRUSTSTORE_PASSWORD" ]; then
4444 echo "ERROR: TRUSTSTORE_PASSWORD not set"
4545 exit 1
4646 fi
4747
48- # Split the PEM bundle into individual certificates
49- csplit -s -z -f /tmp/cert- /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem '/-----BEGIN CERTIFICATE-----/' '{*}'
48+ CA_BUNDLE="/etc/pki/ca-trust/extracted/pem/tls-ca- bundle.pem"
49+ TRUSTSTORE_PATH="/run/secrets/truststore/truststore.p12"
5050
51- # Create the truststore with each certificate
52- TRUSTSTORE_PATH="/run/secrets/truststore/cacerts"
51+ # Verify CA bundle exists
52+ if [ ! -f "$CA_BUNDLE" ]; then
53+ echo "ERROR: CA bundle not found at $CA_BUNDLE"
54+ exit 1
55+ fi
5356
54- # Remove any existing truststore
55- rm -f "$TRUSTSTORE_PATH"
57+ # Count certificates in bundle
58+ CERT_COUNT=$(grep -c "BEGIN CERTIFICATE" "$CA_BUNDLE" || echo "0")
59+ echo "Found $CERT_COUNT certificates in CA bundle"
5660
57- # Import each certificate into the truststore
58- cert_index=0
59- for cert_file in /tmp/cert-*; do
60- if [ -s "$cert_file" ]; then
61- echo "Importing certificate $cert_index from $cert_file"
62- keytool -import -noprompt \
63- -alias "ztvp-ca-$cert_index" \
64- -keystore "$TRUSTSTORE_PATH" \
65- -storepass "$TRUSTSTORE_PASSWORD" \
66- -file "$cert_file" || echo "Warning: Failed to import $cert_file"
67- cert_index=$((cert_index + 1))
68- fi
69- done
61+ # Create PKCS12 truststore from PEM bundle using openssl (single command, no loop)
62+ openssl pkcs12 -export -nokeys \
63+ -in "$CA_BUNDLE" \
64+ -out "$TRUSTSTORE_PATH" \
65+ -passout pass:"$TRUSTSTORE_PASSWORD" \
66+ -name "ztvp-ca-bundle"
7067
71- echo "Successfully created truststore with $cert_index certificates "
68+ echo "Successfully created PKCS12 truststore "
7269 ls -lh "$TRUSTSTORE_PATH"
70+
71+ # Verify the truststore
72+ echo "Verifying PKCS12 truststore..."
73+ openssl pkcs12 -info -in "$TRUSTSTORE_PATH" -passin pass:"$TRUSTSTORE_PASSWORD" -nokeys 2>&1 | head -10
7374 env :
7475 - name : TRUSTSTORE_PASSWORD
7576 valueFrom :
8283 readOnly : true
8384 - name : truststore
8485 mountPath : /run/secrets/truststore
86+ - name : wait-for-keycloak
87+ image : registry.redhat.io/openshift4/ose-tools-rhel9:latest
88+ imagePullPolicy : IfNotPresent
89+ command :
90+ - /bin/sh
91+ - -c
92+ - |
93+ echo "Waiting for Keycloak OIDC endpoint to be available..."
94+ KEYCLOAK_URL="{{ default (printf "https://keycloak.%s/realms/ztvp/.well-known/openid-configuration" .Values.global.localClusterDomain) .Values.app.oidc.authServerUrl }}/.well-known/openid-configuration"
95+ # Remove duplicate .well-known if authServerUrl already contains realm
96+ KEYCLOAK_URL=$(echo "$KEYCLOAK_URL" | sed 's|/.well-known/openid-configuration/.well-known/openid-configuration|/.well-known/openid-configuration|')
97+
98+ MAX_RETRIES=60
99+ RETRY_INTERVAL=5
100+ RETRY_COUNT=0
101+
102+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
103+ if curl -sf --cacert /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem "$KEYCLOAK_URL" > /dev/null 2>&1; then
104+ echo "Keycloak is available!"
105+ exit 0
106+ fi
107+ RETRY_COUNT=$((RETRY_COUNT + 1))
108+ echo "Keycloak not ready yet (attempt $RETRY_COUNT/$MAX_RETRIES). Retrying in ${RETRY_INTERVAL}s..."
109+ sleep $RETRY_INTERVAL
110+ done
111+
112+ echo "WARNING: Keycloak not available after $MAX_RETRIES attempts. Continuing anyway..."
113+ exit 0
114+ volumeMounts :
115+ - name : ztvp-trusted-ca
116+ mountPath : /etc/pki/ca-trust/extracted/pem
117+ readOnly : true
85118 - name : init-spiffe-helper
86119 image : {{ template "qtodo.image" .Values.app.images.spiffeHelper }}
87120 imagePullPolicy : {{ .Values.app.images.spiffeHelper.pullPolicy }}
@@ -213,7 +246,7 @@ spec:
213246 value : ' 0.0.0.0'
214247 - name : QUARKUS_HTTP_PORT
215248 value : ' 8080'
216- - name : QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION
249+ - name : QUARKUS_HIBERNATE_ORM_SCHEMA_MANAGEMENT_STRATEGY
217250 value : ' drop-and-create'
218251{{- if eq .Values.app.spire.enabled false }}
219252 - name : QUARKUS_DATASOURCE_USERNAME
@@ -241,9 +274,9 @@ spec:
241274 secretKeyRef :
242275 name : qtodo-truststore-secret
243276 key : truststore-password
244- # JVM-level truststore configuration for all SSL connections
277+ # JVM-level truststore configuration for all SSL connections (PKCS12 format)
245278 - name : JAVA_TOOL_OPTIONS
246- value : " -Djavax.net.ssl.trustStore=/run/secrets/truststore/cacerts -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStorePassword=$(TRUSTSTORE_PASSWORD)"
279+ value : " -Djavax.net.ssl.trustStore=/run/secrets/truststore/truststore.p12 -Djavax.net.ssl.trustStoreType=PKCS12 -Djavax.net.ssl.trustStorePassword=$(TRUSTSTORE_PASSWORD)"
247280{{- end }}
248281{{- end }}
249282{{- if eq .Values.app.spire.enabled true }}
0 commit comments