Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions base/ubi10/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@ replace_user_home() {
echo "$1" | sed "s|^/home/tooling|$HOME|"
}

jdk_import_ca_bundle() {
CA_BUNDLE="${JDK_CA_BUNDLE:-/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem}"
KEYSTORE_PASSWORD="${JDK_KEYSTORE_PASSWORD:-changeit}"

if ! command -v keytool >/dev/null 2>&1; then
return
fi

if [ ! -f "$CA_BUNDLE" ]; then
echo "[jdk] Failed to import CA certificates from ${CA_BUNDLE}. File doesn't exist"
return
fi

bundle_name=$(basename "$CA_BUNDLE")
certs_imported=0
cert_index=0
tmp_file=/tmp/cert.pem
is_cert=false
echo "[jdk] Importing certificates..."
while IFS= read -r line; do
if [ "$line" = "-----BEGIN CERTIFICATE-----" ]; then
is_cert=true
cert_index=$((cert_index+1))
echo "$line" > ${tmp_file}
elif [ "$line" = "-----END CERTIFICATE-----" ]; then
is_cert=false
echo "$line" >> ${tmp_file}
if keytool -import -trustcacerts -cacerts -storepass "$KEYSTORE_PASSWORD" -noprompt -alias "${bundle_name}_${cert_index}" -file $tmp_file; then
certs_imported=$((certs_imported+1))
fi
certs_imported=$((certs_imported+1))
Copy link
Collaborator

@dkwon17 dkwon17 Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check the keytool command for an error and increment certs_imported only if there is no error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

elif [ "$is_cert" = true ]; then
echo "$line" >> ${tmp_file}
fi
done < "$CA_BUNDLE"

echo "[jdk] Imported ${certs_imported} certificates from ${CA_BUNDLE}"
rm -f $tmp_file
}

# Ensure $HOME exists when starting
if [ ! -d "${HOME}" ]; then
mkdir -p "${HOME}"
Expand Down Expand Up @@ -219,4 +259,6 @@ if [ -d /home/tooling/.config ]; then
echo "Finished creating .config symlinks."
fi

jdk_import_ca_bundle &

exec "$@"
42 changes: 42 additions & 0 deletions base/ubi9/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,46 @@ replace_user_home() {
echo "$1" | sed "s|^/home/tooling|$HOME|"
}

jdk_import_ca_bundle() {
CA_BUNDLE="${JDK_CA_BUNDLE:-/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem}"
KEYSTORE_PASSWORD="${JDK_KEYSTORE_PASSWORD:-changeit}"

if ! command -v keytool >/dev/null 2>&1; then
return
fi

if [ ! -f "$CA_BUNDLE" ]; then
echo "[jdk] Failed to import CA certificates from ${CA_BUNDLE}. File doesn't exist"
return
fi

bundle_name=$(basename "$CA_BUNDLE")
certs_imported=0
cert_index=0
tmp_file=/tmp/cert.pem
is_cert=false
echo "[jdk] Importing certificates..."
while IFS= read -r line; do
if [ "$line" = "-----BEGIN CERTIFICATE-----" ]; then
is_cert=true
cert_index=$((cert_index+1))
echo "$line" > ${tmp_file}
elif [ "$line" = "-----END CERTIFICATE-----" ]; then
is_cert=false
echo "$line" >> ${tmp_file}
if keytool -import -trustcacerts -cacerts -storepass "$KEYSTORE_PASSWORD" -noprompt -alias "${bundle_name}_${cert_index}" -file $tmp_file; then
certs_imported=$((certs_imported+1))
fi
certs_imported=$((certs_imported+1))
elif [ "$is_cert" = true ]; then
echo "$line" >> ${tmp_file}
fi
done < "$CA_BUNDLE"

echo "[jdk] Imported ${certs_imported} certificates from ${CA_BUNDLE}"
rm -f $tmp_file
}

# Ensure $HOME exists when starting
if [ ! -d "${HOME}" ]; then
mkdir -p "${HOME}"
Expand Down Expand Up @@ -218,4 +258,6 @@ if [ -d /home/tooling/.config ]; then
echo "Finished creating .config symlinks."
fi

jdk_import_ca_bundle &

exec "$@"