Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cloudflared service #545

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ If you have a spare domain name you can configure applications to be accessible
* [Booksonic](https://booksonic.org/) - The selfhosted audiobook server
* [Calibre-web](https://github.com/janeczku/calibre-web) - Provides a clean interface for browsing, reading and downloading eBooks using an existing Calibre database.
* [Cloud Commander](https://cloudcmd.io/) - A dual panel file manager with integrated web console and text editor
* [Cloudflared (Argo tunnel)](https://github.com/cloudflare/cloudflared) - Bypass Carrier Grade NAT (CGNAT) restrictions by serving your services through a direct Cloudflare connection
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs tweaking - the name has been changed to "Cloudflare Tunnel", and it'd be better to mention its primary purpose (increasing security with a private VPN tunnel into the Cloudflare network).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, I just used cloudflared to bypass CGNAT but I see how it's useful to show its other capabilities to the user

* [Cloudflare DDNS](https://hub.docker.com/r/joshuaavalon/cloudflare-ddns/) - automatically update Cloudflare with your IP address
* [CouchPotato](https://couchpota.to/) - for downloading and managing movies
* [Deluge](https://dev.deluge-torrent.org/) - A lightweight, Free Software, cross-platform BitTorrent client.
Expand Down
27 changes: 27 additions & 0 deletions docs/applications/cloudflared.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cloudflared (Argo tunnel)

Homepage: [https://github.com/cloudflare/cloudflared](https://github.com/cloudflare/cloudflared)

Cloudflare Argo tunnel: [https://blog.cloudflare.com/argo-tunnel/](https://blog.cloudflare.com/argo-tunnel/)

Cloudflare: [https://www.cloudflare.com](https://www.cloudflare.com)

This service is very useful when your NAS doesn't have a static IP and it's situated a [Carrier Grade NAT](https://en.wikipedia.org/wiki/Carrier-grade_NAT). With this approach your NAS is connected directly to the Cloudflare servers, which allow public access to your externally available applications.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAT circumvention is a useful feature but not the primary purpose


## Usage

Set `cloudflared_enabled: true` in your `inventories/<your_inventory>/nas.yml` file.

Set `cloudflared_token` to the one you grab from the Cloudflare Zero Trust Dashboard (more below).

## Specific Configuration

Create a cloudflare account if you don't have one. You will need to purchase a domain name registered with Cloudflare, or migrate an existing one on the platform.

On your cloudflare account page, navigate to the Zero Trust dashboard, and create a Tunnel in the Access/Tunnels menu.

After choosing a name for your tunnel, in the environment section choose Docker, and take note of the token in the code section below (the long string after the `--token` command): this will be your `cloudflared_token`.

In the next page (public hostname) you will need to set some values, which we will delete later: set your domain as your cloudflare hostname, Service as `HTTPS` and `localhost`, then save the changes. Edit the Catch-all-rule to be `https://localhost:443`, then delete the entry you made one step before. Your Cloudflare tunnel will now redirect all incoming requests to your Traefik service runnin on port 443, which will route them accordingly.
HitLuca marked this conversation as resolved.
Show resolved Hide resolved

Now your chosen services are exposed to the internet (the ones that have the `*_available_externally` variable set to `true`).
8 changes: 5 additions & 3 deletions nas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
tags: users

roles:

###
### Requirements
###
Expand All @@ -25,7 +24,6 @@
- docker
- skip_ansible_lint


###
### Ansible-NAS Roles
###
Expand All @@ -39,7 +37,6 @@
- ansible-nas-docker
- ansible-nas


###
### Applications
###
Expand Down Expand Up @@ -68,6 +65,11 @@
- cloudcmd
when: (cloudcmd_enabled | default(False))

- role: cloudflared
tags:
- cloudflared
when: (cloudflared_enabled | default(False))

- role: cloudflare_ddns
tags:
- cloudflare_ddns
Expand Down
4 changes: 4 additions & 0 deletions roles/cloudflared/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
cloudflared_enabled: false

cloudflared_token: ""
12 changes: 12 additions & 0 deletions roles/cloudflared/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Cloudflared Docker Container
docker_container:
name: cloudflared
image: cloudflare/cloudflared
pull: true
env:
TZ: "{{ ansible_nas_timezone }}"
restart_policy: unless-stopped
command: "tunnel --no-autoupdate run --token {{ cloudflared_token }}"
network_mode: "host"
recreate: true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to recreate the container on every run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my mistake, it's left behind from my personal setup in which I was setting watchtower labels for autoupdate, which requires recreating the container