{"id":665,"date":"2021-10-16T10:31:31","date_gmt":"2021-10-16T15:31:31","guid":{"rendered":"https:\/\/secognition.com\/?p=665"},"modified":"2022-01-02T17:46:28","modified_gmt":"2022-01-02T22:46:28","slug":"adding-tls-to-your-elastic-web-interface","status":"publish","type":"post","link":"https:\/\/secognition.com\/?p=665","title":{"rendered":"Adding TLS to your Elastic Web Interface"},"content":{"rendered":"<p>Once in a while I reset my Elasticsearch config to stay up to date on new developments and see how I can improve my setup.\u00a0 I thought to add a secure certificate to the front end of my elastic instance.\u00a0 There&#8217;s alot of documents out there but not something that brings it all together.\u00a0 This is not a config to install x-pack secure authentication and have access to certificate checking.\u00a0 This blog is strictly installing a secure certificate.<\/p>\n<p>The steps we&#8217;ll be following:<\/p>\n<ul>\n<li><strong>Setup a domain name and associate an A record<\/strong><\/li>\n<li><strong>Use LetsEncrypt to generate a new certificate<\/strong><\/li>\n<li><strong>Install the certificate in Nginx and Kibana<\/strong><\/li>\n<\/ul>\n<p>I performed these steps on a Ubuntu 20.04 server configuration running vanilla Elasticsearch and Kibana 7.15.1.\u00a0 More information on this installation can be found <a href=\"https:\/\/secognition.com\/?p=192\">here.<\/a><\/p>\n<h4>Setup a Domain (or Subdomain) for a Fully Qualified Domain Name:<\/h4>\n<p>I own a domain called secognition.com, I registered it through <a href=\"https:\/\/www.gandi.net\">https:\/\/www.gandi.net<\/a>.\u00a0 They offer many services relatively inexpensively.\u00a0 In this case, I wanted to add a subdomain to secognition.com and point the name to my new Elasticsearch server.\u00a0 I went into my domain configuration gandi.net and added <em>delphi<\/em> as an A record.\u00a0 This creates the subdomain and I pointed it to the internal IP of my new server which was 10.255.100.100.\u00a0 You will want to stay logged into your domain configuration as one more step will be required in the certificate part of the procedure.<\/p>\n<p>Small warning: Adding internal routable IPs to the internet DNS table is not recommended.\u00a0 Since I don&#8217;t have an internal DNS to point to, adding this won&#8217;t break anything.\u00a0 If ever you were to present your Elasticsearch server for use on the internet for folks to browse, you would need to change this internal IP to your new internet IP and modify your internal DNS to point to the internal IP.<\/p>\n<p>Ok so we&#8217;ve added the DNS record, saved it and can ping the fully qualified domain name.\u00a0 Next, setup LetsEncrypt.<\/p>\n<h4>LetEncrypt TLS Certificates Installation<\/h4>\n<p>The next step involves installing some additional applications on your elasticsearch server.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-666\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/installcertbot.png\" alt=\"\" width=\"679\" height=\"31\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/installcertbot.png 679w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/installcertbot-300x14.png 300w\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" \/><\/p>\n<p>The command above will install the certbot application to interact with LetsEncrypt.\u00a0 LetsEncrypt is a service from the Electronic Frontier Foundation (EFF) where they offer free encryption certificates that last for a period of 3 months.\u00a0 These certificates will need to be renewed, but the certbot can help out by automating this functionality.<\/p>\n<p>Once certbot is installed, we can proceed to generate the certificates and download them to our new server.<\/p>\n<pre><span style=\"color: #000000;\"><strong>certbot --manual certonly -d delphi.yoursever.com -m &lt;your e-mail address&gt; --preferred-challenge dns --agree-tos<\/strong><\/span><\/pre>\n<p>The command above tells LetsEncrypt the following:<\/p>\n<ul>\n<li>We want a manual creation of the certificate. (&#8211;manual)<\/li>\n<li>We only want the certificate and it&#8217;s corresponding keys. (certonly)<\/li>\n<li>-d will be the name of your new domain or subdomain<\/li>\n<li>-m Is for the e-mail address LetsEncrypt can contact you at when a renewal is coming up and for other EFF related activities.<\/li>\n<li>&#8211;preferred-challenge This is to advise LetsEncrypt that instead of validating your identity through a local webserver on the internet, you will enter a TXT entry on your DNS record to validate that you did request this certificate.<\/li>\n<li>&#8211;agree-tos is to agree to the Terms of Service.<\/li>\n<\/ul>\n<p>Once you enter the command you&#8217;ll be presented with a code to enter into your DNS records.<\/p>\n<p>Something similar to:<\/p>\n<p><code><span style=\"color: #000000;\"><strong>_acme-challenge.yourserver.com<\/strong><\/span><\/code>\u00a0 with some code after it.<\/p>\n<p>Log back into your domain DNS management screen and create a TXT type record.<\/p>\n<p>You will need to enter the _acme_challenge part as the hostname to your TXT.\u00a0 No need to add the .yourdomain.com part, this will be done automatically.<\/p>\n<p>You will then enter the random code LetsEncrypt provided into the value part.\u00a0 Save the entry and press enter to continue the process, the certbot will attempt to validate the new TXT record.\u00a0\u00a0 This may take a few minutes. be patient.<\/p>\n<p>Once the validation of the certbot is complete, the certificates will be saved in the \/etc\/letsencrypt directory.<\/p>\n<h4>Install the certificate in Nginx and Kibana<\/h4>\n<p>Almost completed.\u00a0 Now we need to configure the certificates in Nginx and Kibana.\u00a0 Thankfully, certbot can do this for us for Nginx.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-668\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2.png\" alt=\"\" width=\"595\" height=\"28\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2.png 595w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2-300x14.png 300w\" sizes=\"auto, (max-width: 595px) 100vw, 595px\" \/><\/p>\n<p>Replace delphi.yourserver.com with your own fully qualified domain name.<\/p>\n<p>You should then see the following choices.\u00a0 Since we already have the certificates downloaded, choose 1 to not renew and replace the existing certs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-669\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2-1.png\" alt=\"\" width=\"874\" height=\"139\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2-1.png 874w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2-1-300x48.png 300w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot2-1-768x122.png 768w\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-670\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot3.png\" alt=\"\" width=\"949\" height=\"180\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot3.png 949w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot3-300x57.png 300w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/certbot3-768x146.png 768w\" sizes=\"auto, (max-width: 949px) 100vw, 949px\" \/><\/p>\n<p>certbot will search for the nginx configuration file for your domain.\u00a0 The server_name entry should be the same as what you put into the certbot command.\u00a0 If found, certbot will ask if you want to\u00a0 modify the file to add the locations of the TLS certificates and give you a choice to redirect unencrypted traffic (port 80) to port 443 https. I chose 2.<\/p>\n<p>Your nginx domain config file should resemble something like this now.<\/p>\n<pre><span style=\"color: #000000;\"><strong>server {<\/strong>\r\n\r\n<strong>server_name delphi.myserver.com;<\/strong>\r\n\r\n<strong>location \/ {<\/strong>\r\n<strong>proxy_pass https:\/\/localhost:5601;<\/strong>\r\n<strong>proxy_http_version 1.1;<\/strong>\r\n<strong>proxy_set_header Upgrade $http_upgrade;<\/strong>\r\n<strong>proxy_set_header Connection 'upgrade';<\/strong>\r\n<strong>proxy_set_header Host $host;<\/strong>\r\n<strong>proxy_cache_bypass $http_upgrade;<\/strong>\r\n<strong>}<\/strong>\r\n\r\n<strong>listen 443 ssl; # managed by Certbot<\/strong>\r\n<strong>ssl_certificate \/etc\/letsencrypt\/live\/delphi.myserver.com\/fullchain.pem; # managed by Certbot<\/strong>\r\n<strong>ssl_certificate_key \/etc\/letsencrypt\/live\/delphi.myserver.com\/privkey.pem; # managed by Certbot<\/strong>\r\n<strong>include \/etc\/letsencrypt\/options-ssl-nginx.conf; # managed by Certbot<\/strong>\r\n<strong>ssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem; # managed by Certbot<\/strong>\r\n\r\n\r\n<strong>}server {<\/strong>\r\n<strong>if ($host = delphi.myserver.com) {<\/strong>\r\n<strong>return 301 https:\/\/$host$request_uri;<\/strong>\r\n<strong>} # managed by Certbot<\/strong>\r\n\r\n\r\n<strong>listen 80;<\/strong>\r\n\r\n<strong>server_name delphi.myserver.com;<\/strong>\r\n<strong>return 404; # managed by Certbot<\/strong>\r\n\r\n\r\n<strong>}<\/strong><\/span><\/pre>\n<p>Make sure to modify the domain names (delphi.myserver.com) to your own domain names and restart the nginx process.<\/p>\n<pre><span style=\"color: #000000;\"><strong>dave@delphi:~$ sudo service nginx restart<\/strong>\r\n<strong>dave@delphi:~$<\/strong><\/span><\/pre>\n<p>For Kibana, we&#8217;ll need to copy over the certificates to the \/etc\/kibana directory.\u00a0 I created a SSL directory and copied the letsencrypt certificates into the directory then changed the permissions and ownership.\u00a0 You will have to perform this step everytime the certificates are renewed.<\/p>\n<pre><span style=\"color: #000000;\"><strong>mkdir \/etc\/kibana\/ssl<\/strong>\r\n<strong>cp -pr \/etc\/letsencrypt\/live\/delphi.myserver.com \/etc\/kibana\/ssl<\/strong>\r\n<strong>chmod 750 \/etc\/kibana\/ssl\/delphi.myserver.com<\/strong>\r\n<strong>chmod 640 \/etc\/kibana\/ssl\/delphi.myserver.com\/*<\/strong>\r\n<strong>chown -R root.kibana \/etc\/kibana\/ssl\/delphi.myserver.com\/<\/strong><\/span><\/pre>\n<p>In Kibana edit your \/etc\/kibana\/kibana.yml config as follows, uncomment the server. lines and add in the directories to your certificates:<\/p>\n<pre><span style=\"color: #000000;\"><strong>server.ssl.enabled: true<\/strong>\r\n<strong>server.ssl.certificate: \/etc\/kibana\/ssl\/delphi.myserver.com\/fullchain1.pem<\/strong>\r\n<strong>server.ssl.key: \/etc\/kibana\/ssl\/delphi.myserver\/privkey1.pem<\/strong><\/span><\/pre>\n<p>Restart your kibana and elasticsearch processes to apply the new configuration<\/p>\n<pre><span style=\"color: #000000;\"><strong>dave@delphi:~$ sudo service elasticsearch restart<\/strong>\r\n<strong>[sudo] password for dave:<\/strong>\r\n<strong>dave@delphi:~$ sudo service kibana restart<\/strong>\r\n<strong>dave@delphi:~$<\/strong><\/span><\/pre>\n<p>Check the status of your processes<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-671\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elaststat.png\" alt=\"\" width=\"1073\" height=\"113\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elaststat.png 1073w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elaststat-300x32.png 300w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elaststat-1024x108.png 1024w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elaststat-768x81.png 768w\" sizes=\"auto, (max-width: 1073px) 100vw, 1073px\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-672\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/kibanastat.png\" alt=\"\" width=\"979\" height=\"86\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/kibanastat.png 979w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/kibanastat-300x26.png 300w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/kibanastat-768x67.png 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>Then attempt to browse using HTTPS to your Elasticsearch server.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-673\" src=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elasticwebhttps.png\" alt=\"\" width=\"1920\" height=\"815\" srcset=\"https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elasticwebhttps.png 1920w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elasticwebhttps-300x127.png 300w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elasticwebhttps-1024x435.png 1024w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elasticwebhttps-768x326.png 768w, https:\/\/secognition.com\/wp-content\/uploads\/2021\/10\/elasticwebhttps-1536x652.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>I hope this was informative and saved you some time &#8211; I spent approximately 2 hours figuring out which entries to add and which to remove to make this work correctly.\u00a0 If all goes well this should not take more than 30 minutes.<\/p>\n<p>Thanks for reading.\u00a0 Stay safe and let me know how things went in the comments if there are any steps I may have missed or ways to gain efficiencies in the process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once in a while I reset my Elasticsearch config to stay up to date on new developments and see how I can improve my setup.\u00a0 I thought to add a secure certificate to the front end of my elastic instance.\u00a0 There&#8217;s alot of documents out there but not something that brings it all together.\u00a0 This&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/secognition.com\/?p=665\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-665","post","type-post","status-publish","format-standard","hentry","category-security"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/secognition.com\/index.php?rest_route=\/wp\/v2\/posts\/665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/secognition.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/secognition.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/secognition.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/secognition.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=665"}],"version-history":[{"count":0,"href":"https:\/\/secognition.com\/index.php?rest_route=\/wp\/v2\/posts\/665\/revisions"}],"wp:attachment":[{"href":"https:\/\/secognition.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/secognition.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/secognition.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}