Skip to content

Commit

Permalink
pass the TUN device instead of creating it in the container, fix cmj2…
Browse files Browse the repository at this point in the history
  • Loading branch information
cmj2002 committed Dec 8, 2024
1 parent 94bb0b0 commit 06239fc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ services:
image: caomingjun/warp
container_name: warp
restart: always
devices:
- /dev/net/tun:/dev/net/tun
ports:
- "1080:1080"
environment:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
image: caomingjun/warp
container_name: warp
restart: always
devices:
- /dev/net/tun:/dev/net/tun
ports:
- "1080:1080"
environment:
Expand Down
2 changes: 2 additions & 0 deletions docs/proxy-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ services:
image: caomingjun/warp
container_name: warp
restart: always
devices:
- /dev/net/tun:/dev/net/tun
ports:
- "1080:1080"
environment:
Expand Down
45 changes: 45 additions & 0 deletions docs/tun-not-permitted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Solution to open tun operation not permitted

## Problem

On Nov 21, 2024, [containerd](https://github.com/containerd/containerd) released version [1.7.24](https://github.com/containerd/containerd/releases/tag/v1.7.24) which updated [runc](https://github.com/opencontainers/runc) to 1.2.2 and introduced [a breaking change that remove tun/tap from the default device rules](https://github.com/opencontainers/runc/pull/3468).

**This cause `/dev/net/tun` cannot be accessed by the container if the device is not explicitly passed, even if the container has created `/dev/net/tun` by itself.**

Thanks [@hugoghx](https://github.com/hugoghx) for [reporting this issue](https://github.com/cmj2002/warp-docker/issues/41).

## Solution

To solve this issue, you need to pass the `/dev/net/tun` device to the container. We also recommend you to update the image to the latest version to avoid any other issues.

To pass the device to the container, you need to add `devices` to service level. For example:

```yaml
version: "3"

services:
warp:
image: caomingjun/warp
container_name: warp
restart: always
# ===== Add the following 2 lines =====
devices:
- /dev/net/tun:/dev/net/tun
# ================ End ================
ports:
- "1080:1080"
environment:
- WARP_SLEEP=2
# - WARP_LICENSE_KEY= # optional
cap_add:
# Docker already have them, these are for podman users
- MKNOD
- AUDIT_WRITE
# additional required cap for warp, both for podman and docker
- NET_ADMIN
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
- net.ipv4.conf.all.src_valid_mark=1
volumes:
- ./data:/var/lib/cloudflare-warp
```
2 changes: 2 additions & 0 deletions docs/warp-connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
image: caomingjun/warp
container_name: warp
restart: always
devices:
- /dev/net/tun:/dev/net/tun
ports:
- "1080:1080"
environment:
Expand Down
7 changes: 3 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
# exit when any command fails
set -e

# create a tun device if not exist to ensure compatibility with Podman
# check if /dev/net/tun is available
if [ ! -e /dev/net/tun ]; then
sudo mkdir -p /dev/net
sudo mknod /dev/net/tun c 10 200
sudo chmod 600 /dev/net/tun
echo "CRITIC: /dev/net/tun not pass, check https://github.com/cmj2002/warp-docker/blob/main/docs/tun-not-permitted.md for more information"
exit 1
fi

# start dbus
Expand Down

0 comments on commit 06239fc

Please sign in to comment.