Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created October 16, 2024 18:53
Show Gist options
  • Select an option

  • Save danielrosehill/a370062d40d31173be4cb8cc9bd17ee9 to your computer and use it in GitHub Desktop.

Select an option

Save danielrosehill/a370062d40d31173be4cb8cc9bd17ee9 to your computer and use it in GitHub Desktop.
Connecting to Home Assistant OS via a Cloudflare Tunnel & A Network Gateway

Connecting to Home Assistant OS via a Cloudflare Tunnel

This can be a little tricky to get right, but here's one config that works (at least now, 10/24).

1: Set up your tunnel to your network gateway

This Gist assumes you're using something like a network gateway device rather than attempting to tunnel directly to HAOS or the VM running it.

Firstly, set up the tunnel to that device and verify that the tunnel is operational.

Next, two modifications to the configuration.yaml are needed:

  1. Set your gateway as a trusted_proxy (using its LAN IP)
  2. Set the base URL

Worked Example

Say I want to provision an access point to my Home Assistant and I have a domain called danielshome.com

Step 1:

I might set up a mini PC as my network gateway. So I'll open up a tunnel to danielshome.com and then I'll set up an Access rule so that only I (or authenticated people) can access it.

Step 2:

Let's say my Home Assistant is running on 192.0.0.1:8123, I'll then create a hostname record at (say):

homeassistant.danielshome.com and have the local connection (service) setting as:

192.0.0.1:8123

Step 3:

If my network gateway (for the sake of this example) has a fixed local IP of 192.0.0.2, I would add

cors_allowed_origins:

- https://homeassistant.danielshome.com

And I would add the gateway as a trusted proxy:

  use_x_forwarded_for: true
  trusted_proxies:
  - 192.0.0.2
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment