{"id":914,"date":"2020-04-09T07:21:17","date_gmt":"2020-04-09T07:21:17","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=914"},"modified":"2020-04-09T07:21:17","modified_gmt":"2020-04-09T07:21:17","slug":"configure-ssl-jenkins","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=914","title":{"rendered":"How to Configure SSL on Jenkins Server &#8211; Step by Step Guide"},"content":{"rendered":"<p>It is very important to secure Jenkins by enabling SSL which runs in a project environment. This article walks you through the step-by-step guide for configuring SSL on a Jenkins server.<\/p>\n<p>Following are the steps involved in configuring SSL on the Jenkins server.<\/p>\n<ol>\n<li>Obtain SSL certificates<\/li>\n<li>Convert SSL keys to PKCS12 format<\/li>\n<li>Convert PKCS12 to JKS format<\/li>\n<li>Add JKS to Jenkins path<\/li>\n<li>Configure Jenkins startup to use the JKS file.<\/li>\n<li>Validate Jenkins SSL<\/li>\n<\/ol>\n<p>Let&#8217;s get started with the setup<\/p>\n<h3 id=\"step-1-obtain-domain-ssl-certificates\">Step 1: Obtain Domain &amp; SSL Certificates<\/h3>\n<p>You should have a valid domain pointing to Jenkins server IP to configure SSL. The domain can be internal or external based on your organization&#8217;s infrastructure.<\/p>\n<p>SSL certificate can be obtained using the following methods.<\/p>\n<ol>\n<li>In most cases, you will be having Jenkins in a private environment with an internal DNS and you can obtain the internal SSL certificates from the respective organizations.<\/li>\n<li>You can also create self-signed SSL certificates using OpenSSL. Follow <a href=\"https:\/\/devopscube.com\/create-self-signed-certificates-openssl\/\" rel=\"noreferrer noopener\">create self-signed certificates using OpenSSL<\/a><\/li>\n<li>Also, you can use services as <a href=\"https:\/\/letsencrypt.org\/?ref=devopscube.com\" rel=\"noreferrer noopener\">Letsencrypt<\/a> for valid SSL certificates. But these certificates have to be renewed every three months.<\/li>\n<\/ol>\n<h3 id=\"step-2-convert-ssl-keys-to-pkcs12-format\">Step 2: Convert SSL keys to PKCS12 format<\/h3>\n<blockquote><p><strong>Note:<\/strong> If you already have the certificate in<code> .p12<\/code> or<code> .pfx<\/code> format, you don&#8217;t have to do this conversion.<\/p><\/blockquote>\n<p>The command given below converts SSL certs to intermediate PKCS12 format named <code>jenkins.p12<\/code>. Make sure you have the following certs with you before executing the command.<\/p>\n<ol>\n<li>ca.crt<\/li>\n<li>server.key<\/li>\n<li>server.crt<\/li>\n<\/ol>\n<p>Also,<\/p>\n<ol>\n<li>Replace <code>jenkins.devopscube.com<\/code> in the command with your own alias name<\/li>\n<li>Replace <code>your-strong-password<\/code> with a strong password.<\/li>\n<\/ol>\n<pre><code>openssl pkcs12 -export -out jenkins.p12 \\\n-passout 'pass:your-strong-password' -inkey server.key \\\n-in server.crt -certfile ca.crt -name jenkins.devopscube.com<\/code><\/pre>\n<h3 id=\"step-3-convert-pkcs12-to-jks-format\">Step 3: Convert PKCS12 to JKS format<\/h3>\n<p>Use the following keytool command to convert<code> jenkins.p12<\/code> file to JKS format.<\/p>\n<p>Replace the following with your own values.<\/p>\n<ol>\n<li><code>-srcstorepass<\/code>  &#8211; Password used in Step 3<\/li>\n<li><code>-deststorepass<\/code> &#8211; Replace with a strong password.<\/li>\n<li><code>-srcalias <\/code>&#8211; alias name used in step 2<\/li>\n<li><code>-destalias<\/code> &#8211; Replace with a destination alias name.<\/li>\n<\/ol>\n<pre><code>keytool -importkeystore -srckeystore jenkins.p12 \\\n-srcstorepass 'your-secret-password' -srcstoretype PKCS12 \\\n-srcalias jenkins.devopscube.com -deststoretype JKS \\\n-destkeystore jenkins.jks -deststorepass 'your-secret-password' \\\n-destalias jenkins.devopscube.com<\/code><\/pre>\n<p>You should see a file named <code>jenkins.jks<\/code> in you current location.<\/p>\n<h3 id=\"step-4-add-jks-to-jenkins-path\">Step 4: Add JKS to Jenkins path<\/h3>\n<p><code>jenkins.jks<\/code> file should be saved in a specific location where Jenkins can access it.<\/p>\n<p>Let&#8217;s create a folder and move the <code>jenkins.jks<\/code> key to that location.<\/p>\n<pre><code>mkdir -p \/etc\/jenkins\ncp jenkins.jks \/etc\/jenkins\/<\/code><\/pre>\n<p>Change the permissions of the keys and folder.<\/p>\n<pre><code>chown -R jenkins: \/etc\/jenkins\nchmod 700 \/etc\/jenkins\nchmod 600 \/etc\/jenkins\/jenkins.jks<\/code><\/pre>\n<h3 id=\"step-5-modify-jenkins-configuration-for-ssl\">Step 5: Modify Jenkins Configuration for SSL<\/h3>\n<p>All the key Jenkins startup configurations are present in <code>\/etc\/sysconfig\/jenkins<\/code> file. All the SSL-based configurations go into this file.<\/p>\n<p>Open the file<\/p>\n<pre><code>sudo vi \/etc\/sysconfig\/jenkins<\/code><\/pre>\n<p>Find and replace the values in the file as shown below.<\/p>\n<blockquote><p><strong>Note:<\/strong> Replace <code>your-keystore-password <\/code>with the Keystore password, you set in step 3. Also you can use either 443 or 8443 for ports.<\/p><\/blockquote>\n<pre><code>JENKINS_PORT=\"-1\"\nJENKINS_HTTPS_PORT=\"8443\"\nJENKINS_HTTPS_KEYSTORE=\"\/etc\/jenkins\/jenkins.jks\"\nJENKINS_HTTPS_KEYSTORE_PASSWORD=\"&lt;your-keystore-password&gt;\"\nJENKINS_HTTPS_LISTEN_ADDRESS=\"0.0.0.0\"<\/code><\/pre>\n<p>Save the configuration and restart Jenkins.<\/p>\n<pre><code>sudo systemctl restart jenkins<\/code><\/pre>\n<p>Check Jenkins status.<\/p>\n<pre><code>sudo systemctl status jenkins<\/code><\/pre>\n<h3 id=\"step-6-validate-ssl\">Step 6: Validate SSL<\/h3>\n<p>Now you should be able to access Jenkins over HTTPS with port 8443<\/p>\n<pre><code>https:\/\/&lt;jenkins-dns\/ip&gt;:8443<\/code><\/pre>\n<p>You can also use curl to verify SSL<\/p>\n<pre><code>curl -k https:\/\/&lt;jenkins-dns\/ip&gt;:8443<\/code><\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this <a href=\"https:\/\/devopscube.com\/jenkins-2-tutorials-getting-started-guide\/\" rel=\"noreferrer noopener\">Jenkins tutorial<\/a>, you have learned how to run Jenkins on HTTPS.<\/p>\n<p>Next, you can check out the following blogs on the Jenkins agent setup.<\/p>\n<ol>\n<li><a href=\"https:\/\/devopscube.com\/setup-slaves-on-jenkins-2\/\" rel=\"noreferrer noopener\">Jenkins agent setup<\/a><\/li>\n<li><a href=\"https:\/\/devopscube.com\/docker-containers-as-build-slaves-jenkins\/\" rel=\"noreferrer noopener\">Jenkins Docker based agent setup<\/a><\/li>\n<li><a href=\"https:\/\/devopscube.com\/jenkins-build-agents-kubernetes\/\" rel=\"noreferrer noopener\">Setup Kubernetes as Jenkins agent<\/a><\/li>\n<\/ol>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/configure-ssl-jenkins\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Configure SSL on Jenkins Server &#8211; Step by Step Guide \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/configure-ssl-jenkins\/<\/p>\n","protected":false},"author":1,"featured_media":915,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-914","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=914"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/914\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/915"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}