Skip to content

Commit 1530b82

Browse files
committed
Address comments on the "rootless CA certs" patch
Address the following problems with adoptium#538: 1. Correct the shell selection for entrypoint, Ubuntu flavours still need explicit `bash` for variables with dots in their names 2. Change unhelpful exported variable name (changed from `CACERT` to `JRE_CACERTS_PATH`) 3. Change `which` to more-POSIX-compatible `command -v` 4. More cleanup 5. Explicitely use `TMPDIR` when available instead of hard-coded `/tmp`
1 parent b65ebd7 commit 1530b82

File tree

63 files changed

+852
-623
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+852
-623
lines changed

.test/tests/java-ca-certificates-update/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CMD1=date
1010

1111
# CMD2 in each run is to check for the `dockerbuilder` certificate in the Java keystore. Entrypoint export $CACERT to
1212
# point to the Java keystore.
13-
CMD2=(sh -c "keytool -list -keystore \$CACERT -storepass changeit -alias dockerbuilder")
13+
CMD2=(sh -c "keytool -list -keystore \$JRE_CACERTS_PATH -storepass changeit -alias dockerbuilder")
1414

1515
# For a custom entrypoint test, we need to create a new image. This image will get cleaned up at the end of the script
1616
# by the `finish` trap function.

11/jdk/alpine/entrypoint.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env sh
2-
# Converted to POSIX shell to avoid the need for bash in the image
2+
# This script defines `sh` as the interpreter, which is available in all POSIX environments. However, it might get
3+
# started with `bash` as the shell to support dotted.environment.variable.names which are not supported by POSIX, but
4+
# are supported by `sh` in some Linux flavours.
35

46
set -e
57

68
# JDK truststore location
7-
CACERT=$JAVA_HOME/lib/security/cacerts
9+
JRE_CACERTS_PATH=$JAVA_HOME/lib/security/cacerts
810

911
# JDK8 puts its JRE in a subdirectory
1012
if [ -f "$JAVA_HOME/jre/lib/security/cacerts" ]; then
11-
CACERT=$JAVA_HOME/jre/lib/security/cacerts
13+
JRE_CACERTS_PATH=$JAVA_HOME/jre/lib/security/cacerts
1214
fi
1315

1416
# Opt-in is only activated if the environment variable is set
@@ -21,14 +23,14 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
2123

2224
# Figure out whether we can write to the JVM truststore. If we can, we'll add the certificates there. If not,
2325
# we'll use a temporary truststore.
24-
if [ ! -w "$CACERT" ]; then
26+
if [ ! -w "$JRE_CACERTS_PATH" ]; then
2527
# We cannot write to the JVM truststore, so we create a temporary one
26-
CACERT_NEW=$(mktemp)
27-
echo "Using a temporary truststore at $CACERT_NEW"
28-
cp $CACERT $CACERT_NEW
29-
CACERT=$CACERT_NEW
28+
JRE_CACERTS_PATH_NEW=$(mktemp)
29+
echo "Using a temporary truststore at $JRE_CACERTS_PATH_NEW"
30+
cp "$JRE_CACERTS_PATH" "$JRE_CACERTS_PATH_NEW"
31+
JRE_CACERTS_PATH=$JRE_CACERTS_PATH_NEW
3032
# If we use a custom truststore, we need to make sure that the JVM uses it
31-
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${CACERT} -Djavax.net.ssl.trustStorePassword=changeit"
33+
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${JRE_CACERTS_PATH} -Djavax.net.ssl.trustStorePassword=changeit"
3234
fi
3335

3436
tmp_store=$(mktemp)
@@ -37,14 +39,17 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
3739
trust extract --overwrite --format=java-cacerts --filter=ca-anchors --purpose=server-auth "$tmp_store"
3840

3941
# Add the system CA certificates to the JVM truststore.
40-
keytool -importkeystore -destkeystore "$CACERT" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt # >/dev/null
42+
keytool -importkeystore -destkeystore "$JRE_CACERTS_PATH" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt
43+
44+
# Clean up the temporary truststore
45+
rm "$tmp_store"
4146

4247
# Import the additional certificate into JVM truststore
4348
for i in /certificates/*crt; do
4449
if [ ! -f "$i" ]; then
4550
continue
4651
fi
47-
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$CACERT" -storepass changeit # >/dev/null
52+
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$JRE_CACERTS_PATH" -storepass changeit # >/dev/null
4853
done
4954

5055
# Add additional certificates to the system CA store. This requires write permissions to several system
@@ -68,12 +73,12 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
6873
fi
6974

7075
# UBI/CentOS
71-
if which update-ca-trust >/dev/null; then
76+
if command -v update-ca-trust >/dev/null; then
7277
update-ca-trust
7378
fi
7479

7580
# Ubuntu/Alpine
76-
if which update-ca-certificates >/dev/null; then
81+
if command -v update-ca-certificates >/dev/null; then
7782
update-ca-certificates
7883
fi
7984
else
@@ -84,6 +89,6 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
8489
fi
8590

8691
# Let's provide a variable with the correct path for tools that want or need to use it
87-
export CACERT
92+
export JRE_CACERTS_PATH
8893

8994
exec "$@"

11/jdk/centos/entrypoint.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env sh
2-
# Converted to POSIX shell to avoid the need for bash in the image
2+
# This script defines `sh` as the interpreter, which is available in all POSIX environments. However, it might get
3+
# started with `bash` as the shell to support dotted.environment.variable.names which are not supported by POSIX, but
4+
# are supported by `sh` in some Linux flavours.
35

46
set -e
57

68
# JDK truststore location
7-
CACERT=$JAVA_HOME/lib/security/cacerts
9+
JRE_CACERTS_PATH=$JAVA_HOME/lib/security/cacerts
810

911
# JDK8 puts its JRE in a subdirectory
1012
if [ -f "$JAVA_HOME/jre/lib/security/cacerts" ]; then
11-
CACERT=$JAVA_HOME/jre/lib/security/cacerts
13+
JRE_CACERTS_PATH=$JAVA_HOME/jre/lib/security/cacerts
1214
fi
1315

1416
# Opt-in is only activated if the environment variable is set
@@ -21,14 +23,14 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
2123

2224
# Figure out whether we can write to the JVM truststore. If we can, we'll add the certificates there. If not,
2325
# we'll use a temporary truststore.
24-
if [ ! -w "$CACERT" ]; then
26+
if [ ! -w "$JRE_CACERTS_PATH" ]; then
2527
# We cannot write to the JVM truststore, so we create a temporary one
26-
CACERT_NEW=$(mktemp)
27-
echo "Using a temporary truststore at $CACERT_NEW"
28-
cp $CACERT $CACERT_NEW
29-
CACERT=$CACERT_NEW
28+
JRE_CACERTS_PATH_NEW=$(mktemp)
29+
echo "Using a temporary truststore at $JRE_CACERTS_PATH_NEW"
30+
cp "$JRE_CACERTS_PATH" "$JRE_CACERTS_PATH_NEW"
31+
JRE_CACERTS_PATH=$JRE_CACERTS_PATH_NEW
3032
# If we use a custom truststore, we need to make sure that the JVM uses it
31-
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${CACERT} -Djavax.net.ssl.trustStorePassword=changeit"
33+
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${JRE_CACERTS_PATH} -Djavax.net.ssl.trustStorePassword=changeit"
3234
fi
3335

3436
tmp_store=$(mktemp)
@@ -37,14 +39,17 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
3739
trust extract --overwrite --format=java-cacerts --filter=ca-anchors --purpose=server-auth "$tmp_store"
3840

3941
# Add the system CA certificates to the JVM truststore.
40-
keytool -importkeystore -destkeystore "$CACERT" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt # >/dev/null
42+
keytool -importkeystore -destkeystore "$JRE_CACERTS_PATH" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt
43+
44+
# Clean up the temporary truststore
45+
rm "$tmp_store"
4146

4247
# Import the additional certificate into JVM truststore
4348
for i in /certificates/*crt; do
4449
if [ ! -f "$i" ]; then
4550
continue
4651
fi
47-
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$CACERT" -storepass changeit # >/dev/null
52+
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$JRE_CACERTS_PATH" -storepass changeit # >/dev/null
4853
done
4954

5055
# Add additional certificates to the system CA store. This requires write permissions to several system
@@ -68,12 +73,12 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
6873
fi
6974

7075
# UBI/CentOS
71-
if which update-ca-trust >/dev/null; then
76+
if command -v update-ca-trust >/dev/null; then
7277
update-ca-trust
7378
fi
7479

7580
# Ubuntu/Alpine
76-
if which update-ca-certificates >/dev/null; then
81+
if command -v update-ca-certificates >/dev/null; then
7782
update-ca-certificates
7883
fi
7984
else
@@ -84,6 +89,6 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
8489
fi
8590

8691
# Let's provide a variable with the correct path for tools that want or need to use it
87-
export CACERT
92+
export JRE_CACERTS_PATH
8893

8994
exec "$@"

11/jdk/ubi/ubi9-minimal/entrypoint.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env sh
2-
# Converted to POSIX shell to avoid the need for bash in the image
2+
# This script defines `sh` as the interpreter, which is available in all POSIX environments. However, it might get
3+
# started with `bash` as the shell to support dotted.environment.variable.names which are not supported by POSIX, but
4+
# are supported by `sh` in some Linux flavours.
35

46
set -e
57

68
# JDK truststore location
7-
CACERT=$JAVA_HOME/lib/security/cacerts
9+
JRE_CACERTS_PATH=$JAVA_HOME/lib/security/cacerts
810

911
# JDK8 puts its JRE in a subdirectory
1012
if [ -f "$JAVA_HOME/jre/lib/security/cacerts" ]; then
11-
CACERT=$JAVA_HOME/jre/lib/security/cacerts
13+
JRE_CACERTS_PATH=$JAVA_HOME/jre/lib/security/cacerts
1214
fi
1315

1416
# Opt-in is only activated if the environment variable is set
@@ -21,14 +23,14 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
2123

2224
# Figure out whether we can write to the JVM truststore. If we can, we'll add the certificates there. If not,
2325
# we'll use a temporary truststore.
24-
if [ ! -w "$CACERT" ]; then
26+
if [ ! -w "$JRE_CACERTS_PATH" ]; then
2527
# We cannot write to the JVM truststore, so we create a temporary one
26-
CACERT_NEW=$(mktemp)
27-
echo "Using a temporary truststore at $CACERT_NEW"
28-
cp $CACERT $CACERT_NEW
29-
CACERT=$CACERT_NEW
28+
JRE_CACERTS_PATH_NEW=$(mktemp)
29+
echo "Using a temporary truststore at $JRE_CACERTS_PATH_NEW"
30+
cp "$JRE_CACERTS_PATH" "$JRE_CACERTS_PATH_NEW"
31+
JRE_CACERTS_PATH=$JRE_CACERTS_PATH_NEW
3032
# If we use a custom truststore, we need to make sure that the JVM uses it
31-
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${CACERT} -Djavax.net.ssl.trustStorePassword=changeit"
33+
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${JRE_CACERTS_PATH} -Djavax.net.ssl.trustStorePassword=changeit"
3234
fi
3335

3436
tmp_store=$(mktemp)
@@ -37,14 +39,17 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
3739
trust extract --overwrite --format=java-cacerts --filter=ca-anchors --purpose=server-auth "$tmp_store"
3840

3941
# Add the system CA certificates to the JVM truststore.
40-
keytool -importkeystore -destkeystore "$CACERT" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt # >/dev/null
42+
keytool -importkeystore -destkeystore "$JRE_CACERTS_PATH" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt
43+
44+
# Clean up the temporary truststore
45+
rm "$tmp_store"
4146

4247
# Import the additional certificate into JVM truststore
4348
for i in /certificates/*crt; do
4449
if [ ! -f "$i" ]; then
4550
continue
4651
fi
47-
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$CACERT" -storepass changeit # >/dev/null
52+
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$JRE_CACERTS_PATH" -storepass changeit # >/dev/null
4853
done
4954

5055
# Add additional certificates to the system CA store. This requires write permissions to several system
@@ -68,12 +73,12 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
6873
fi
6974

7075
# UBI/CentOS
71-
if which update-ca-trust >/dev/null; then
76+
if command -v update-ca-trust >/dev/null; then
7277
update-ca-trust
7378
fi
7479

7580
# Ubuntu/Alpine
76-
if which update-ca-certificates >/dev/null; then
81+
if command -v update-ca-certificates >/dev/null; then
7782
update-ca-certificates
7883
fi
7984
else
@@ -84,6 +89,6 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
8489
fi
8590

8691
# Let's provide a variable with the correct path for tools that want or need to use it
87-
export CACERT
92+
export JRE_CACERTS_PATH
8893

8994
exec "$@"

11/jdk/ubuntu/focal/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ RUN set -eux; \
100100
echo "java --version"; java --version; \
101101
echo "Complete."
102102
COPY entrypoint.sh /__cacert_entrypoint.sh
103-
ENTRYPOINT ["/__cacert_entrypoint.sh"]
103+
ENTRYPOINT ["/usr/bin/env", "bash", "-c", "/__cacert_entrypoint.sh"]
104104

105105
CMD ["jshell"]

11/jdk/ubuntu/focal/entrypoint.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env sh
2-
# Converted to POSIX shell to avoid the need for bash in the image
2+
# This script defines `sh` as the interpreter, which is available in all POSIX environments. However, it might get
3+
# started with `bash` as the shell to support dotted.environment.variable.names which are not supported by POSIX, but
4+
# are supported by `sh` in some Linux flavours.
35

46
set -e
57

68
# JDK truststore location
7-
CACERT=$JAVA_HOME/lib/security/cacerts
9+
JRE_CACERTS_PATH=$JAVA_HOME/lib/security/cacerts
810

911
# JDK8 puts its JRE in a subdirectory
1012
if [ -f "$JAVA_HOME/jre/lib/security/cacerts" ]; then
11-
CACERT=$JAVA_HOME/jre/lib/security/cacerts
13+
JRE_CACERTS_PATH=$JAVA_HOME/jre/lib/security/cacerts
1214
fi
1315

1416
# Opt-in is only activated if the environment variable is set
@@ -21,14 +23,14 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
2123

2224
# Figure out whether we can write to the JVM truststore. If we can, we'll add the certificates there. If not,
2325
# we'll use a temporary truststore.
24-
if [ ! -w "$CACERT" ]; then
26+
if [ ! -w "$JRE_CACERTS_PATH" ]; then
2527
# We cannot write to the JVM truststore, so we create a temporary one
26-
CACERT_NEW=$(mktemp)
27-
echo "Using a temporary truststore at $CACERT_NEW"
28-
cp $CACERT $CACERT_NEW
29-
CACERT=$CACERT_NEW
28+
JRE_CACERTS_PATH_NEW=$(mktemp)
29+
echo "Using a temporary truststore at $JRE_CACERTS_PATH_NEW"
30+
cp "$JRE_CACERTS_PATH" "$JRE_CACERTS_PATH_NEW"
31+
JRE_CACERTS_PATH=$JRE_CACERTS_PATH_NEW
3032
# If we use a custom truststore, we need to make sure that the JVM uses it
31-
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${CACERT} -Djavax.net.ssl.trustStorePassword=changeit"
33+
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS} -Djavax.net.ssl.trustStore=${JRE_CACERTS_PATH} -Djavax.net.ssl.trustStorePassword=changeit"
3234
fi
3335

3436
tmp_store=$(mktemp)
@@ -37,14 +39,17 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
3739
trust extract --overwrite --format=java-cacerts --filter=ca-anchors --purpose=server-auth "$tmp_store"
3840

3941
# Add the system CA certificates to the JVM truststore.
40-
keytool -importkeystore -destkeystore "$CACERT" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt # >/dev/null
42+
keytool -importkeystore -destkeystore "$JRE_CACERTS_PATH" -srckeystore "$tmp_store" -srcstorepass changeit -deststorepass changeit -noprompt
43+
44+
# Clean up the temporary truststore
45+
rm "$tmp_store"
4146

4247
# Import the additional certificate into JVM truststore
4348
for i in /certificates/*crt; do
4449
if [ ! -f "$i" ]; then
4550
continue
4651
fi
47-
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$CACERT" -storepass changeit # >/dev/null
52+
keytool -import -noprompt -alias "$(basename "$i" .crt)" -file "$i" -keystore "$JRE_CACERTS_PATH" -storepass changeit # >/dev/null
4853
done
4954

5055
# Add additional certificates to the system CA store. This requires write permissions to several system
@@ -68,12 +73,12 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
6873
fi
6974

7075
# UBI/CentOS
71-
if which update-ca-trust >/dev/null; then
76+
if command -v update-ca-trust >/dev/null; then
7277
update-ca-trust
7378
fi
7479

7580
# Ubuntu/Alpine
76-
if which update-ca-certificates >/dev/null; then
81+
if command -v update-ca-certificates >/dev/null; then
7782
update-ca-certificates
7883
fi
7984
else
@@ -84,6 +89,6 @@ if [ -n "$USE_SYSTEM_CA_CERTS" ]; then
8489
fi
8590

8691
# Let's provide a variable with the correct path for tools that want or need to use it
87-
export CACERT
92+
export JRE_CACERTS_PATH
8893

8994
exec "$@"

11/jdk/ubuntu/jammy/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ RUN set -eux; \
100100
echo "java --version"; java --version; \
101101
echo "Complete."
102102
COPY entrypoint.sh /__cacert_entrypoint.sh
103-
ENTRYPOINT ["/__cacert_entrypoint.sh"]
103+
ENTRYPOINT ["/usr/bin/env", "bash", "-c", "/__cacert_entrypoint.sh"]
104104

105105
CMD ["jshell"]

0 commit comments

Comments
 (0)