Securing Home Assistant

Ok so i have finally decided to make my Home Assistant install accessible remotely.

Being a paranoid guy… I have been reading up on securing my Home Assistant install here and around the web but i seam to be hitting a brick wall.

So far i have set up a DDNS with DuckDNS pointing to my Public IP. (Working fine)

My HA install runs in a docker on a Synology NAS i decided not to go the certbot/lets encrypt root and bought a SSL certificate for the DuckDNS domain.

I authenticated and installed the certificate on my Synology NAS nievely thinking id just force HTTPS and everything would now be encrypted.

This is where i hit the wall I’m confused as to weather i need to set my Synology to serve over SSL for my HA port somewhere in the Synology GUI?(Cant find this option) OR use the http component in HA to serve using the certificate OR both.

I have tried using the HTTP component but HA fails to load afterword. Not being 100% sure where the certs reside and which one listed to use doesn’t help. Browsing using SSH shows a cert folder with a whole bunch of files.

I also tried exporting the certificate using Synology and storing them in an easy accessible folder then pointing HA HTTP component to it but this had the same effect. With bot CA and Server certificate.

Id like to use the certificate i have purchased and installed on my Synology to serve my HA installation and Mosquitto instance over SSL. Is this possible or am i looking at it all wrong?

Any help would be very much appreciated.

2 Likes

No idea what are you talking about regarding certificates and stuff, sorry :blush: , but if you are that paranoid the best way is to go with the Tor Network.

Using Tor with Home Assistant

It’s pretty easy to setup actually.
Hope this helps.
Regards

Hi Jamieb,

When you bought the certificate, then you should have received two separate files.

  • the certificate itself
  • the key file helping to identify your certificate

You need both of these in a place where HA can read them. I do not think it actually matters where you put them, but HA must have read access to them. (And naturally no one else)

So what you need to do:
(You can putty / ssh for all these)

  1. Find out under what user your ha install runs. (ps axu | grep python) Find the line where it says hass* then the first column should give you the username.

  2. Copy the files somewhere on your synology. Lets say /var/opt/ha/certs

  3. Add read access to the files for the user you got from 1.

  4. In your configuration.yaml you should reference the correct path:
    ssl_certificate: /var/opt/ha/certs/your.domain.certificate.crt (or .pem if you received a pem format certificate)
    ssl_key: /var/opt/ha/certs/your.domain.keyfile.key (or .pem if you received a pem format keyfile)

then you should start hass daemon in foreground to see if everything went ok.

First time I did it I got “invalid config fot [http]: not a file or dictionary value @
data[‘http’][‘ssl_key’]” This meant that HA could not read my ssl key file. And it did not load the interface at all, because of the ssl error.

But you do not need to buy a ceritificate and key file, you can easily generate a self signed certificate in one line, and then copy the files to some place.
the command is:
openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout server.key -out server.crt

where days 365 is the validity period. If you change it to eg. 3650, then your certificate will be valid for 10 years.
server.key will be your key file, which could be named as mydomain.duckdns.org.key
server.crt will be your certificate file, which could be named as mydomain.duckdns.org.crt
for easy identification. During the generation of certificates you need to fill in some sensible information: Country code, organization, email address, common name. What you should pay attention to is that the common name should be mydomain.duckdns.org., the other values are to your liking.

Last but not least I am not familiar with the operating system on a Synology, but taken these from a standard ubuntu, hopefully your NAS has somekind of an embedded linux so all these will work.

tom

1 Like

In a lot of cases I’m just using a SSH tunnel to get access to an unsecured web interface. This doesn’t play nice with smartphones but saves me the hassle of handling TLS certificates and investing time in securing the webserver itself.

Just my 0.02 cents.

1 Like

Thanks you very much for the replies @vdarkobar @towme and @fabaff much apreciated. I started to follow toms instruction and fell at the first hurdle, convinced myself this was due to running in docker and steered of course trying to get Home Assistant to run directly on the Synology.

Long story short i’m back to running in docker now and Ill be looking more into this.

Hi,

i am still lurking in the HA forums, and have no real automation of anything relevant built and HA yet.
HOWEVER, my setup is very much similar to the OP system (HA running on docker on a synology NAS).
I am also a little paranoid with the security, and what make me fell safe is VPN.
In my case, i do have a separate PFSense box (OP, if you dont have it you should check it out), i installed OPENVPN on it. so the only way to access my home network is via VPN… feels very safe in my case.
that means, all notifications and messages that START INSIDE my network will reach my cell phone.
If someone wants to access my entire network, it is only possible using the VPN, so no need to do port forwarding or anything else…
In PFsense, i create an own network and i can manage the access from it.

I hope it helps.

Luis

The first step can be left to end. it is only important to be sure that no one else has access to the certificate files.

@luismoed
VPN access is surly safe, but the WAF / GAF is too low… :slight_smile:

This is where i’m failing i don’t seam to be able to get Home Assistant to see the certificate/key.

I’ve tried setting permissions via Synology GUI and SSH but Home Assistant still wont see them it returns the error

"invalid config fot [http]: not a file or dictionary value @ data['http']['ssl_key']"

I even tried making it view-able to everyone but still get the error. Could this be caused by running in a docker environment?

Also thanks for the reply @luismoed ill look into it.

this means there is a typo in your config line ssl_key.

HA can not find a file, nor a directory named like you typed in your config.

You should give the exact path to your ssl key file
so if your ssl key file is named: my_ssl_key.pem, and it is located in /etc/ssl/certs, then the config entry should look like:
ssl_key: /etc/ssl/certs/my_ssl_key.pem

And don’t forget the yaml identation !
http: should not be idented at all, ssl_key: on the other hand should be idented 2 spaces. And ssl_certificate should start the same place where ssl_key starts.

cheers
tom

Thanks Tom i appreciate the reply.

Still having zero luck with this! Indentation is fine and i have tried numerous directories still with no avail.

Each time home assistant runs fine in Docker but just displays nothing.

Log file still saying

homeassistant.bootstrap: Invalid config for [http]: not a file for dictionary value @ data['http']['ssl_certificate']. Got '/XXXX/SSL/server.crt' not a file for dictionary value @ data['http']['ssl_key']. Got '/XXXX/SSL/server.key'

Or to that effect depending on directory.

I can’t help but think i am overlooking something stupid here. Each time i do a full circle and come back to permissions. But as i stated earlier during testing i have made the file available to everyone.

As an alternative, have you thought about just installing the VPN server package on your Synology and then using VPN to access home assistant? That’s what I’ve been using, I have a Synology DS1815+ running my VPN to get into my network and then just connect to the VPN on my phone to access HA which is running on a Raspberry Pi.

Hi Matt,

sorry to jump in but can you please make some guide on how to setup VPN (OpenVPN if possible), or at least point to some useful and easy to implement guide on the net.

There is no useful manual here on the forum on this topic…

If you have some spare time, of course :slight_smile: .

Thanks

Hi @vdarkobar - here’s a good guide that I followed. I used LT2P, but Synology also supports OpenVPN:
https://www.synology.com/en-global/knowledgebase/DSM/help/VPNCenter/vpn_setup

The problem i have there is making it wife proof. I presume each time you want to sign into HA over the VPN you need to connect via a client on your device?

Yeah, the WifeAcceptanceFactor!

Anyway, I have fiddled a little bit with docker to try to reproduce your install environment. More I am into this docker thingy, the more I am convinced that docker itself is your problem.

First I tried this:

docker install
docker start
docker pull python
cd /
mkdir ha
docker run -d --name=“home-assistant” -v /ha:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant

Which seemed to download more than 300 MBs, but in the end it did not start home-assistant, and didn’t even create anything in my /ha directory. So I gave up on this

Next I tried:

docker run --rm -it ubuntu:14.04 /bin/bash
sudo passwd
“give root password”
su -l
apt-get update
apt-get install nano
apt-get install python3.4 python-pip
mkdir /etc/certs
cd /etc/certs
openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout server.key -out server.crt

Which resulted in openssl not found, so I tried to apt-get install openssl, but it could not locate a package named openssl. So I gave up on this as well.

So now I am stuck at the very first part: Installing HA!

I can’t really see what advantage docker gives you over running virtualbox and a virtual machine. But I have found a bounch of things that are hard to solve. Because docker seems to be using tiny linux which is a very stripped down linux flavor not supporting usual debian or centos commands or packages.
Maybe if you gave me couple of hints about reproducing your environment, I could help a little more

cheers
tom

Hi Tom,

Indeed the WifeAcceptanceFactor! I really do very much appreciate the time your taking to help.

After failing multiple times installing HA natively on my “Synology” i opted to go down the Docker route like it seams many in my situation have.

My installation looks like this.

Docker installed via package centre
HA installed via the registry image home assistant/home-assistant:latest

Note: The image in the registry only seams to pull an older version for me so i do the pull of new releases via terminal using $docker pull home assistant/home-assistant

The HA docker container called home-assistant is set-up to run on port 8123 and the i add the following to the volume in advance settings.

File/Folder - docker/home-assistant/.ssh + Mount path /root/.ssh

File/Folder - docker/home-assistant/scripts + Mount path /scripts

File/Folder - docker/home-assistant/config + Mount path /config

This container is then started and my configs are within /volume1/docker/home-assistant

I have tried placing the SSL cert and key within a directory inside this folder and even adding it within the volume but still to no avail.

Inside my config folder i have my yaml config files split into multiple files with http/ssl residing in the main configuration.yaml along with some smaller entries. I also have some custom component entries in a custom_component folder.

This docker container is running with one other container “Home-Bridge”

Running in Docker isn’t really offering any advantages except maybe the ease of access to config files and easy start/stop/failed notifications from the GUI.

A downside to running in docker aside this is it is a fairly long process to perform updates of HA.

Thanks again Jamie

Hi,

I am also using docker on synology.
in my case, it was a nightmare to use the synology docker GUI.
So I found easier to SSH into the NAS and run from CLI. also, to the best of my knowledge run via CLI is the ONLY way to have the Zwave stick to work.
what you can do after launch the container is to have a terminal session on it (go do docker, container, click on the HA container, click on details, click on terminal, click on create). selec the bash you just created and navigate (from inside the container) to the folder where the SSL files should be and check if they are really inside.

Luis

Thanks for the reply Luis, this would make sense as this is the only way my HomeBridge container will run correctly.

Out of interest could you tell me the exact command you use to run in the CLI? This would possibly also cure my problem with my EnOcean stick.

Hi,

the command i use is:

sudo docker run -d --name=“home-assistant” -p 8123:8123 -v /volume1/docker/homeassistant/config:/config -v /etc/localtime:/etc/locatime:ro --device=/dev/ttyACM0 homeassistant/home-assistant

Problem Solved!

I now seam to be able to access via https for anybody else who runs into this problem running in Docker.

I ran via the CLI and added

-v /path/tocerts:/path/tocerts:ro

to the command. Thanks you very @towme , @luismoed and everyone else who helped.

If you come across this with the same troubles feel free to PM or message in here and ill help the best i can.