권한이없는 LXC 컨테이너 내에 / dev / tun 장치를 만드는 방법은 무엇입니까? tun 장치

이 질문은 openvpn에 대한 lxc guest의 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.

나는 바닐라 우분투 14.04 64 비트를 호스트로 사용하고 컨테이너로 만들었습니다.

lxc-create -t download -n mylxc  -- -d ubuntu -r trusty -a amd64

/dev/tun권한이없는 LXC에서 장치를 실행하는 사람 이 있습니까?



답변

당신은 명시 적으로 CAP_MKNOD에 추가 할 필요가 능력을 당신에게 용기 .

  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.

다음을 사용하여 이것을 자동화하려고 시도 할 수도 있습니다 ( systemd컨테이너 내부에서 사용하는 경우 ).

  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.

스크립트 실행을 가리킬 수 있습니다 mknod.

docker이것을 사용 하는 것은 매우 쉽습니다. 기본적으로 컨테이너는 권한이 없습니다 .

이 예제에서는 trusty레지스트리에서 컨테이너를 가져옵니다.

sudo -r sysadm_r docker pull corbinu/docker-trusty
Pulling repository corbinu/docker-trusty
...
Status: Downloaded newer image for corbinu/docker-trusty:latest

그리고 내부에 필요한 기능을 알려주는 대화식 모드로 시작하고 있습니다.

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

반대로 :

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


답변