<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>it-security on Much Ado About IT</title><link>https://it.knightnet.org.uk/categories/it-security/</link><description>
Recent content about it-security from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/categories/it-security/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to create secure certificates</title><link>https://it.knightnet.org.uk/kb/nr-qa/https-valid-certificates/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/https-valid-certificates/</guid><pubDate>Sun, 14 Oct 2018 15:54:20 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/https-valid-certificates/</guid><description><div>Generate certificates for Node-RED that are trusted by all modern browsers. This will let you access Node-RED (and other services) over an encrypted HTTPS link.</div><div>&lt;p>&lt;strong>THIS ARTICLE IS CURRENTLY IN DRAFT - it is still being developed. Please feel free to add constructive comments and corrections below.&lt;/strong>&lt;/p>
&lt;h2 id="the-problem">The problem&lt;/h2>
&lt;p>Argh! Why is it so hard to create and manage trusted certificates for &amp;ldquo;internal&amp;rdquo; services!
While you can create your own &amp;ldquo;self-signed&amp;rdquo; certificates, all modern browsers now mark these as insecure and try
to stop you from accessing them. This is wrong. Browsers should allow access to self-signed certificates if they
point to a non-routable IP address (192.168.&lt;em>.&lt;/em> or 10.&lt;em>.&lt;/em>.* for example) or an invalid root domain such as &lt;code>*.something.local&lt;/code>.&lt;/p>
&lt;p>Also, we really probably don&amp;rsquo;t want to expose all of our internal servers to the bad, wide Internet - this is generally a really
bad idea unless you are good at securing things &lt;strong>and&lt;/strong> have the time to keep making sure they stay secure as things update.&lt;/p>
&lt;h2 id="possible-fixes">Possible fixes&lt;/h2>
&lt;p>You could manually add a new (self-signed) root certificate to all devices needing access to your internal services so that your self-signed certificates are trusted - try getting that past the rest of the family!&lt;/p>
&lt;p>The only other alternative is to use a trusted CA. Since I&amp;rsquo;m assuming you are doing this for testing or for use at home,
I also assume that you don&amp;rsquo;t want to spend lots of money. Trusted certificates usually cost - a lot! Often US$100 per year or more.&lt;/p>
&lt;p>However, there is one supplier that issues free trusted certificates. &lt;a href="https://letsencrypt.org">Let&amp;rsquo;s Encrypt&lt;/a>. This is a great service for a great price. But it comes with some overheads.&lt;/p>
&lt;h2 id="its-never-simple">It&amp;rsquo;s never simple&lt;/h2>
&lt;p>OK, so assuming we want to use Let&amp;rsquo;s Encrypt (LE), what issues do we now need to overcome?&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Firstly, we &lt;strong>have&lt;/strong> to have a publicly known domain address. You cannot issue a publicly trusted certificate to an IP address
or non-routable domain name.&lt;/p>
&lt;p>Note that certificates are generally issued to specific domain names so that &lt;code>www.thing.com&lt;/code> and &lt;code>thing.com&lt;/code> are different names. We don&amp;rsquo;t want to mess with all of that all the time, especially if we are doing lots of tests. So we can now use a &amp;ldquo;wildcard&amp;rdquo; certificate for &lt;code>*.thing.com&lt;/code>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Next, we have to have a way for the Let&amp;rsquo;s Encrypt servers to verify that our domain name is actually ours to do something with.&lt;/p>
&lt;p>By default, the LE service wants to have access back to our server in order to verify that it is ours.
This would bring us back to the issue of exposing our server to the Internet, something that we prefer not
to do unless we really have to.&lt;/p>
&lt;p>Thankfully LE now has an alternative called &lt;code>DNS-01&lt;/code>. Unfortunately, this requires our DNS (Domain Name Service) to support
a particular type of secure API. For that we can use Cloudflare or any of the other DNS services listed on the LE website.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Finally, we have to renew the certificate every 3 months since that is all that Let&amp;rsquo;s Encrypt allows us to keep a certificate for. This is a pain but it does have some security benefits.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>Let&amp;rsquo;s look at the details of how to do this.&lt;/p>
&lt;h2 id="1-get-a-domain">1. Get a domain&lt;/h2>
&lt;p>We need a domain and we need it to be one that we can, at least to some degree, control. So some of the free &amp;ldquo;dynamic DNS&amp;rdquo; services probably won&amp;rsquo;t cut it. However, we can get our very own domain for a few £/$ per year so go ahead and do that. Save yourself some pain in the next bit by using Cloudflare themselves to register your domain.&lt;/p>
&lt;p>Once we have a domain, we need to let it be managed by a DNS that supports the &lt;code>DNS-01&lt;/code> verification API. You might be lucky in that your domain registrar already supports that. In most cases, they won&amp;rsquo;t. So now you have to hand over control of the DNS settings to someone
like &lt;a href="https://cloudflare.com/">Cloudflare&lt;/a> who&amp;rsquo;s free service is plenty for what we need. Your domain registrar will tell you how to
change the name servers that control your domain. Don&amp;rsquo;t worry, your registrar remains the overall controller so renewals are not an issue.&lt;/p>
&lt;p>As we will be using a wildcard certificate, we don&amp;rsquo;t need to worry about setting up specific names at this point.&lt;/p>
&lt;p>Also, as we will be using DNS-01 verification, we don&amp;rsquo;t need to point anything at our public IP address. Use the DNS settings to point the default &amp;ldquo;A&amp;rdquo; DNS entry at a dummy IP address like &lt;code>10.10.10.10&lt;/code>. That&amp;rsquo;s fine and it means that we won&amp;rsquo;t be leaking any information about our private network.&lt;/p>
&lt;h2 id="2a-install-a-client-for-lets-encrypt">2a. Install a client for Let&amp;rsquo;s Encrypt&lt;/h2>
&lt;p>There are lots of clients for LE, see the list on their website. For this post, I&amp;rsquo;m going to use a Raspberry Pi as I have one running permanently controlling my home automation system. You could also use a NAS or any PC. Even some routers such as the ever excellent &lt;a href="https://www.ubnt.com/edgemax/edgerouter-lite/">Ubiquity EdgeRouter Lite&lt;/a> &lt;a href="https://github.com/hungnguyenm/edgemax-acme">can be used&lt;/a>.&lt;/p>
&lt;p>I am going to use a 3rd-party BASH (Linux command-line) script as this is a lot simpler than the official Python based script.&lt;/p>
&lt;p>From your Pi, follow the &lt;a href="https://github.com/Neilpang/acme.sh#1-install-online">instructions to install the script&lt;/a>. Start a remote command line using an SSH client from a convenient computer. Log in using an ID that is allowed to do administration on the Pi. Then install the script using &lt;code>curl https://get.acme.sh | sh&lt;/code>. Note that I didn&amp;rsquo;t bother to become root as I need to use the certificate with a Node.JS service that isn&amp;rsquo;t run globally as root (this is best practice, don&amp;rsquo;t run things as root as that opens up additional security issues). I also ran &lt;code>alias acme.sh=~/.acme.sh/acme.sh&lt;/code> manually rather than logging out and back in again to pick up the defined alias.&lt;/p>
&lt;h2 id="2b-get-the-cloudflare-api-details">2b. Get the Cloudflare API details&lt;/h2>
&lt;p>So, we&amp;rsquo;re ready now right? Not quite. First we need somewhere to actually run the client tool that will initially get our first certificate and that will then run periodically to renew the certificate.&lt;/p>
&lt;p>As we are using DNS-01 validation with Cloudflare, we need the API access details. Jump ahead in the &lt;code>acme.sh&lt;/code> instructions to the part on &lt;a href="https://github.com/Neilpang/acme.sh#7-automatic-dns-api-integration">DNS API integration&lt;/a> since that&amp;rsquo;s what we need in order to avoid exposing our internal servers to the Internet. We need a configuration file. The &lt;a href="https://github.com/Neilpang/acme.sh/tree/master/dnsapi#how-to-use-dns-api">instructions are in the the &lt;code>dnsapi&lt;/code> folder&lt;/a>.&lt;/p>
&lt;p>Log into your Cloudflare account, go to &amp;ldquo;My Profile&amp;rdquo; under the little person icon top-right. Pick up your verified email address then scroll down to the bottom &amp;ldquo;API Keys&amp;rdquo; &amp;amp; click on &amp;ldquo;View&amp;rdquo; against the &amp;ldquo;Global API Key&amp;rdquo;. While you are there, turn on 2-factor authentication to protect your account and services. &lt;strong>Keep this information safe! If someone gets hold of it, they can change your DNS and other settings.&lt;/strong>&lt;/p>
&lt;p>Issue the commands &lt;code>export CF_Key=&amp;quot;sdfsdfsdfljlbjkljlkjsdfoiwje&amp;quot; &amp;amp;&amp;amp; export CF_Email=&amp;quot;xxxx@sss.com&amp;quot;&lt;/code> which temporarily puts the security information into environment variables.&lt;/p>
&lt;h2 id="2c-get-our-first-certificate">2c. Get our first certificate&lt;/h2>
&lt;p>Now we are ready to try and get our first certificate. Run the following from your SSH command line:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">acme.sh --issue --dns dns_cf -d example.com -d *.example.com
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Obviously replacing the domain names with your own. The entry that starts with &lt;code>*&lt;/code> gives you a wildcard certificate so that you
can use this certificate with any sub-domain like &lt;code>www.example.com&lt;/code> or &lt;code>fred.example.com&lt;/code>.&lt;/p>
&lt;h2 id="3-certificate-renewals">3. Certificate renewals&lt;/h2>
&lt;p>As mentioned, LE certificates expire every 90 days. Thankfully, the script we just ran not only does gets us our first certificate, it &lt;a href="https://github.com/Neilpang/acme.sh#11-how-to-renew-the-certs">sets up a script to renew the certificate every 60 days&lt;/a> - giving some extra time for the occasional renewal failures. You can adjust the renewal in the configuration file if you really want to. You don&amp;rsquo;t have to worry about restarting this if your device reboots.&lt;/p>
&lt;p>Once the script has run for the first time, go ahead and &lt;a href="https://github.com/Neilpang/acme.sh#13-how-to-upgrade-acmesh">run the following so that the script itself auto-updates&lt;/a>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">acme.sh --upgrade --auto-upgrade
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="using-names-instead-of-ip-addresses">Using names instead of IP addresses&lt;/h2>
&lt;p>New we have a certificate that we can use for any service simply by referencing that service by name.&lt;/p>
&lt;p>Note, though, that you can no longer reference your services by IP address.&lt;/p>
&lt;p>For example &lt;code>pi.example.com&lt;/code> but not &lt;code>192.168.1.20&lt;/code>.&lt;/p>
&lt;p>Using an IP address will throw an error in modern browsers.&lt;/p>
&lt;p>So a slight wrinkle in our effort to get rid of browser errors since, most home servers are access via an IP address not a name. How do we fix that? We have a couple of options.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Use your router&amp;rsquo;s DHCP or DNS service to define names for local services.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Install a DNS service on a local device.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Update the &lt;code>hosts&lt;/code> file on every client device.&lt;/p>
&lt;p>This may work if you only have one or two laptops and nothing else but even then it is clunky. With mobile devices, it won&amp;rsquo;t be possible anyway.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>Both 1 and 2 will require some configuration. What we are doing is creating names that point to local IP addresses. How you do this, depends on the router or DNS server you have.&lt;/p>
&lt;p>In either case, we really want a &lt;em>fixed&lt;/em> IP address to work with so that our Pi (or other device running our services) is always at the same address. All routers should have the ability to do this so look for the &lt;code>DHCP&lt;/code> settings. You will need to know the MAC address of the device, it looks something like &lt;code>b8:27:eb:df:49:7e&lt;/code> (you may see it with upper case letters and/or without the colons). The router&amp;rsquo;s DHCP pages will have a list of active &amp;ldquo;leases&amp;rdquo; that will show that information. You use that address, which is defined by a network interface on a device, to issue a fixed IP address via the DHCP service. Make sure that your fixed addresses don&amp;rsquo;t overlap with the range defined for DHCP to issue dynamically.&lt;/p>
&lt;p>Sometimes, your DHCP server will let you define a name to go with this configuration. That&amp;rsquo;s great because you can now specify the name to include the domain that the certificate is issued to. e.g. &lt;code>pi.example.com&lt;/code>.&lt;/p>
&lt;p>The Ubiquiti EdgeRouter&amp;rsquo;s will let you define names manually using a Wizard called &amp;ldquo;&lt;a href="https://192.168.1.1/#Wizard/feature/DNS_host_names">DNS Host Names&lt;/a>&amp;rdquo;. Some other routers may give you access to the router&amp;rsquo;s &lt;code>hosts&lt;/code> file.&lt;/p>
&lt;p>If you can&amp;rsquo;t do that on your router, you will need a DNS server that will let you define names to IP addresses. That&amp;rsquo;s a bit more complex and beyond the scope of this, already rather long, blog post I&amp;rsquo;m afraid.&lt;/p>
&lt;h2 id="using-your-certificate">Using your certificate&lt;/h2>
&lt;p>Now you have the certificate and can access your servers via names instead of IP addresses so you are ready - finally - to configure the services to use the certificates.&lt;/p>
&lt;p>You can configure most TCP/IP based services to use TLS (Transport Layer Security) which is what we will mostly want our certificate for. Most people will be familiar with accessing web pages over HTTPS which is TLS applied to HTTP. But we can also use the certificate to secure communications for file transfers (FTPS or SFTP), Email (SMTPS, IMAPS, etc.).&lt;/p>
&lt;h3 id="node-red">Node-RED&lt;/h3>
&lt;p>Node-RED is a service built over NodeJS and ExpressJS. It creates a web server that we can secure using our certificate. The same certificate will also be used to help to secure websocket communications.&lt;/p>
&lt;p>Once you&amp;rsquo;ve changed the settings below, remember to access Node-RED using the server name instead of the IP address. You will need to restart the Node-RED service.&lt;/p>
&lt;h4 id="settingsjs">settings.js&lt;/h4>
&lt;p>This file is where we configure Node-RED to use HTTPS. Note that the settings are the same as those from NodeJS so you can check out any other settings in the NodeJS documentation.&lt;/p>
&lt;p>The &lt;code>settings.js&lt;/code> file is found in your &lt;code>userDir&lt;/code> folder which is generally &lt;code>~/.node-red&lt;/code> if installed according to the instructions on the Node-RED website. &lt;code>~&lt;/code> is the &amp;ldquo;home&amp;rdquo; folder for the user ID running the Node-RED service.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="p">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">module&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">exports&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">const&lt;/span> &lt;span class="nx">path&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nx">require&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;path&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">const&lt;/span> &lt;span class="nx">fs&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nx">require&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;fs&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">https&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Don&amp;#39;t forget to adjust the paths below
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="c1">// according to your installation
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">key&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="nx">fs&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">readFileSync&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">path&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">join&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;..&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s1">&amp;#39;.acme.sh&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s1">&amp;#39;&amp;lt;server_name&amp;gt;&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;&amp;lt;server_name&amp;gt;.key&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">cert&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="nx">fs&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">readFileSync&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">path&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">join&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;..&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s1">&amp;#39;.acme.sh&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s1">&amp;#39;&amp;lt;server_name&amp;gt;&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;fullchain.cer&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Where &lt;code>&amp;lt;server_name&amp;gt;&lt;/code> is something like &lt;code>pi2.example.com&lt;/code> - whatever you have defined as the name associated with the IP address.&lt;/p>
&lt;h3 id="mqtt-broker-mosquitto">MQTT broker Mosquitto&lt;/h3>
&lt;blockquote>
&lt;p>NOTE: This section is not complete as I&amp;rsquo;ve not managed to get this working as yet.&lt;/p>
&lt;/blockquote>
&lt;p>Many IoT systems make use of MQTT for publish and subscribe handling of data from devices. The more we embed IoT into our lives, the more important it is to secure the MQTT brokers. By enabling encrypted communications via TLS and then configuring user ID&amp;rsquo;s and strong passcodes between devices and the broker, we can help make things a lot more secure.&lt;/p>
&lt;p>Mosquitto is one of the most common MQTT brokers due to its small size and high performance.&lt;/p>
&lt;p>On a Linux system, Mosquitto configuration files are found in &lt;code>/etc/mosquitto&lt;/code>. Try not to edit &lt;code>/etc/mosquitto/mosquitto.conf&lt;/code>, instead add your own file to &lt;code>/etc/mosquitto/conf.d&lt;/code>. It will be loaded automatically and will not be overridden when Mosquitto is upgraded.&lt;/p>
&lt;h4 id="etcmosquittoconfdcustomconf">/etc/mosquitto/conf.d/custom.conf&lt;/h4>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="webmin">Webmin&lt;/h3>
&lt;p>Webmin is a really helpful remote administration tool for Linux servers. Being web-based means that you can use your certificate with it. Replace the default certificate by going to &lt;em>Webmin &amp;gt; Webmin Configuration &amp;gt; SSL Settings&lt;/em> (https://&amp;lt;domain_name&amp;gt;:10000/webmin/edit_ssl.cgi?xnavigation=1).&lt;/p>
&lt;p>Then change the default &lt;em>Private key file&lt;/em> path with the the one generated by the &lt;code>acme.sh&lt;/code> script (it ends with &lt;code>.key&lt;/code>). Also change the &lt;em>certificate file&lt;/em> setting to be the file &lt;code>fullchain.cer&lt;/code> in the same folder.&lt;/p>
&lt;p>Now restart Webmin from the main Webmin configuration page or issue the command &lt;code>sudo systemctl restart webmin&lt;/code>.&lt;/p>
&lt;p>No more certificate errors as long as you remember to use your server name not IP address.&lt;/p>
&lt;h3 id="web-servers">Web servers&lt;/h3>
&lt;p>There are so many posts about configuring any of the regular web servers with certificates that I&amp;rsquo;m not going to repeat them here.&lt;/p>
&lt;p>Just remember that you have all the certificate and key files that you need so you only need to make the folder available (read-only) to the user ID that runs the web server. Then to configure the appropriate files.&lt;/p>
&lt;h3 id="router-ubiquiti-edgerouter">Router (Ubiquiti EdgeRouter)&lt;/h3>
&lt;p>There is a &lt;a href="https://github.com/hungnguyenm/edgemax-acme">dedicated script for EdgeOS&lt;/a> which you may wish to use for simplicity. Otherwise, you will need to remember to securely transfer the fullchain.cer and xxx.key files to the router&amp;rsquo;s filing system each time they are updated.&lt;/p>
&lt;p>You can change to custom key and certificate files using the &amp;ldquo;Config Tree&amp;rdquo; &lt;em>service / gui&lt;/em>.&lt;/p>
&lt;h3 id="influxdb-and-telegraf">InfluxDB and Telegraf&lt;/h3>
&lt;p>InfluxDB is a timeseries database that is very efficient at recording data over time. Great for sensor data. All access is, by default, over HTTP so it is possible to configure it to use HTTPS.&lt;/p>
&lt;p>Telegraf is from the same vendor as InfluxDB. It can also be configured to talk to InfluxDB over HTTPS.&lt;/p>
&lt;h3 id="grafana">Grafana&lt;/h3>
&lt;blockquote>
&lt;p>NOTE: Grafana seems to want to be able to &lt;strong>write&lt;/strong> to something - either the folder or the cert/key files - that it shouldn&amp;rsquo;t do so currently is failing. I haven&amp;rsquo;t had time to resolve this as yet.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;code>/etc/grafana/grafana.ini&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">[server]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Protocol (http, https, socket)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">protocol = https
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># https certs &amp;amp; key file
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">cert_file = /home/pi/.acme.sh/&amp;lt;server_name&amp;gt;/fullchain.cer
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">cert_key = /home/pi/.acme.sh/&amp;lt;server_name&amp;gt;/&amp;lt;server_name&amp;gt;.key
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/it-security">it-security</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/security">security</category></item><item><title>How to secure Node-RED</title><link>https://it.knightnet.org.uk/kb/nr-qa/securing-node-red/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/securing-node-red/</guid><pubDate>Sun, 30 Sep 2018 13:48:14 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/securing-node-red/</guid><description><div>Node-RED is increasingly used in situations that require reasonable security. Up to now, however, the information required to secure it correctly has been fragmented. This article aims to give an end-to-end outline to enable anyone to secure their installation.</div><div>&lt;p>&lt;strong>THIS ARTICLE IS CURRENTLY IN DRAFT - it is still being developed. Please feel free to add constructive comments and corrections below.&lt;/strong>&lt;/p>
&lt;p>I am going to attempt to describe the various options and configurations that you will need to think
about in order to secure an instance of Node-RED. This is probably going to be a &lt;em>long&lt;/em> article!&lt;/p>
&lt;p>Please see my other articles &lt;em>&lt;a href="https://it.knightnet.org.uk/kb/nr-qa/node-red-internet/">Making Node-RED available over the Internet&lt;/a>&lt;/em> and &lt;em>&lt;a href="https://it.knightnet.org.uk/kb/nr-qa/telegram-bot/">Secure Home Automation Controls via a Telegram Bot&lt;/a>&lt;/em> for other ideas about the security of Node-RED in regard to use over the Internet and how to avoid having to worry about some of the issues dealt with here.&lt;/p>
&lt;h2 id="warning-and-disclaimer">Warning and disclaimer&lt;/h2>
&lt;p>This is my best view of securing Node-RED. I&amp;rsquo;ve not been a professional developer in a long time and
I am not a professional security analyst (I&amp;rsquo;m a IT technology and information security manager).&lt;/p>
&lt;p>So you must not assume that this article covers every issue. You must also not assume, even if you
follow every best practice, that an instance of Node-RED will be &amp;ldquo;Secure&amp;rdquo;. It may not be for many reasons.&lt;/p>
&lt;p>&lt;strong>Get your system and its infrastructure tested to destruction by professionals.&lt;/strong>&lt;/p>
&lt;p>Hopefully though, this article will at least let you see the issues and have a reasonable go at making
your instance of Node-RED a little more secure.&lt;/p>
&lt;h2 id="terminology">Terminology&lt;/h2>
&lt;p>A few words and phrases that will be used along with the least technical descriptions that I can come up with.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Term&lt;/th>
&lt;th>Meaning&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;a href="https://en.wikipedia.org/wiki/Encryption">Encryption&lt;/a>&lt;/td>
&lt;td>Changing human readable information into something that requires a special key before it can be understood.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;a href="https://en.wikipedia.org/wiki/Authentication">Authentication&lt;/a>&lt;/td>
&lt;td>Providing a secured identifier to a system to prove that the person accessing the system is who they &lt;em>claim&lt;/em> to be.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;a href="https://en.wikipedia.org/wiki/Authorization">Authorisation&lt;/a>&lt;/td>
&lt;td>Controlling what information a user of a system is allowed to see and what actions they are allowed to take.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">TLS&lt;/a>&lt;/td>
&lt;td>A defined protocol for securing connections between systems and applications. In basic use, it provides a minimum level of &lt;em>authentication&lt;/em> of a server (via a certificate chain of trust) and facilitates encrypted communications with that server.&lt;!-- raw HTML omitted -->It also has additional mechanisms that will also provide a minimum level of trust of the client application. However, this is rarely used in Internet web applications.&lt;!-- raw HTML omitted -->TLS may be used to secure many different application and system interactions, not just between a browser and a server.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP&lt;/a>(&lt;a href="https://en.wikipedia.org/wiki/HTTPS">S&lt;/a>)&lt;/td>
&lt;td>The main web protocol that lets browsers get human readable information from web servers. HTTPS is HTTP secured with TLS (used to also allow a protocol called SSL but that is deprecated as insecure). Ideally, &lt;em>every&lt;/em> connection to a server from a browser should be over HTTPS since the use of &lt;a href="https://developers.google.com/web/fundamentals/security/encrypt-in-transit/why-https">HTTP allows some pretty bad things to happen&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h1 id="the-basic-architecture-of-node-red">The basic architecture of Node-RED&lt;/h1>
&lt;p>To help us understand what needs to be secured, here is the basic technical architecture of Node-RED. From the outside in. This is only one way to view the architecture of course, I&amp;rsquo;ve tried to keep things as simple as possible.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;em>Your flows, Dashboard and other pages served by Node-RED&lt;/em>&lt;/p>
&lt;p>This is the &amp;ldquo;code&amp;rdquo; that you (or your users/administrators) have put together.&lt;/p>
&lt;p>Node-RED is a general purpose tool and so is capable of creating web pages and various other types of connections such as websockets, TCP/UDP connections and much more.&lt;/p>
&lt;p>Anything that is created at this level either must be secured by Node-RED&amp;rsquo;s settings or by your code.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;em>The Node-RED runtime API&lt;/em>&lt;/p>
&lt;p>This is the bit of magic that makes everything work. At some point, this will be independent to the administration side but at the moment (~ v0.19) it isn&amp;rsquo;t.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;em>The Node-RED Administration user interface&lt;/em>&lt;/p>
&lt;p>This is a web application (web page plus websocket connections) that lets you build your own applications using Node-RED. It uses various 3rd-party libraries to do some of the heavy lifting (D3, JQuery, etc.)&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;em>The Node-RED core and contributed nodes&lt;/em>&lt;/p>
&lt;p>Here is all of the clever custom code, generally tucked out of the way so you don&amp;rsquo;t need to worry about it.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;em>ExpressJS&lt;/em>&lt;/p>
&lt;p>ExpressJS is a library for NodeJS that does the heavy lifting of providing a web server.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;em>NodeJS&lt;/em>&lt;/p>
&lt;p>NodeJS is a collection of JavaScript and C code that lets people build application servers across different operating systems. It lets people use JavaScript (typically a browser language) to create their server applications.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;em>Operating System&lt;/em>&lt;/p>
&lt;p>Apart from the hardware, we are now at the bottom of the architecture.&lt;/p>
&lt;p>No point in securing everything else unless you have secured things at this level.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>In order to secure Node-RED, we have to pay some attention to all of these layers. Thankfully, the guys to created Node-RED have thought about many of the details and made it at least somewhat easier to provide a basic level of security.&lt;/p>
&lt;h1 id="settings-that-you-need-to-think-about">Settings that you need to think about&lt;/h1>
&lt;h2 id="other-considerations">Other considerations&lt;/h2>
&lt;h3 id="nodejs-and-package-vulnerabilities">NodeJS and package vulnerabilities&lt;/h3>
&lt;p>As Node-RED itself needs to have backwards compatibility with older versions of NodeJS, it may be forced to use packages (AKA modules or libraries) that are now out-of-date. Similarly, nodes that you rely on may not get updated as regularly as needed to stay ahead of vulnerabilities.&lt;/p>
&lt;p>NodeJS itself is very rapidly changing and unless you are updating it regularly (e.g. weekly) it may also have outstanding vulnerabilities.&lt;/p>
&lt;p>To mitigate these issues, you need to:&lt;/p>
&lt;ul>
&lt;li>Update NodeJS weekly or daily in sensitive installations. You will also want a set of regression tests - test that are run after every update - if you want users to be able to rely on rapid update cycles.&lt;/li>
&lt;li>&lt;code>npm&lt;/code> itself may have vulnerabilities and may need to be updated out of cycle from NodeJS.&lt;/li>
&lt;li>Regularly run &lt;code>npm outdated&lt;/code> and &lt;code>npm audit&lt;/code> on both the location you install Node-RED (global by default) and the location where you install contributed nodes. Update nodes regularly or consider the impact of nodes that have dependencies failing audits. Note that &lt;code>npm audit&lt;/code> is only available on newer versions of npm.&lt;/li>
&lt;/ul>
&lt;h1 id="issues-and-limitations">Issues and limitations&lt;/h1>
&lt;h2 id="specifics">Specifics&lt;/h2>
&lt;h1 id="references">References&lt;/h1>
&lt;ol>
&lt;li>&lt;a href="https://nodered.org/docs/security">Node-RED Official documentation on security&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://it.knightnet.org.uk/kb/nr-qa/node-red-internet/">Making Node-RED available over the Internet&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://it.knightnet.org.uk/kb/nr-qa/telegram-bot/">Secure Home Automation Controls via a Telegram Bot&lt;/a>&lt;/li>
&lt;li>Why should we use HTTPS?
&lt;ol>
&lt;li>&lt;a href="https://developers.google.com/web/fundamentals/security/encrypt-in-transit/why-https">Google&amp;rsquo;s take&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.cloudflare.com/learning/security/why-use-https/">Cloudflare&amp;rsquo;s take&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://https.cio.gov/everything/">The US Government&amp;rsquo;s take&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.troyhunt.com/heres-why-your-static-website-needs-https/">A leading security experts take&lt;/a> (Troy Hunt)&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ol></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/it-security">it-security</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/security">security</category></item><item><title>Presentation: Security and Governance in the Cloud</title><link>https://it.knightnet.org.uk/2016/11/cloud-security-and-governance.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2016/11/cloud-security-and-governance.html</guid><pubDate>Mon, 28 Nov 2016 12:54:25 +0000</pubDate><guid>https://it.knightnet.org.uk/2016/11/cloud-security-and-governance.html</guid><description><div/><div>&lt;p>Here is a presentation that I did recently for NHS CIO’s and CCIO’s.
It is all about how NHS England has followed a journey to cloud services and the IT Security &amp;amp; Information Governance issues we had to deal with along the way. It tries to also show other NHS organisations how they might work towards similar aims.&lt;/p>
&lt;!-- raw HTML omitted --></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/enterprise">Enterprise</category><category domain="https://it.knightnet.org.uk/categories/it-security">IT Security</category><category domain="https://it.knightnet.org.uk/categories/microsoft">Microsoft</category><category domain="https://it.knightnet.org.uk/tags/cyber-security">cyber security</category><category domain="https://it.knightnet.org.uk/tags/enterprise-architecture">Enterprise Architecture</category><category domain="https://it.knightnet.org.uk/tags/enterprise-systems">Enterprise Systems</category><category domain="https://it.knightnet.org.uk/tags/governance">Governance</category><category domain="https://it.knightnet.org.uk/tags/government">government</category><category domain="https://it.knightnet.org.uk/tags/microsoft">Microsoft</category><category domain="https://it.knightnet.org.uk/tags/nhs">nhs</category><category domain="https://it.knightnet.org.uk/tags/office-365">Office 365</category><category domain="https://it.knightnet.org.uk/tags/presentation">Presentation</category><category domain="https://it.knightnet.org.uk/tags/security">Security</category><category domain="https://it.knightnet.org.uk/tags/solutions-architecture">Solutions Architecture</category></item></channel></rss>