Skip to content

Commit

Permalink
first hardcoded version
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz75 committed Aug 31, 2023
1 parent fa33176 commit db04bda
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 530 deletions.
73 changes: 0 additions & 73 deletions cloudflared/.README.j2

This file was deleted.

224 changes: 7 additions & 217 deletions cloudflared/DOCS.md
Original file line number Diff line number Diff line change
@@ -1,222 +1,22 @@
# Home Assistant Add-on: AIS Cloudflared
# AIS Cloudflared

Cloudflared connects your Home Assistant Instance via a secure tunnel to a domain
or subdomain at Cloudflare. This allows you to expose your Home Assistant
instance and other services to the Internet without opening ports on your router.
Additionally, you can utilize Cloudflare Zero Trust to further secure your
connection.
Cloudflared connects your Home Assistant Instance via a secure tunnel to a
subdomain ``dom-xxx.paczka.pro`` at Cloudflare.
This allows you to expose your Home Assistant
instance to the Internet without opening ports on your router.

## Disclaimer

Please make sure you comply with the
[Cloudflare Self-Serve Subscription Agreement][cloudflare-sssa] when using this
add-on.

## Initial setup

### Prerequisites

1. A domain name (e.g. example.com) using Cloudflare for DNS. If you don't have
one see [Domain name and Cloudflare set up](#domain-name-and-cloudflare-set-up).
1. Decide between a local tunnel (managed by the add-on) or a remote tunnel
(managed in Cloudflare's interface). [Learn more][addon-remote-or-local].
1. This add-on should be [installed][addon-installation] but not started yet.

After completing the prerequisites, proceed below based on the type of tunnel you
chose.

### Local tunnel add-on setup (recommended)
### Local tunnel add-on setup

In the following steps a Cloudflare Tunnel will be automatically created by the
add-on to expose your Home Assistant instance.

If you only want to expose other services, you can leave `external_hostname`
empty and set `additional_hosts` as [described below](#configuration).

1. Configure the `http` integration in your Home Assistant config as
[described below](#configurationyaml)
1. Set `external_hostname` add-on option to the domain/subdomain
you want to use for remote access e.g. `ha.example.com`
1. Start the add-on (this will overwrite any existing DNS entries matching
`external_hostname` or `additional_hosts`)
1. Paste the URL from the add-on logs in a new tab to authenticate with Cloudflare
1. Access your Home Assistant via the remote URL without port e.g.
`https://ha.example.com/`

A tunnel should now be listed in your Cloudflare Teams dashboard.
Please review the additional configuration options below.

### Remote tunnel add-on setup (advanced)

In the following steps you will manually create a Cloudflare Tunnel in the Zero
Trust Dashboard and provide the token to the add-on.

1. Configure the `http` integration in to your Home Assistant config as
[described below](#configurationyaml)
1. Create a Cloudflare Tunnel in the Cloudflare Teams dashboard following
[this how-to][addon-remote-tunnel]
1. Set `tunnel_token` add-on option to your [tunnel token][create-remote-managed-tunnel]
(all other configuration will be ignored)
1. Start the add-on, check the logs to confirm everything went as
expected
1. Access your Home Assistant via the remote URL without port e.g.
`https://ha.example.com/`

Your tunnel should now be associated with the Cloudflared add-on. Any
configuration changes should be made in the Cloudflare Teams dashboard.

## Configuration

**These configuration options only apply to the local tunnel setup**. More
advanced config can be achieved using the remote tunnel setup.

- [`external_hostname`](#option-external_hostname)
- [`additional_hosts`](#option-additional_hosts)
- [`tunnel_name`](#option-tunnel_name)
- [`catch_all_service`](#option-catch_all_service)
- [`nginx_proxy_manager`](#option-nginx_proxy_manager)
- [`log_level`](#option-log_level)

### Overview: Add-on configuration

**Note**: _Remember to restart the add-on when the configuration is changed._

Example add-on configuration:

```yaml
external_hostname: ha.example.com
additional_hosts:
- hostname: router.example.com
service: http://192.168.1.1
- hostname: website.example.com
service: http://192.168.1.3:8080
```
**Note**: _This is just an example, don't copy and paste it! Create your own!_
### Option: `external_hostname`

Set the `external_hostname` option to the domain name or subdomain that you want
to use to access Home Assistant on.

This is optional, `additional_hosts` can be used instead to only expose other
services.

**Note**: _The tunnel name needs to be unique in your Cloudflare account._

```yaml
external_hostname: ha.example.com
```

### Option: `additional_hosts`

You can use the internal reverse proxy of Cloudflare Tunnel to define additional
hosts next to Home Assistant. That way, you can use the tunnel to also access
other systems like a diskstation, router or anything else.

Like the `external_hostname` option used for Home Assistant, DNS entries will
be automatically created at Cloudflare.

Add the (optional) `disableChunkedEncoding` option to a hostname, to disable
chunked transfer encoding. This is useful if you are running a WSGI server,
like Proxmox for example. Visit [Cloudflare Docs][disablechunkedencoding] for
further information.

Please find below an example entry for three additional hosts:

```yaml
additional_hosts:
- hostname: router.example.com
service: http://192.168.1.1
- hostname: diskstation.example.com
service: https://192.168.1.2:5001
- hostname: website.example.com
service: http://192.168.1.3:8080
disableChunkedEncoding: true
```

**Note**: _If you delete a hostname from the list, it will not be served
anymore. Nevertheless, you should also manually delete the DNS entry from
Cloudflare since it can not be deleted by the add-on._

### Option: `tunnel_name`

The `tunnel_name` option allows changing the tunnel name to something other
than the default of `homeassistant`.

**Note**: _The tunnel name needs to be unique in your Cloudflare account._

```yaml
tunnel_name: myHomeAssistant
```

### Option: `post_quantum`

If you want Cloudflared to use post-quantum cryptography for the tunnel,
set this flag.

**Note**: _When `post_quantum` is set, cloudflared restricts itself to QUIC
transport for the tunnel connection. This might lead to problems for some users.
Also, it will only allow post-quantum hybrid key exchanges and not fall back to
a non post-quantum connection._

```yaml
post_quantum: true
```

### Option: `catch_all_service`

If you want to forward all requests from any hostnames not defined in the
`external_hostname` or the `additional_hosts`, you can use this option and
define a URL to forward to. For example, this can be used for reverse proxies.

**Note**: _If you want to use the HA add-on [Nginx Proxy Manager][nginx_proxy_manager]
as reverse proxy, you should set the flag `nginx_proxy_manager` ([see
below](#option-nginx_proxy_manager)) and not use this option._

```yaml
catch_all_service: http://192.168.1.100
```

**Note**: _This will still route your defined `external_hostname`to Home Assistant
as well as any potential `additional_hosts` to where you defined in the config.
Any other incoming traffic will be routed to the defined service._

In order to route hostnames through the tunnel, you have to create individual
CNAME records in Cloudflare for all of them, pointing to your `external_hostname`
or directly to the tunnel URL that you can get from the CNAME entry of
`external_hostname`.

Alternatively you can add a [wildcard DNS record](https://blog.cloudflare.com/wildcard-proxy-for-everyone/)
in Cloudflare by adding a CNAME record with `*` as name.

### Option: `nginx_proxy_manager`

If you want to use Cloudflare Tunnel with the add-on
[Nginx Proxy Manager][nginx_proxy_manager], you can do so by setting this option.
It will automatically set the catch_all_service to the internal URL of Nginx Proxy
Manager. You do not have to add the option `catch_all_service` to your config (if
you add it anyways, it will be ignored).

```yaml
nginx_proxy_manager: true
```

**Note**: _As with `catch_all_service`, this will still route your defined
`external_hostname`to Home Assistant as well as any potential `additional_hosts`
to where you defined in the config. Any other incoming traffic will be routed
to Nginx Proxy Manager._

In order to route hostnames through the tunnel, you have to create individual
CNAME records in Cloudflare for all of them, pointing to your `external_hostname`
or directly to the tunnel URL that you can get from the CNAME entry of
`external_hostname`.

Alternatively you can add a [wildcard DNS record](https://blog.cloudflare.com/wildcard-proxy-for-everyone/)
in Cloudflare by adding a CNAME record with `*` as name.

Finally, you have to set-up your proxy hosts in Nginx Proxy Manager and forward
them to wherever you like.

### Option: `log_level`

Expand Down Expand Up @@ -266,20 +66,12 @@ Remember to restart Home Assistant when the configuration is changed.
If you need assistance changing the config, please follow the
[Advanced Configuration Tutorial][advancedconfiguration].

## Add-On Wiki

For more advance [How-Tos][how-tos] and a [Troubleshooting Section](troubleshooting),
please visit the [Add-On Wiki on GitHub][addon-wiki].

## Authors & contributors

The original setup of this repository is by [Tobias Brenner][tobias].

## License

MIT License

Copyright (c) 2023 Tobias Brenner
Copyright (c) 2023 AIS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -304,10 +96,8 @@ SOFTWARE.
[advancedconfiguration]: https://www.home-assistant.io/getting-started/configuration/
[cloudflare-sssa]: https://www.cloudflare.com/en-gb/terms/
[how-tos]: https://github.com/brenner-tobias/addon-cloudflared/wiki/How-tos
[nginx_proxy_manager]: https://github.com/hassio-addons/addon-nginx-proxy-manager
[tobias]: https://github.com/brenner-tobias
[troubleshooting]: https://github.com/brenner-tobias/addon-cloudflared/wiki/Troubleshooting
[disablechunkedencoding]: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/configuration/configuration-file/ingress#disablechunkedencoding
[create-remote-managed-tunnel]: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/#1-create-a-tunnel
[addon-remote-tunnel]: https://github.com/brenner-tobias/addon-cloudflared/wiki/How-tos#how-to-configure-remote-tunnels
[addon-remote-or-local]: https://github.com/brenner-tobias/addon-cloudflared/wiki/How-tos#local-vs-remote-managed-tunnels
2 changes: 1 addition & 1 deletion cloudflared/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LABEL \
maintainer="AIS <https://github.com/sviete/>" \
org.opencontainers.image.title="${BUILD_NAME}" \
org.opencontainers.image.description="${BUILD_DESCRIPTION}" \
org.opencontainers.image.vendor="Tobias Brenner <https://github.com/brenner-tobias/>" \
org.opencontainers.image.vendor="AIS <https://github.com/sviete/>" \
org.opencontainers.image.authors="AIS <https://github.com/sviete/>" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://github.com/${BUILD_REPOSITORY}" \
Expand Down
20 changes: 4 additions & 16 deletions cloudflared/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
name: Cloudflared
name: AIS Cloudflared
version: dev
slug: cloudflared
description: "Use a AIS Cloudflare Tunnel to remotely
connect to Home Assistant without opening any ports"
description: "Use a AIS Cloudflare Tunnel to remotely connect to Home Assistant without opening any ports"
url: "https://github.com/sviete/ha-addon-cloudflared/"
codenotary: [email protected]
init: false
Expand All @@ -20,17 +19,6 @@ map:
- share:rw
- config:rw
options:
external_hostname: ""
additional_hosts: []
log_level: "info"
schema:
external_hostname: str?
additional_hosts:
- hostname: str
service: str
disableChunkedEncoding: bool?
tunnel_name: str?
tunnel_token: str?
post_quantum: bool?
catch_all_service: str?
nginx_proxy_manager: bool?
log_level: list(trace|debug|info|notice|warning|error|fatal)?
log_level: list(trace|debug|info|notice|warning|error|fatal)
2 changes: 1 addition & 1 deletion cloudflared/rootfs/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# ==============================================================================
# Home Assistant Add-on: Cloudflared
# Home Assistant Add-on: AIS Cloudflared
#
# Container build of Cloudflared
# ==============================================================================
Expand Down
Loading

0 comments on commit db04bda

Please sign in to comment.