Note: This info is really only useful if you have your own domain. It would not work directly with a dynamic DNS service such as duckdns although your domain can point to a duckdns address using a CNAME, this is what I do.
I recently found out that Cloudflare offer a free package for personal use and so I’ve been playing around with what it can offer my Home Assistant setup.
Even if you’ve never heard of Cloudflare you probably access content using it everyday, for example, this forum is served through Cloudflare. This is by no means my area of expertise (if I even have one) but from what I understand Cloudflare is a service that sits between a web server and it’s clients with it’s main aims to protect against DDoS attacks and improve performance (by caching content using a CDN network).
What really interested me was that they also offer free SSL certification. Given they sit in the middle of communications there actually needs to be 2 SSL certificates to cover each leg of the communication, in the Home Assistant context this would be something like Web Browser (Serving Front End) >> Cloudflare and Cloudflare >> Home Assistant.
For their personal-use offering the Web Browser >> Cloudflare part is covered by a certificate that is shared by a number of Cloudflare users. This certificate is automatically renewed by Cloudflare and so you don’t need to worry about keeping it renewed.
For the Cloudflare >> Home Assistant part Cloudflare can provide what they call an origin certificate. From what I understand, this is a certificate that is signed by Cloudflare, it wouldn’t be validated by your browser but it doesn’t need to be as it is only Cloudflare themselves that see it. Your browser would only see the shared certificate above which is accepted by most browsers. The really good bit here is that this origin certificate can be valid for 15 years!
Between Cloudflare automatcially renewing the shared certificate and the 15 year expiry of the origin certificate you pretty much don’t need to worry about renewing SSL certificates .
The process of issuing an origin certificate is also very easy. You don’t even need to create a Certificate Sigining Request (CSR), they can do this for you. You just ask for a certificate and then download the .pem and .key files which can be used in Home Assistant:
http:
ssl_certificate: /home/your_user/.homeassistant/certificate.pem
ssl_key: /home/your_user/.homeassistant/privkey.pem
The process of setting up Cloudflare as well is very simple and only takes a few minutes.
It’s worth noting that Cloudflare have a number of ways in which SSL can be configured, the setup I am describing here can be used with the Full SSL (Strict) model.
I’m still playing around with Cloudflare and I’m interested to see if the caching adversely affects Home Assistant in any way (particularly when I’m making changes).
One good part I have found is that it makes it very easy to auto forward HTTP to HTTPS. This means that I can type www.<mydomain>.com in my browser and it automatically uses HTTPS (I don’t need to specify it).
One caveat I will mention is that Cloudflare only proxies HTTP and HTTPS using a limited set of ports. This means that you will need to have you Home Assistant exposed on one of these ports and you won’t be able to use other services (such as SSH) using the address you protect with Cloudflare. There are however a number of ways around this e.g.
- Skip out Cloudflare by directly using the external IP address or duckdns address of your Home Assistant instance.
- Create another sub-domain that is not routed through Cloudflare e.g. ssh.<yourdomain>.com.
Hopefully this is useful to someone.