Skip to content

Commit 1abaf12

Browse files
committed
Added Optional Routing
1 parent f26593b commit 1abaf12

3 files changed

Lines changed: 48 additions & 24 deletions

File tree

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ This image packages the Linux `cloudflare-warp` client for running a Cloudflare
55
It is designed for:
66

77
- headless `warp-cli` connector enrollment
8-
- bidirectional mesh traffic
9-
- subnet routing through the container
10-
- routed return traffic by enabling forwarding and disabling reverse path filtering
8+
- plain node connectivity by default
9+
- optional subnet routing through the container
10+
- optional routed return traffic by enabling forwarding and disabling reverse path filtering
1111
- network troubleshooting with `ping` and `traceroute`
1212

1313
## What is included
@@ -18,9 +18,9 @@ It is designed for:
1818
- an entrypoint that:
1919
- starts `warp-svc`
2020
- streams `warp-svc` logs into `docker logs`
21-
- enables IPv4 forwarding
22-
- disables `rp_filter` to avoid dropping asymmetric return traffic
23-
- accepts forwarded traffic in the `FORWARD` chain
21+
- optionally enables IPv4 forwarding for subnet routing
22+
- optionally disables `rp_filter` to avoid dropping asymmetric return traffic
23+
- optionally accepts forwarded traffic in the `FORWARD` chain
2424
- optionally runs `warp-cli connector new <TOKEN>`
2525
- optionally runs `warp-cli connect`
2626
- periodically logs `warp-cli status` changes
@@ -45,7 +45,15 @@ Set your connector token first:
4545
export WARP_CONNECTOR_TOKEN='your-cloudflare-mesh-token'
4646
```
4747

48-
If you are using `network_mode: host`, apply the routing sysctls on the Docker host before starting the container:
48+
By default the container behaves like a WARP Mesh node and does not enable subnet forwarding.
49+
50+
To turn on subnet routing and reverse-path handling, set:
51+
52+
```bash
53+
export WARP_ENABLE_SUBNET_ROUTING=true
54+
```
55+
56+
If subnet routing is enabled and you are using `network_mode: host`, apply the routing sysctls on the Docker host before starting the container:
4957

5058
```bash
5159
sudo sysctl -w net.ipv4.ip_forward=1
@@ -66,6 +74,8 @@ If you want to manage forwarding policy outside the container, set:
6674
export WARP_MANAGE_FORWARD_CHAIN=false
6775
```
6876

77+
`WARP_MANAGE_FORWARD_CHAIN` only matters when `WARP_ENABLE_SUBNET_ROUTING=true`.
78+
6979
The container also supports periodic status logging. The default interval is 15 seconds, and only changed status snapshots are emitted:
7080

7181
```bash
@@ -96,7 +106,9 @@ docker exec -it cf-warp-cli traceroute 1.1.1.1
96106

97107
## Routing notes
98108

99-
For subnet routing to work end to end, the surrounding network must send the target CIDR back through this container's host. The container enables forwarding and avoids reverse path filtering drops, but upstream route tables still need to point the advertised subnet toward the Docker host running this container.
109+
When `WARP_ENABLE_SUBNET_ROUTING=false`, this container just joins Mesh as a node and does not try to route third-party subnet traffic.
110+
111+
When `WARP_ENABLE_SUBNET_ROUTING=true`, the surrounding network must send the target CIDR back through this container's host. The container enables forwarding and avoids reverse path filtering drops, but upstream route tables still need to point the advertised subnet toward the Docker host running this container.
100112

101113
If this is deployed in a cloud VPC, also make sure the instance or VM is allowed to forward traffic and that any source/destination checking is disabled where required by the platform.
102114

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
environment:
1313
WARP_CONNECTOR_TOKEN: "${WARP_CONNECTOR_TOKEN}"
1414
WARP_AUTOCONNECT: "true"
15+
WARP_ENABLE_SUBNET_ROUTING: "${WARP_ENABLE_SUBNET_ROUTING:-false}"
1516
WARP_MANAGE_FORWARD_CHAIN: "true"
1617
WARP_STATUS_INTERVAL_SECONDS: "${WARP_STATUS_INTERVAL_SECONDS:-15}"
1718
volumes:

docker/entrypoint.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ log() {
66
printf '[%s] %s\n' "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" "$*"
77
}
88

9+
is_true() {
10+
case "${1,,}" in
11+
1|true|yes|on) return 0 ;;
12+
*) return 1 ;;
13+
esac
14+
}
15+
916
log_command_output() {
1017
local prefix="$1"
1118

@@ -42,6 +49,11 @@ set_sysctl_if_present() {
4249
}
4350

4451
configure_forwarding() {
52+
if ! is_true "${WARP_ENABLE_SUBNET_ROUTING:-false}"; then
53+
log "WARP_ENABLE_SUBNET_ROUTING is disabled; skipping forwarding and reverse-path configuration"
54+
return 0
55+
fi
56+
4557
set_sysctl_if_present net.ipv4.ip_forward 1
4658
set_sysctl_if_present net.ipv4.conf.all.forwarding 1
4759

@@ -51,15 +63,17 @@ configure_forwarding() {
5163
}
5264

5365
configure_firewall() {
66+
if ! is_true "${WARP_ENABLE_SUBNET_ROUTING:-false}"; then
67+
log "WARP_ENABLE_SUBNET_ROUTING is disabled; leaving iptables FORWARD chain unchanged"
68+
return 0
69+
fi
70+
5471
local manage_forward_chain="${WARP_MANAGE_FORWARD_CHAIN:-true}"
5572

56-
case "${manage_forward_chain,,}" in
57-
1|true|yes|on) ;;
58-
*)
59-
log "WARP_MANAGE_FORWARD_CHAIN is disabled; leaving iptables FORWARD chain unchanged"
60-
return 0
61-
;;
62-
esac
73+
if ! is_true "${manage_forward_chain}"; then
74+
log "WARP_MANAGE_FORWARD_CHAIN is disabled; leaving iptables FORWARD chain unchanged"
75+
return 0
76+
fi
6377

6478
if command -v iptables >/dev/null 2>&1; then
6579
iptables -C FORWARD -j ACCEPT >/dev/null 2>&1 || iptables -A FORWARD -j ACCEPT
@@ -158,15 +172,12 @@ enroll_connector_if_requested() {
158172
connect_if_requested() {
159173
local autoconnect="${WARP_AUTOCONNECT:-true}"
160174

161-
case "${autoconnect,,}" in
162-
1|true|yes|on)
163-
log "Connecting WARP"
164-
warp-cli --accept-tos connect 2>&1 | log_command_output "[warp-cli] "
165-
;;
166-
*)
167-
log "WARP_AUTOCONNECT is disabled; leaving the client disconnected"
168-
;;
169-
esac
175+
if is_true "${autoconnect}"; then
176+
log "Connecting WARP"
177+
warp-cli --accept-tos connect 2>&1 | log_command_output "[warp-cli] "
178+
else
179+
log "WARP_AUTOCONNECT is disabled; leaving the client disconnected"
180+
fi
170181
}
171182

172183
status_snapshot() {

0 commit comments

Comments
 (0)