OK, can't deny that CF ZT can be confusing. Took me a while to get my head around it. In case it helps, I've dumped my setup notes below.
Tailscale, I think, is more a straight VPN service so you need a VPN client - I've not tried it myself though so I might be wrong.
CF ZT is several things: a web proxy service, SASE and zero-trust network. So yes, more complex, but it avoids the traditional VPN issues.
NGROK is the easiest option - as long as you follow my guide to getting a secure connection. It is also the most limited but it is enough to work with for short periods.
Getting ready
Get started Ā· Cloudflare Zero Trust docs
- Sign up for Cloudflare.
- Create a new domain or transfer control of an existing domain to CF.
CF must know about your endpoint before ZT will work. It must also be managing your domain's DNS. You don't have to transfer the domain registration to CF only make the CF DNS servers the managing ones. But CF is almost always cheaper and better anyway so best to move the registration.
- Sign up for CF Zero Trust.
Configuration and monitoring is done from the Cloudflare Zero Trust portal. Specifically the "Access" section.
Create an access group
There are several ways to include ID's into access groups. By email for example or GitHub/Google OAuth. Access groups define who can connect to services and how.
Assign 1 or more identity providers to the group.
Create a tunnel
Cloudflare Tunnel Ā· Cloudflare Zero Trust docs
- Install cloudflared
You can do this by going to the ZT portal, Access > Tunnel, create a tunnel. Name it and save, instructions are given on installing.
You need to create a tunnel anyway - however, installation is better managed via the cloudflared repository.
Local config is in ~/.cloudflared/config.yml
but probably best to use remote (CF ZT portal) config.
- Configure the tunnel from the instructions given as you create the tunnel in the portal. If installing cloudflared from the repository, you only need the
sudo cloudflared service install
part.
- Part of setting up a tunnel is adding either/both public hostnames and private networks. When setting up a public hostname, create an application as well so that you can give/protect access to that endpoint.
You can add multiple of these.
You should only create 1 tunnel for each network.
In the tunnel, you define hostnames which are publicly accessible (sub)domains with optional URL paths.
Each hostname connects to a "service". The service URN is relative to the server running cloudflared. e.g. ssh://localhost:22
or http://localhost:1880
.
Create your applications
Node-RED
Create a Public Hostname on the tunnel. The "service" is the http(s) connection on localhost, e.g. https://localhost:1880
. It cannot have a path.
To give/protect access to public hostnames,
- Create a Self-hosted application.
- The application domain should be the same as the tunnel's public hostname.
- Make sure to assign 1 or more identity providers.
- Add an access policy
SSH
Do not turn on "Protect with Access"
Create a Public Hostname on the tunnel. The "service" ssh://localhost:22
.
Create a matching Application. Turn on the option to create a browser SSH terminal. Access via browser.
Tunnelling a specific web path
If you want to create a different login or other security for a specific Node-RED path (e.g. /ui
for Dashboard), you will need to use a local proxy such as NGINX. Create an entry that turns the location (e.g. node-red path) into a new IP port.
How to Forward Request to Another Port in NGINX - Fedingo
Errors
Don't forget to check the cloudflared logs using sudo journalctl -u cloudflared.service
Already installed
home@home:~$ sudo cloudflared service install .........
2023-10-23T17:27:08Z INF Using Systemd
2023-10-23T17:27:08Z ERR error generating service template error="cloudflared service is already installed at /etc/systemd/system/cloudflared.service; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command"
cloudflared service is already installed at /etc/systemd/system/cloudflared.service; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command
home@home:~$ sudo systemctl stop cloudflared.service
home@home:~$ sudo systemctl disable cloudflared.service
home@home:~$ sudo rm /etc/systemd/system/cloudflared*
home@home:~$ sudo cloudflared service install ....
2023-10-23T18:16:41Z INF Using Systemd
2023-10-23T18:16:42Z INF Linux service for cloudflared installed successfully
home@home:~$ sudo systemctl enable cloudflared.service
home@home:~$ sudo systemctl start cloudflared.service
home@home:~$
You have to stop and disable the service
ICMP - ping_group_range
How to allow unprivileged users to use ICMP (ping) - Knowledge Base - OpenNMS Community
2023-10-23T18:27:56Z WRN The user running cloudflared process has a GID (group ID) that is not within ping_group_range. You might need to add that user to a group within that range, or instead update the range
to encompass a group the user is already in by modifying /proc/sys/net/ipv4/ping_group_range. Otherwise cloudflared will not be able to ping this network error="Group ID 1000 is not between ping group 1 to 0"
2023-10-23T18:27:56Z WRN ICMP proxy feature is disabled error="cannot create ICMPv4 proxy: Group ID 1000 is not between ping group 1 to 0 nor ICMPv6 proxy: socket: permission denied"
This command adds the user to the ping group (default is 1 0
which means that no user can do ICMP pings):
sysctl net.ipv4.ping_group_range='10000 10000'
To make permanent:
sudo nano /etc/sysctl.d/99-allow-ping.conf
Add the following line and save the file:
net.ipv4.ping_group_range=10000 10000
Load the settings without a reboot using:
sudo sysctl -p /etc/sysctl.d/99-allow-ping.conf
Probably sensible to set up a suitable group and give access to that group.
Bad gateway
- Check if Node-RED is configured to use https
If so, check if this is a local cert - if so, turn off cert checking in the tunnel public hostname config.
- Check if you have moved the default root paths
If so, make sure you are using the correct path in the url.