这个问题类似于Openvpn 的在 lxc 来宾中没有 tun 设备。LXC 已经发展,最近推出了无特权的 LXC 容器,它提供了另一层防止越狱的安全性。
我需要在一个非特权容器中创建一个 OpenVPN 服务器。我不知道如何让容器创建一个私有的 tun 网络设备。
我确实附加lxc.cgroup.devices.allow = c 10:200 rwm
到~/.local/share/lxc/mylxc/config
.
启动容器后,mknod /dev/net/tun c 10 200
返回mknod: '/dev/net/tun': Operation not permitted
容器内部。
我使用 vanilla Ubuntu 14.04 64bit 作为主机和一个容器
lxc-create -t download -n mylxc -- -d ubuntu -r trusty -a amd64
Run Code Online (Sandbox Code Playgroud)
有没有人设法让/dev/tun
设备在非特权 LXC 下运行?
\n\n\nRun Code Online (Sandbox Code Playgroud)\nlxc.cap.keep\n Specify the capability to be kept in the container. All other\n capabilities will be dropped. When a special value of "none"\n is encountered, lxc will clear any keep capabilities specified\n up to this point. A value of "none" alone can be used to drop\n all capabilities.\n
您还可以尝试使用以下方法自动执行此操作(如果您碰巧systemd
在容器内使用):
\n\n\nRun Code Online (Sandbox Code Playgroud)\nlxc.hook.autodev\n A hook to be run in the container\'s namespace after mounting\n has been done and after any mount hooks have run, but before\n the pivot_root, if lxc.autodev == 1. The purpose of this hook\n is to assist in populating the /dev directory of the container\n when using the autodev option for systemd based containers.\n The container\'s /dev directory is relative to the\n ${LXC_ROOTFS_MOUNT} environment variable available when the\n hook is run.\n
它可以指向正在运行的脚本mknod
。
使用docker
这个非常容易实现。默认情况下,容器是无特权的。
在此示例中,我trusty
从注册表中提取一个容器:
sudo -r sysadm_r docker pull corbinu/docker-trusty\nPulling repository corbinu/docker-trusty\n...\nStatus: Downloaded newer image for corbinu/docker-trusty:latest\n
Run Code Online (Sandbox Code Playgroud)\n\n我以交互模式启动它,告知我需要的内部功能:
\n\nsudo -r sysadm_r docker run --cap-drop ALL --cap-add MKNOD \\\n -i -t corbinu/docker-trusty bash\nroot@46bbb43095ec:/# ls /dev/\nconsole fd/ full fuse kcore mqueue/ null ptmx pts/ random shm/ stderr stdin stdout tty urandom zero\nroot@46bbb43095ec:/# mkdir /dev/net\nroot@46bbb43095ec:/# mknod /dev/net/tun c 10 200\nroot@46bbb43095ec:/# ls -lrt /dev/net/tun\ncrw-r--r--. 1 root root 10, 200 Apr 6 16:52 /dev/net/tun\n
Run Code Online (Sandbox Code Playgroud)\n\n相对于:
\n\nsudo -r sysadm_r docker run --cap-drop ALL \\\n -i -t corbinu/docker-trusty bash\nroot@9a4cdc75a5ec:/# mkdir /dev/net\nroot@9a4cdc75a5ec:/# mknod /dev/net/tun c 10 200\nmknod: \xe2\x80\x98/dev/net/tun\xe2\x80\x99: Operation not permitted\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
10696 次 |
最近记录: |