gpt4 book ai didi

linux - Alpine Linux 3.7 上的 Docker 容器 : Strange pid 1 not visible within the container's pid namespace

转载 作者:太空狗 更新时间:2023-10-29 11:41:18 24 4
gpt4 key购买 nike

我目前正在跟踪我们在 Alpine Linux 3.7 主机上使用 dockerd 17.10.0-ce 时遇到的奇怪问题。似乎对于该主机上的所有容器,作为 Docker 镜像的入口点/命令启动的进程树在容器本身内是不可见的。相比之下,在 Ubuntu 主机上,同一镜像的进程树将显示为 PID 1。

这是一个例子。

使用明确的已知入口点/命令运行容器:

% docker run -d --name testcontainer --rm busybox /bin/sh -c 'sleep 1000000'

验证 dockerd 正确地看到进程:

% docker top testcontainer
PID USER TIME COMMAND
6729 root 0:00 /bin/sh -c sleep 1000000
6750 root 0:00 sleep 1000000

现在,在该容器内启动一个 shell 并检查进程列表:

% docker exec -t -i testcontainer /bin/sh
/ # ps -ef
PID USER TIME COMMAND
6 root 0:00 /bin/sh
12 root 0:00 ps -ef

可以观察到,我们的入口点命令(/bin/sh -c 'sleep 1000000')在容器本身内是不可见的。即使运行 top 也会产生相同的结果。

我在这里遗漏了什么吗?在具有相同 docker 引擎版本的 Ubuntu 主机上,结果如我所料。这是否与 Alpine 的硬化内核有关,导致容器 PID 空间的分隔方式出现问题?

对于调查领域的任何帮助表示赞赏。

-b

最佳答案

这个问题似乎与 Alpine 内核实现的 grsecurity 模块有关。在这种特定情况下,GRKERNSEC_CHROOT_FINDTASK 内核设置用于限制进程可以在 chroot 环境之外执行的操作。这由 kernel.grsecurity.chroot_findtask sysctl 变量控制。

来自 grsecurity 文档:

kernel.grsecurity.chroot_findtask

If you say Y here, processes inside a chroot will not be able to kill, send signals with fcntl, ptrace, capget, getpgid, setpgid, getsid, or view any process outside of the chroot. If the sysctl option is enabled, a sysctl option with name "chroot_findtask" is created.

我现在找到的唯一解决方法是禁用此标志以及 chroot_deny_mknodchroot_deny_chmod 标志,以获得与非安全内核。

kernel.grsecurity.chroot_deny_mknod=0
kernel.grsecurity.chroot_deny_chmod=0
kernel.grsecurity.chroot_findtask=0

当然,这并不理想,因为它会绕过并禁用系统的安全功能,但对于开发环境来说可能是一种有效的解决方法。

关于linux - Alpine Linux 3.7 上的 Docker 容器 : Strange pid 1 not visible within the container's pid namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47876468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com