Browse code

rootless: optional support for lxc-user-nic SUID binary

lxc-user-nic can eliminate slirp overhead but needs /etc/lxc/lxc-usernet to be configured for the current user.

To use lxc-user-nic, $DOCKERD_ROOTLESS_ROOTLESSKIT_NET=lxc-user-nic also needs to be set.

This commit also bumps up RootlessKit from v0.3.0 to v0.4.0:
https://github.com/rootless-containers/rootlesskit/compare/70e0502f328bc5ffb14692a7ea41abb77196043b...e92d5e772ee7e103aecf380c5874a40c52876ff0

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>

Akihiro Suda authored on 2019/04/19 17:54:29
Showing 3 changed files
... ...
@@ -9,7 +9,9 @@
9 9
 # External dependencies:
10 10
 # * newuidmap and newgidmap needs to be installed.
11 11
 # * /etc/subuid and /etc/subgid needs to be configured for the current user.
12
-# * Either slirp4netns (v0.3+) or VPNKit needs to be installed.
12
+# * Either one of slirp4netns (v0.3+), VPNKit, lxc-user-nic needs to be installed.
13
+#   slirp4netns is used by default if installed. Otherwise fallsback to VPNKit.
14
+#   The default value can be overridden with $DOCKERD_ROOTLESS_ROOTLESSKIT_NET=(slirp4netns|vpnkit|lxc-user-nic)
13 15
 #
14 16
 # See the documentation for the further information.
15 17
 
... ...
@@ -35,24 +37,32 @@ if [ -z $rootlesskit ]; then
35 35
 	exit 1
36 36
 fi
37 37
 
38
-net=""
39
-mtu=""
40
-if which slirp4netns >/dev/null 2>&1; then
41
-	if slirp4netns --help | grep -- --disable-host-loopback; then
42
-		net=slirp4netns
43
-		mtu=65520
44
-	else
45
-		echo "slirp4netns does not support --disable-host-loopback. Falling back to VPNKit."
46
-	fi
47
-fi
38
+: "${DOCKERD_ROOTLESS_ROOTLESSKIT_NET:=}"
39
+: "${DOCKERD_ROOTLESS_ROOTLESSKIT_MTU:=}"
40
+net=$DOCKERD_ROOTLESS_ROOTLESSKIT_NET
41
+mtu=$DOCKERD_ROOTLESS_ROOTLESSKIT_MTU
48 42
 if [ -z $net ]; then
49
-	if which vpnkit >/dev/null 2>&1; then
50
-		net=vpnkit
51
-		mtu=1500
52
-	else
53
-		echo "Either slirp4netns (v0.3+) or vpnkit needs to be installed"
54
-		exit 1
43
+	if which slirp4netns >/dev/null 2>&1; then
44
+		if slirp4netns --help | grep -- --disable-host-loopback; then
45
+			net=slirp4netns
46
+			if [ -z $mtu ]; then
47
+				mtu=65520
48
+			fi
49
+		else
50
+			echo "slirp4netns does not support --disable-host-loopback. Falling back to VPNKit."
51
+		fi
55 52
 	fi
53
+	if [ -z $net ]; then
54
+		if which vpnkit >/dev/null 2>&1; then
55
+			net=vpnkit
56
+		else
57
+			echo "Either slirp4netns (v0.3+) or vpnkit needs to be installed"
58
+			exit 1
59
+		fi
60
+	fi
61
+fi
62
+if [ -z $mtu ]; then
63
+	mtu=1500
56 64
 fi
57 65
 
58 66
 if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then
... ...
@@ -66,7 +76,8 @@ if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then
66 66
 	#         (by either systemd-networkd or NetworkManager)
67 67
 	# * /run: copy-up is required so that we can create /run/docker (hardcoded for plugins) in our namespace
68 68
 	$rootlesskit \
69
-		--net=$net --mtu=$mtu --disable-host-loopback --port-driver=builtin \
69
+		--net=$net --mtu=$mtu \
70
+		--disable-host-loopback --port-driver=builtin \
70 71
 		--copy-up=/etc --copy-up=/run \
71 72
 		$DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS \
72 73
 		$0 $@
... ...
@@ -20,7 +20,6 @@ $ grep ^$(whoami): /etc/subgid
20 20
 penguin:231072:65536
21 21
 ```
22 22
 
23
-* Either [slirp4netns](https://github.com/rootless-containers/slirp4netns) (v0.3+) or [VPNKit](https://github.com/moby/vpnkit) needs to be installed. slirp4netns is preferred for the best performance.
24 23
 
25 24
 ### Distribution-specific hint
26 25
 
... ...
@@ -82,3 +81,12 @@ To route ping packets, you need to set up `net.ipv4.ping_group_range` properly a
82 82
 ```console
83 83
 $ sudo sh -c "echo 0   2147483647  > /proc/sys/net/ipv4/ping_group_range"
84 84
 ```
85
+
86
+### Changing network stack
87
+
88
+`dockerd-rootless.sh` uses [slirp4netns](https://github.com/rootless-containers/slirp4netns) (if installed) or [VPNKit](https://github.com/moby/vpnkit) as the network stack by default.
89
+These network stacks run in userspace and might have performance overhead. See [RootlessKit documentation](https://github.com/rootless-containers/rootlesskit/tree/v0.4.0#network-drivers) for further information.
90
+
91
+Optionally, you can use `lxc-user-nic` instead for the best performance.
92
+To use `lxc-user-nic`, you need to edit [`/etc/lxc/lxc-usernet`](https://github.com/rootless-containers/rootlesskit/tree/v0.4.0#--netlxc-user-nic-experimental) and set `$DOCKERD_ROOTLESS_ROOTLESSKIT_NET=lxc-user-nic`.
93
+
... ...
@@ -1,7 +1,7 @@
1 1
 #!/bin/sh
2 2
 
3
-# v0.3.0
4
-ROOTLESSKIT_COMMIT=70e0502f328bc5ffb14692a7ea41abb77196043b
3
+# v0.4.0
4
+ROOTLESSKIT_COMMIT=e92d5e772ee7e103aecf380c5874a40c52876ff0
5 5
 
6 6
 install_rootlesskit() {
7 7
 	case "$1" in