There was recently a great thread discussing the safest Home Assistant setup.
I wanted to open up a follow-up thread to ask more specific questions about NGINX and Cloudfare specifically and summarize what options are available.
Questions:
- Is anybody using NGINX in their HA setup? If so, what do you add to your Home Assistant configuration to restrict incoming access to traffic only coming through NGINX? I sort of remember some server_host HTTP configuration option, but can’t seem to find it.
Can anybody provide examples of what use_x_forwarded_for and cors_allowed_origins is used for?
- A few people have mentioned using Cloudfare to mask their public IP address. Can anybody specifically share how they set this up and what the experience is there?
So far, to make Home Assistant safe there are some options. Please feel free to mention any holes or missing information here. It’d be great to summarize this information in an easy-to-understand page for new Home Assistant users.
Security Step 1: Password Protect Home Assistant
This is basic and every Home Assistant user should utilize this option. Enable this using the api_password command in the HTTP component setup.
If you don’t need to access HA outside of your local network, stop here. Home Assistant can’t be hacked if it can’t be accessed.
However, for those people that want to access HA from the internet you’ll first need to…
Open Your Home Assistant instance to the outside world
In order to access Home Assistant from the web, you’ll need to setup a port forwarding rule in your router and/or modem. Typically, you’ll forward any external port you choose (8123, 12345, etc) to the internal IP address:port that Home Assistant is running on (normally 8123).
Then, to access Home Assistant from the web, you can go to a web browser and type http://externalIPaddress:externalport and should be good to go.
If you’re on your internal network you can then either access Home Assistant by typing in yourRaspberryPiIPaddress:8123 or the externalPublicIPaddress:externalport. In some cases, the external IP address will not work on your internal network. In that case, you’ll need to explore setting up a loopback rule in your router.
Security Step 2: Setting up a DNS Service (aka DuckDNS, DNS-O-Matic, etc)
These services forward a normal URL (e.g. yourHAinstance.duckdns.org) to the public IP address of your internet service. These don’t provide any real security, but make it convenient for accessing your Home Assistant instance from the web. At that point, you can access your HA instance by going to http://yournamehere.duckdns.org:externalport
Security Step 3: SSL Encryption
This is a major security step. Using a service like LetsEncrypt a SSL certificate can be issued. These certificates allow you to encrypt traffic that is being sent over the web so people can’t snoop on it. There is lots of good documentation for setting up LetsEncrypt.
At this point, you can access your HA instance by going to https://yourNameHere.duckdns.org
Security Step 4: NGINX
The next level is to setup NGINX. NGINX acts as an SSL proxy. HassIO makes setting up NGINX super easy. First, forward external port 443 to the internal port 443 at your Pi’s IP address. NGINX forwards incoming traffic on port 443 to your HA instance which is running on port 8123.
There is a way to restrict HA access to only what is coming from NGINX, but I can’t remember that command.
NGINX is advantageous to using just SSL encryption because NGINX is a tested platform against attacks whereas Home Assistant (theoretically) could have unknown exploits?
Security Step 5: VPN
VPNs facilitate a secure connection between two devices. Can anybody share how they setup their VPN service, how that relates to what ports they are forwarding, and what their HA HTTP config settings are?
Security Step 6: CloudFare
Cloudfare can mask your public IP address. You setup your DNS server to connect to the cloudfare server and it forward traffic through to your public IP address. It isn’t clear to me if people are preserving SSL encryption through the CloudFare servers or if it terminates there. Are there any other options for protecting a public IP address?
Security Step 7: VLAN
VLAN is a virtual local area network that segregates devices into their own networks. That way if one device is compromised it doesn’t compromise the whole network. Use case - keeping all IoT devices on one VLAN and PCs/servers (containing private data) on another VLAN.
I’m very interested in know what you all think on these topics, if anything is missing, or if you have any pointers on setup. I’m happy to write up a more official page as I can get more information. Cheers!