Jenkins (standalone) SSL + Let's Encrypt

Jenkins

In this tutorial, I will show how to use Let's Encrypt free SSL with a standalone Jenkins in Ubuntu 16.04.

 

Installation of certbot and jenkins are not included in this tutorial.

 

Generate Certificates

Run the command to generate the certificate and key files.

sudo certbot certonly --standalone --preferred-challenges http -d example.com

You should get this response:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2019-02-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Just in case you got this response:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Cleaning up challenges
Problem binding to port 80: Could not bind to IPv4 or IPv6.

You need to stop your web server and try again.

 

Convert the certificate to JKS keystore

Go to your certificate folder

cd /etc/letsencrypt/live/example.com

And execute this command to convert the certificate to PKCS12 file first

openssl pkcs12 -inkey privkey.pem -in fullchain.pem -export -out keys.pkcs12

If you are renewing the certificates, make sure to delete the existing /var/lib/jenkins/jenkins.jks file first.

Then convert to JKS file

keytool -importkeystore -srckeystore keys.pkcs12 -srcstoretype pkcs12 -destkeystore /var/lib/jenkins/jenkins.jks

Enter export and import passwords and answer "yes" if asked to overwrite an existing alias

Enter Export Password:
Verifying - Enter Export Password:
root@example:/etc/letsencrypt/live/example.com# keytool -importkeystore -srckeystore keys.pkcs12 -srcstoretype pkcs12 -destkeystore /var/lib/jenkins/jenkins.jks
Importing keystore keys.pkcs12 to /var/lib/jenkins/jenkins.jks...
Enter destination keystore password:  
Enter source keystore password:  
Existing entry alias 1 exists, overwrite? [no]:  yes
Entry for alias 1 successfully imported.
Import command completed:  1 entries successfully imported, 0 entries failed or cancelled

 

Set Jenkins configuration to use the SSL

Edit the Jenkins config file

vim /etc/default/jenkins

Look for JENKINS_ARGS and update the value to this:

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=-1 --httpsPort=8443 --httpsKeyStore=/var/lib/jenkins/jenkins.jks --httpsKeyStorePassword=PASSWORD_SET_ON_CONVERT_TO_JKS"

Restart jenkins

sudo service jenkins restart

 

Comments

person

Stephen (not verified)

3 months ago Permalink

I think you replaced the wrong command for converting to key.pkcs12. The step under "Convert to JKS file" does not produce a JKS file.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.