Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding SSL certificate in Distroless Image(Java Application)

I have a Java application containerized (docker) based on Distroless and I would like to add an SSL certificate in JVM's store.

I see an option like using Docker's RUN command to import the SSL certificate into JVM store using Java keytool option, but since Distroless doesn't come with Shell I couldn't able to use RUN command.

Is there a best way to add an SSL certificate into cacerts-Java with Distroless as Base image?

like image 846
Haran Avatar asked Mar 01 '19 16:03

Haran


People also ask

How set SSL Certificate in Java?

The steps to install a new certificate into the Java default truststore are: extract cert from server: openssl s_client -connect server:443. import certificate into truststore using keytool: keytool -import -alias alias.server.com -keystore $JAVA_HOME/jre/lib/security/cacerts.


1 Answers

We can use the exec form to write the command which doesn’t require a shell.

FROM gcr.io/distroless/java@sha256:da8aa0fa074d0ed9c4b71ad15af5dffdf6afdd768efbe2f0f7b0d60829278630
COPY my.crt /tmp/my.crt
RUN [\
 "/usr/lib/jvm/java-11-openjdk-amd64/bin/keytool",\
 "-import",\
 "-trustcacerts",\
 "-cacerts",\
 "-noprompt",\
 "-storepass",\
 "changeit",\
 "-alias",\
 "my",\
 "-file",\
 "/tmp/my.crt"\
]

Be sure to adjust the command to your needs!

like image 199
Fleshgrinder Avatar answered Oct 16 '22 17:10

Fleshgrinder