Raspbian 上 Apache2 挂载命名空间的奇怪行为

Raspbian 上 Apache2 挂载命名空间的奇怪行为

我目前正在尝试理解为什么在 Raspbian Stretch (Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l GNU/Linux) 上运行的 Apache2 (2.4.25-3+deb9u2) 具有对根挂载点的看法与 bash 等不同。

cat /proc/{PID of Apache2}/mountinfo给出以下输出:

129 127 179:2 / / ro,noatime shared:80 master:1 - ext4 /dev/root ro,data=ordered

cat /proc/self/mountinfo从 bash 执行会给出以下输出:

15 0 179:2 / / ro,noatime shared:1 - ext4 /dev/root ro,data=ordered

据我了解的解释man 7 mount_namespaceshttps://lwn.net/Articles/689856/,https://lwn.net/Articles/690679/输出man 5 proc告诉我 Apache 是对等组 1 的从属设备。它本身创建了一个 ID 为 80 的共享对等组。

我不明白的是,为什么会发生这种情况。我认为 systemd 可以控制这一点,因此我创建了/etc/systemd/system/apache2.service包含以下内容的文件:

.include /lib/systemd/system/apache2.service

[Service]
MountFlags=shared

但显然这没有帮助。当我删除 MountFlags 行时也没有区别。

因此,除了了解为什么会出现这种情况之外,我想知道是否有任何方法可以防止 Apache 成为根安装对等组的从属服务器。

此外,如果我重新挂载根目录以使其可mount -o remount,rw /在 bash 中写入,则这不会传播到 Apache2 挂载命名空间中。示例,从mountinfo上面开始:

# mount -o remount,rw /
# cat /proc/self/mountinfo
15 0 179:2 / / rw,noatime shared:1 - ext4 /dev/root rw,data=ordered
# cat /proc/{PID of Apache2}/mountinfo
129 127 179:2 / / ro,noatime shared:80 master:1 - ext4 /dev/root rw,data=ordered

这是 Apache 安全功能的一部分吗?

更新 1:如果我在 root 挂载为 rw 时(重新)启动 Apache2 服务,则重新挂载将传播到 Apache2 挂载命名空间。只有在root为ro的情况下启动Apache2服务,不起作用?!

答案1

删除PrivateTmp=trueapache2.service中的设置。

https://www.freedesktop.org/software/systemd/man/systemd.exec.html

如果为 true,则为执行的进程设置一个新的文件系统命名空间,并在其中安装私有 /tmp 和 /var/tmp 目录,该目录不被命名空间之外的进程共享。

相关内容