Você precisa adicionar explicitamente o CAP_MKNOD recurso ao seu container .
lxc.cap.keep Specify the capability to be kept in the container. All other capabilities will be dropped. When a special value of "none" is encountered, lxc will clear any keep capabilities specified up to this point. A value of "none" alone can be used to drop all capabilities.
Você também pode tentar automatizar isso (se acontecer de você usar systemd
dentro do container) usando:
lxc.hook.autodev A hook to be run in the container's namespace after mounting has been done and after any mount hooks have run, but before the pivot_root, if lxc.autodev == 1. The purpose of this hook is to assist in populating the /dev directory of the container when using the autodev option for systemd based containers. The container's /dev directory is relative to the ${LXC_ROOTFS_MOUNT} environment variable available when the hook is run.
que pode apontar para um script executando mknod
.
Usando docker
isso é muito fácil de realizar. Por padrão, os contêineres são unprivileged .
Neste exemplo, estou puxando um contêiner trusty
do registro:
sudo -r sysadm_r docker pull corbinu/docker-trusty
Pulling repository corbinu/docker-trusty
...
Status: Downloaded newer image for corbinu/docker-trusty:latest
E eu estou começando no modo interativo informando sobre a capacidade que eu preciso dentro:
sudo -r sysadm_r docker run --cap-drop ALL --cap-add MKNOD \
-i -t corbinu/docker-trusty bash
root@46bbb43095ec:/# ls /dev/
console fd/ full fuse kcore mqueue/ null ptmx pts/ random shm/ stderr stdin stdout tty urandom zero
root@46bbb43095ec:/# mkdir /dev/net
root@46bbb43095ec:/# mknod /dev/net/tun c 10 200
root@46bbb43095ec:/# ls -lrt /dev/net/tun
crw-r--r--. 1 root root 10, 200 Apr 6 16:52 /dev/net/tun
Em oposição a:
sudo -r sysadm_r docker run --cap-drop ALL \
-i -t corbinu/docker-trusty bash
root@9a4cdc75a5ec:/# mkdir /dev/net
root@9a4cdc75a5ec:/# mknod /dev/net/tun c 10 200
mknod: ‘/dev/net/tun’: Operation not permitted