卷已加密且无法由主机访问?

我想要一个Docker容器,该容器具有无法被主机访问的存储卷。

我遵循了this guide,它使用docker-lvm-plugin插件来装入LUKS加密卷。经过对方法的一些修改,我最终做到了:

apt install lvm2
apt install xfsprogs
pvcreate /dev/sdb
vgcreate docker /dev/sdb
lvcreate -L 15G -T docker/internal
lvcreate -L 30G -T docker/volumes
mkdir -p /var/run/key
mount -t ramfs -o size=4M ramfs /var/run/key
dd if=/dev/urandom of=/var/run/key/key.bin bs=1024 count=16
apt install cryptsetup
docker volume create --driver lvm --name cryptvol --opt size=100M --opt crypt=luks --opt keyfile=/var/run/key/key.bin
docker run -d --name container -v cryptvol:/home alpine tail -f /dev/null

但是我可以这样做:

$ docker exec -it container sh -c 'echo hello > /home/hello.txt'
$ # hello.txt is readable inside container
$ docker exec -it container -c 'cat /home/hello.txt'
hello
$ # hello.txt ALSO readable outside container
$ cat /var/lib/docker-lvm-plugin/cryptvol/hello.txt
hello

似乎加密卷的内容对主机可见。

是否可以在主机无法访问的Docker容器中拥有加密卷?

lryup 回答:卷已加密且无法由主机访问?

否。

Docker不是VM工具,它运行具有隔离(名称空间)和资源限制(cgroup)的应用程序。在同一内核上运行的主机进程没有以这些限制运行,因此可以查看容器的内容。即使从主机上受某种方式的限制,主机上的root(以及docker组中的任何用户)都可以输入容器的名称空间。

本文链接:https://www.f2er.com/3150685.html

大家都在问