Skip to content

Commit 272e8eb

Browse files
authored
Merge pull request #991 from linuxserver/universal-cloudflared-cloud-managed
Add support for remotely managed tunnel
2 parents 973e037 + 60bd8e5 commit 272e8eb

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# syntax=docker/dockerfile:1
22

33
# Build container
4-
FROM ghcr.io/linuxserver/baseimage-alpine:3.19 AS buildstage
4+
FROM ghcr.io/linuxserver/baseimage-alpine:3.21 AS buildstage
55

66
ARG MOD_VERSION
77

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,48 @@ If no additional parameters are supplied this mod adds [`cloudflared`](https://g
66

77
If all additional parameters are supplied this docker mod will also create/configure/route/enable a cloudflare tunnel via `cloudflared` and the cloudflare v4 API.
88

9-
## Usage
9+
This mod supports both locally managed and remotely managed tunnels.
10+
11+
## Remotely Managed Tunnel Usage
12+
13+
First create a tunnel on Cloudflare's [Zero Trust Dashboard](https://one.dash.cloudflare.com/) and note the tunnel's token.
14+
15+
Here an example snippet to help you get started using this docker mod.
16+
17+
### docker-compose ([recommended](https://docs.linuxserver.io/general/docker-compose))
18+
19+
```yaml
20+
swag:
21+
image: lscr.io/linuxserver/nginx
22+
container_name: nginx
23+
environment:
24+
PUID: 1000
25+
PGID: 1000
26+
TZ: Europe/London
27+
DOCKER_MODS: linuxserver/mods:universal-cloudflared
28+
CF_REMOTE_MANAGE_TOKEN: cbvcnbvcjyrtd5erxjhgvkjhbvmhnfchgfchgjv
29+
volumes:
30+
- /path/to/appdata/config:/config
31+
restart: unless-stopped
32+
```
33+
34+
# Parameters
35+
36+
Container images/mods are configured using parameters passed at runtime (such as those above).
37+
38+
| Parameter | Function | Notes |
39+
| :----: | --- | --- |
40+
| `DOCKER_MODS` | Enable this docker mod with `linuxserver/mods:universal-cloudflared` | If adding multiple mods, enter them in an array separated by `\|`, such as `DOCKER_MODS: linuxserver/mods:universal-cloudflared\|linuxserver/mods:universal-mod2` |
41+
42+
### Cloudflare tunnel parameters
43+
44+
| Parameter | Function | Notes |
45+
| :----: | --- | --- |
46+
| `CF_REMOTE_MANAGE_TOKEN` | Existing Cloudflare tunnel's token | |
47+
48+
Once set up, all tunnel config will be handled through the [Zero Trust Dashboard](https://one.dash.cloudflare.com/)
49+
50+
## Locally Managed Tunnel Usage
1051

1152
Here an example snippet to help you get started using this docker mod.
1253

root/etc/s6-overlay/s6-rc.d/init-mod-universal-cloudflared-setup/run

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ echo "**** Cloudflared setup script init... ****"
44

55
echo "**** Checking cloudflared setup script requirements... ****"
66
ARCH="$(command arch)"
7-
if [ "${ARCH}" = "x86_64" ]; then
7+
if [ "${ARCH}" = "x86_64" ]; then
88
ARCH="amd64"
9-
elif [ "${ARCH}" = "aarch64" ]; then
10-
ARCH="arm64"
11-
elif [ "${ARCH}" = "armv7l" ]; then
12-
echo "**** The universal cloudflared mod no longer supports arm32v7/armhf per https://info.linuxserver.io/issues/2023-07-01-armhf/ ****"
13-
exit 0
9+
elif [ "${ARCH}" = "aarch64" ]; then
10+
ARCH="arm64"
1411
else
1512
echo "**** Unsupported Linux architecture ${ARCH} found, exiting... ****"
1613
exit 1
@@ -40,7 +37,9 @@ fi
4037
cloudflared -v
4138

4239
echo "**** Checking for cloudflare tunnel parameters... ****"
43-
if [[ ${#CF_ZONE_ID} -gt 0 ]] && [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUNNEL_NAME} -gt 0 ]] && [[ ${#CF_TUNNEL_CONFIG} -gt 0 ]]; then
40+
if [[ -n "${CF_REMOTE_MANAGE_TOKEN}" ]]; then
41+
echo "**** CF_REMOTE_MANAGE_TOKEN is set, cloudflared will attempt to connect to existing tunnel ****"
42+
elif [[ ${#CF_ZONE_ID} -gt 0 ]] && [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUNNEL_NAME} -gt 0 ]] && [[ ${#CF_TUNNEL_CONFIG} -gt 0 ]]; then
4443
if [[ ${#CF_TUNNEL_PASSWORD} -lt 32 ]]; then
4544
echo "**** Cloudflare tunnel password must be at least 32 characters long, exiting... ****"
4645
exit 1

root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cloudflared/run

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/usr/bin/with-contenv bash
22

3-
if [[ $(uname -m) = "armv7l" ]]; then
4-
echo "**** The universal cloudflared mod no longer supports arm32v7/armhf per https://info.linuxserver.io/issues/2023-07-01-armhf/ ****"
5-
sleep infinity
6-
fi
7-
8-
if [[ ${#CF_ZONE_ID} -gt 0 ]] && [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUNNEL_NAME} -gt 0 ]] && [[ ${#CF_TUNNEL_CONFIG} -gt 0 ]] && [[ ${#CF_TUNNEL_PASSWORD} -gt 31 ]]; then
3+
if [[ -n "${CF_REMOTE_MANAGE_TOKEN}" ]]; then
4+
exec s6-setuidgid abc cloudflared tunnel --no-autoupdate run --token ${CF_REMOTE_MANAGE_TOKEN}
5+
elif [[ ${#CF_ZONE_ID} -gt 0 ]] && [[ ${#CF_ACCOUNT_ID} -gt 0 ]] && [[ ${#CF_API_TOKEN} -gt 0 ]] && [[ ${#CF_TUNNEL_NAME} -gt 0 ]] && [[ ${#CF_TUNNEL_CONFIG} -gt 0 ]] && [[ ${#CF_TUNNEL_PASSWORD} -gt 31 ]]; then
96
exec s6-setuidgid abc cloudflared tunnel --no-autoupdate --config /etc/cloudflared/config.yml run
107
else
118
echo "**** Issues with cloudflared settings, sleeping ****"

0 commit comments

Comments
 (0)