Skip to content

Commit 8be33c7

Browse files
committed
chore: Import certificates on the start
Signed-off-by: Anatolii Bazko <[email protected]>
1 parent 4b34b0b commit 8be33c7

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

base/ubi10/entrypoint.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ replace_user_home() {
66
echo "$1" | sed "s|^/home/tooling|$HOME|"
77
}
88

9+
java_import_ca_bundle() {
10+
CA_BUNDLE="${JDK_CA_BUNDLE:-/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem}"
11+
KEYSTORE_PASSWORD="${JDK_KEYSTORE_PASSWORD:-changeit}"
12+
13+
if ! command -v keytool >/dev/null 2>&1; then
14+
return
15+
fi
16+
17+
if [ ! -f "$CA_BUNDLE" ]; then
18+
echo "[jdk] Failed to import CA certificates from ${CA_BUNDLE}. File doesn't exist"
19+
return
20+
fi
21+
22+
bundle_name=$(basename "$CA_BUNDLE")
23+
certs_imported=0
24+
cert_index=0
25+
tmp_file=/tmp/cert.pem
26+
is_cert=false
27+
echo "[jdk] Importing certificates..."
28+
while IFS= read -r line; do
29+
if [ "$line" = "-----BEGIN CERTIFICATE-----" ]; then
30+
is_cert=true
31+
cert_index=$((cert_index+1))
32+
echo "$line" > ${tmp_file}
33+
elif [ "$line" = "-----END CERTIFICATE-----" ]; then
34+
is_cert=false
35+
echo "$line" >> ${tmp_file}
36+
keytool -import -trustcacerts -cacerts -storepass "$KEYSTORE_PASSWORD" -noprompt -alias "${bundle_name}_${cert_index}" -file $tmp_file
37+
certs_imported=$((certs_imported+1))
38+
elif [ "$is_cert" = true ]; then
39+
echo "$line" >> ${tmp_file}
40+
fi
41+
done < "$CA_BUNDLE"
42+
43+
echo "[jdk] Imported ${certs_imported} certificates from ${CA_BUNDLE}"
44+
rm -f $tmp_file
45+
}
46+
947
# Ensure $HOME exists when starting
1048
if [ ! -d "${HOME}" ]; then
1149
mkdir -p "${HOME}"
@@ -219,4 +257,6 @@ if [ -d /home/tooling/.config ]; then
219257
echo "Finished creating .config symlinks."
220258
fi
221259

260+
java_import_ca_bundle &
261+
222262
exec "$@"

base/ubi9/entrypoint.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,44 @@ replace_user_home() {
55
echo "$1" | sed "s|^/home/tooling|$HOME|"
66
}
77

8+
jdk_import_ca_bundle() {
9+
CA_BUNDLE="${JDK_CA_BUNDLE:-/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem}"
10+
KEYSTORE_PASSWORD="${JDK_KEYSTORE_PASSWORD:-changeit}"
11+
12+
if ! command -v keytool >/dev/null 2>&1; then
13+
return
14+
fi
15+
16+
if [ ! -f "$CA_BUNDLE" ]; then
17+
echo "[jdk] Failed to import CA certificates from ${CA_BUNDLE}. File doesn't exist"
18+
return
19+
fi
20+
21+
bundle_name=$(basename "$CA_BUNDLE")
22+
certs_imported=0
23+
cert_index=0
24+
tmp_file=/tmp/cert.pem
25+
is_cert=false
26+
echo "[jdk] Importing certificates..."
27+
while IFS= read -r line; do
28+
if [ "$line" = "-----BEGIN CERTIFICATE-----" ]; then
29+
is_cert=true
30+
cert_index=$((cert_index+1))
31+
echo "$line" > ${tmp_file}
32+
elif [ "$line" = "-----END CERTIFICATE-----" ]; then
33+
is_cert=false
34+
echo "$line" >> ${tmp_file}
35+
keytool -import -trustcacerts -cacerts -storepass "$KEYSTORE_PASSWORD" -noprompt -alias "${bundle_name}_${cert_index}" -file $tmp_file
36+
certs_imported=$((certs_imported+1))
37+
elif [ "$is_cert" = true ]; then
38+
echo "$line" >> ${tmp_file}
39+
fi
40+
done < "$CA_BUNDLE"
41+
42+
echo "[jdk] Imported ${certs_imported} certificates from ${CA_BUNDLE}"
43+
rm -f $tmp_file
44+
}
45+
846
# Ensure $HOME exists when starting
947
if [ ! -d "${HOME}" ]; then
1048
mkdir -p "${HOME}"
@@ -218,4 +256,6 @@ if [ -d /home/tooling/.config ]; then
218256
echo "Finished creating .config symlinks."
219257
fi
220258

259+
jdk_import_ca_bundle &
260+
221261
exec "$@"

0 commit comments

Comments
 (0)