You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This should mostly just point at the main Jetty documentation on the subject, but it would probably be good to add some information about how to set up the keystore for the Docker image/container.
Comment by johncmckim Wednesday Dec 16, 2015 at 21:38 GMT
This would be really helpful. On the main page on docker hub, there is a line that shows running a container like so docker run -d -p 80:8080 -p 443:8443 jetty. Naturally, I thought that meant SSL was configured out of the box. However, it doesn't appear to be the case?
I have tried the config below, but it doesn't seem to work. I've probably got some of the jetty-https.xml config wrong. However, is this the general idea? Something like this in the docs that shows how to do it would be really helpful.
FROM jetty:9.3
RUN keytool -genkey -noprompt \
-alias jetty \
-dname "CN=xxx, OU=xx, O=xx, L=xx, S=xx, C=xx" \
-keystore /usr/local/jetty/etc/keystore \
-storepass password \
-keypass keyPassword
COPY jetty/jetty-https.xml /usr/local/jetty/etc/jetty-https.xml
RUN echo '--module=ssl' >> /usr/local/jetty/start.ini
RUN echo '--module=https' >> /usr/local/jetty/start.ini
Comment by gregw Thursday Dec 17, 2015 at 03:26 GMT
@johncmckim
rather than try to assemble the SSL configuration yourself, you'd be better off using the jetty module system to configure SSL, that way you get all the configuration setup for you (other than the keystore which your setup looks good). So you need something like:
RUN java -jar "$JETTY_HOME/start.jar" --add-to-startd=https
I couldn't get the keytool command to work correctly. I found that they keystore path should be $JETTY_BASE/etc/ketystore which is one step in the right direction. However, after this I found I was having issues with the password.
I ended up opting to add the --create-files command to your suggestion, which downloads a keystore from the jetty source for you. This probably isn't acceptable in many use cases but it is for me.
RUN java -jar "$JETTY_HOME/start.jar" --add-to-startd=https --create-files
@johncmckim If you want to use your own passwords, it looks like you'd want to append settings for jetty.sslContext.keyStorePassword, jetty.sslContext.trustStorePassword, and jetty.sslContext.keyManagerPassword to $JETTY_BASE/start.d/ssl.ini.
The values for these properties could be generated using java -cp $JETTY_HOME/lib/jetty-util-$JETTY_VERSION.jar org.eclipse.jetty.util.security.Password. Be aware that this command may hang when trying to generated the crypted password if you're in a context with low entropy (e.g. in a Boot2Docker VM like I just tried to test...)
These values could be specified for your build using Docker's ARG/--build-arg functionality if you want to avoid hard-coding your passwords.
All that being said, I think in a production context you'd want to avoid generating a self-signed certificate in the Dockerfile and instead mount in an existing keystore containing your private key and certificate with --volume. In that case, I believe the passwords could be passed through to Jetty in the container as additional arguments to the main start.jarCMD.
@johncmckim Were you trying in a VM? I tried that and it hung as well after printing out the "OBF" and "MD5" passwords. I believe the issue is that it's calling new SecureRandom() to generate the CRYPT password and hanging due to a lack of available entropy.
Comment by johncmckim Saturday Dec 19, 2015 at 01:31 GMT
@md5 yes. I was using docker on my windows dev machine. It would be using Virtualbox behind the scenes correct? What you describe is exactly what happened to me. I could see the OBF and MD5 passwords but it would not exit.
I too have the problem of adding ssl to jetty image in docker container. I just used the below commands to add my local keystore to jetty image. any help would be highly appreciated.
ADD keystore.jks $JETTY_HOME}/etc/keystore/keystore.jks
EXPOSE 8443
RUN java -jar "$JETTY_HOME/start.jar" --create-startd --add-to-start=https,ssl
docker run -v/home/gregw/src/jetty-9.4.x/jetty-io/src/test/resources/keystore:/var/lib/jetty/etc/keystore jetty --module=https
So I can see that your keystore is incorrectly named and you have a bracket problem. Try being explict and put the keystore at /var/lib/jetty/etc/keystore
Note you don't need to add the ssl module as that is a transient dependency of https. Nor do you need to create-startd as that is already created.
certificates of all the intermediary CAs that you may have used, so that a complete chain to a valid root may be built. In my case, I have a private CA whose certificate is my-priv-ca.crt, and a signing CA whose certificate is my-sign-ca.crt.
p12 archive built from the public and private parts of the server's certificate. You build it with something like openssl pkcs12 -export -name server -in server.pem -inkey server.key -out server-keystore.p12
In the Dockerfile, I copy all those files where they belong (/var/lib/jetty/start.d/ or /var/lib/jetty/etc/) and then work with the keytool to:
Remeber that you get the obfuscated password with java -cp ./jetty-util-9.3.6.v20151106.jar org.eclipse.jetty.util.security.Password jettyssl.
Note that I needed client authentication active: disable it if your site is public.
Comment by rvesse Friday Mar 20, 2020 at 11:14 GMT
@mimatn That's really helpful, have actually been working on something similar this last week myself and figured out much the same
One other gotcha that people should be aware of is that Jetty defaults to assuming a JKS format key store, if you are using Java 9+ as the JDK in your image then the default format becomes PKCS12 and trying to start Jetty with a Keystore in that format will produce stack traces like the following:
java.security.PrivilegedActionException: java.security.UnrecoverableKeyException: Get Key failed: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
Caused by:
java.security.UnrecoverableKeyException: Get Key failed: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
at java.base/sun.security.pkcs12.PKCS12KeyStore.engineGetKey(Unknown Source)
at java.base/sun.security.util.KeyStoreDelegator.engineGetKey(Unknown Source)
[...]
I believe there is a Jetty setting to change the default format but since in our environment we needed to be backwards compatible to JDK 8 for the time being we added --deststoretype jks to our keytool -importkeystore commands
Activity
joakime commentedon Jun 8, 2020
Wednesday Dec 16, 2015 at 21:38 GMT
This would be really helpful. On the main page on docker hub, there is a line that shows running a container like so
docker run -d -p 80:8080 -p 443:8443 jetty. Naturally, I thought that meant SSL was configured out of the box. However, it doesn't appear to be the case?I have tried the config below, but it doesn't seem to work. I've probably got some of the jetty-https.xml config wrong. However, is this the general idea? Something like this in the docs that shows how to do it would be really helpful.
joakime commentedon Jun 8, 2020
Thursday Dec 17, 2015 at 03:26 GMT
@johncmckim
rather than try to assemble the SSL configuration yourself, you'd be better off using the jetty module system to configure SSL, that way you get all the configuration setup for you (other than the keystore which your setup looks good). So you need something like:
joakime commentedon Jun 8, 2020
Saturday Dec 19, 2015 at 00:36 GMT
Thanks @gregw that was a big help.
I couldn't get the keytool command to work correctly. I found that they keystore path should be
$JETTY_BASE/etc/ketystorewhich is one step in the right direction. However, after this I found I was having issues with the password.I ended up opting to add the
--create-filescommand to your suggestion, which downloads a keystore from the jetty source for you. This probably isn't acceptable in many use cases but it is for me.RUN java -jar "$JETTY_HOME/start.jar" --add-to-startd=https --create-filesjoakime commentedon Jun 8, 2020
Saturday Dec 19, 2015 at 01:03 GMT
@johncmckim If you want to use your own passwords, it looks like you'd want to append settings for
jetty.sslContext.keyStorePassword,jetty.sslContext.trustStorePassword, andjetty.sslContext.keyManagerPasswordto$JETTY_BASE/start.d/ssl.ini.The values for these properties could be generated using
java -cp $JETTY_HOME/lib/jetty-util-$JETTY_VERSION.jar org.eclipse.jetty.util.security.Password. Be aware that this command may hang when trying to generated the crypted password if you're in a context with low entropy (e.g. in a Boot2Docker VM like I just tried to test...)These values could be specified for your build using Docker's
ARG/--build-argfunctionality if you want to avoid hard-coding your passwords.All that being said, I think in a production context you'd want to avoid generating a self-signed certificate in the
Dockerfileand instead mount in an existingkeystorecontaining your private key and certificate with--volume. In that case, I believe the passwords could be passed through to Jetty in the container as additional arguments to the mainstart.jarCMD.joakime commentedon Jun 8, 2020
Saturday Dec 19, 2015 at 01:15 GMT
@md5 I tried the jetty-util as you suggested and it hung every time so I gave up.
Mounting an existing keystore makes much more sense. I'll give that a go next week. Any examples would be appreciated.
joakime commentedon Jun 8, 2020
Saturday Dec 19, 2015 at 01:28 GMT
@johncmckim Were you trying in a VM? I tried that and it hung as well after printing out the "OBF" and "MD5" passwords. I believe the issue is that it's calling
new SecureRandom()to generate theCRYPTpassword and hanging due to a lack of available entropy.joakime commentedon Jun 8, 2020
Saturday Dec 19, 2015 at 01:31 GMT
@md5 yes. I was using docker on my windows dev machine. It would be using Virtualbox behind the scenes correct? What you describe is exactly what happened to me. I could see the OBF and MD5 passwords but it would not exit.
joakime commentedon Jun 8, 2020
Saturday Dec 19, 2015 at 06:54 GMT
I opened this issue to discuss the underlying problem around a lack of entropy causing problems for
java-based images: docker-library/openjdk#60joakime commentedon Jun 8, 2020
Thursday May 10, 2018 at 05:32 GMT
One solution could be using Conscrypt.
joakime commentedon Jun 8, 2020
Sunday Mar 17, 2019 at 10:26 GMT
Hello eveyone,
I too have the problem of adding ssl to jetty image in docker container. I just used the below commands to add my local keystore to jetty image. any help would be highly appreciated.
ADD keystore.jks $JETTY_HOME}/etc/keystore/keystore.jks
EXPOSE 8443
RUN java -jar "$JETTY_HOME/start.jar" --create-startd --add-to-start=https,ssl
joakime commentedon Jun 8, 2020
Monday Mar 18, 2019 at 23:37 GMT
@VivinrajSundararaj and what goes wrong? Does the container start? Do you get errors/logs?
joakime commentedon Jun 8, 2020
Tuesday Mar 19, 2019 at 00:02 GMT
@VivinrajSundararaj FYI I was just able to start a HTTPS connector with:
So I can see that your keystore is incorrectly named and you have a bracket problem. Try being explict and put the keystore at
/var/lib/jetty/etc/keystoreNote you don't need to add the
sslmodule as that is a transient dependency ofhttps. Nor do you need to create-startd as that is already created.joakime commentedon Jun 8, 2020
Friday May 03, 2019 at 20:06 GMT
@gregw I have certificate *.pem file and I have added the file to docker container by the docker command as below
COPY my-domain.pem /etc/ssl/certs/my-domain.pem
docker run -d -p 80:8080 -p 443:8443 -v /home/deploy/backend/ssl:/etc/ssl/certs
Can you please help to provide the steps to make the ssl working in docker container in my local machine?
joakime commentedon Jun 8, 2020
Friday Mar 20, 2020 at 09:53 GMT
I had to work on this setup for work, and since I obtained something that works, maybe someone may find it useful here.
You need:
ssl.iniandhttps.inias explained in the docsopenssl pkcs12 -export -name server -in server.pem -inkey server.key -out server-keystore.p12In the Dockerfile, I copy all those files where they belong (
/var/lib/jetty/start.d/or/var/lib/jetty/etc/) and then work with thekeytoolto:The
ssl.inithen refers to those stores.My Dockerfile is something like this:
ssl.iniinstead goes like this:Remeber that you get the obfuscated password with
java -cp ./jetty-util-9.3.6.v20151106.jar org.eclipse.jetty.util.security.Password jettyssl.Note that I needed client authentication active: disable it if your site is public.
https.iniis just:With the above setup, using:
I have, at port 8443, Jetty serving SSL with my certificate.
I hope this is helpful.
joakime commentedon Jun 8, 2020
Friday Mar 20, 2020 at 11:14 GMT
@mimatn That's really helpful, have actually been working on something similar this last week myself and figured out much the same
One other gotcha that people should be aware of is that Jetty defaults to assuming a JKS format key store, if you are using Java 9+ as the JDK in your image then the default format becomes PKCS12 and trying to start Jetty with a Keystore in that format will produce stack traces like the following:
I believe there is a Jetty setting to change the default format but since in our environment we needed to be backwards compatible to JDK 8 for the time being we added
--deststoretype jksto ourkeytool -importkeystorecommandsjoakime commentedon Jun 8, 2020
Friday Mar 20, 2020 at 15:16 GMT
@rvesse Jetty will just use
java.security.KeyStore, which supports both JKS and PKCS12 since Java 8 (along with OS specific options as well).https://docs.oracle.com/javase/8/docs/api/java/security/KeyStore.html