Skip to main content

Cloudflare - Converting to a managed tunnel

In this guide, we are going to convert from the 'old' style, login locally & configure locally cloudflare tunnel (formally called an Argo tunnel), to the new style, managed though the Cloudflare Zero Trust Dashboard tunnel.

Why?

Whilst im a fan of 'things as code', the ability to move the management of a tunnel to Cloudflare, instead of local code, allows the usage of Terraform to manage directly on the platform, thus improving our ability to manage the tunnel through code, with an actual IaC tool.
Additionally, the legacy method made popular by a few youtubers, whilst perfectly valid, is dependant on files on your disk to be present/set in the right way/permissions to function.
The new method is entirely stateless, and can be re-setup & configured remotely.

Step 1 - Create new tunnel on Cloudflare Zero Trust Dashboard

Login to your Cloudflare Zero Trust Dashboard

Once logged in, on the left, expand access, then click "Tunnels"
X

On the top right, click "Create a tunnel"
X

Give your tunnel a name, in this example, i am calling it unraid-tunnel, as its a tunnel, that i will be running on Unraid.
Then click Save tunnel at the bottom.
X

On this screen, under the Choose your environment section at the top, click Docker.
The area below, underneath Install and run a connector will change to show a docker run command.
Keep this page up, as will need the information from it. X

Step 2 - Create tunnel container in Unraid

Login to your local unraid GUI, and click Docker.
X

At the bottom, click ADD CONTAINER
X

On this screen, we are going to create a custom container for the Cloudflare Tunnel.

Begin entering these settings on the main configuration page.

SettingWhat to enter
Namecloudflare_tunnel_2
Repositorycloudflare/cloudflared:latest
Network TypeYour local docker network - in my case, 'proxynet'

Now, click the toggle in the top right that says BASIC VIEW, and toggle it to ADVANCED VIEW
X

On this screen, we need to add some additional variables -

SettingWhat to enter
Docker Hub URLhttps://hub.docker.com/r/cloudflare/cloudflared/
Icon URLhttps://raw.githubusercontent.com/aeleos/cloudflared/main/cloudflare-icon.png
Extra Parameterssee below

For Extra Parameters, we need to take the output of the cloudflare wizard, everything past "tunnel", but removing '--no-run-autoupdate'.

note

Running containers on the latest rolling releases vs sticking with a known working release is a popular difference of opinion for both self-hosters and big organisations alike.
For this deployment, i am recommending 'latest' as the release tag as a home lab is not critical in nature. If something breaks due to a bad update, it can be diagnosed.
You should however change this based on your personal viewpoint & preference.

Example -

tunnel run --token ABC1234567890

Once information has been inputted, click APPLY at the bottom of the page.
X

You should see 'the command finished successfully!' at the bottom of the deploy page if it was successfully downloaded/deployed.
Click DONE

If you now switch back to the tab for Cloudflare, you should see your new tunnel with the status Connected.
X
Click Next at the bottom of the page to continue.

The next page is where we configure what we are routing and to where - X

To pass everything that the tunnel receives to a proxy container (recommended), enter the following details -

SettingWhat to enterExample
Subdomainmy-tunneln/a
DomainYour domain namedomain.com
PathLeave blankn/a
Service TypeHTTPSn/a
Service URLcontainername:portNginxProxyManager:4443

X

Click Save unraid-container tunnel

Done

At this point, you should point your tunnel CNAME's from wherever they are pointed (usually at your root @), to the new tunnel (my-tunnel.domain.com). This will allow you to quickly cut back to the original tunnel without taking it down should there be issues by just changing the CNAME target to @ again (or whatever it was before).

Getting the tunnel dns record to use

Tunnel DNS records are in the format of tunnel-id.cfargotunnel.com
You can get the tunnel ID from the tunnel status page, under the name.
X