• Cartoon showing a light purple os-tree icon on the left and a dark purple gradiated os-tree icon on the right. a large purple arrow is pointing from the one on the left to the one on the right. the os-tree icon on the right has a septagon with the words OCI on it, representing an OCI contianer image modifying the os-tree it depicts. The podman selkie seals cartoon is inbetween the two icons under the arrow. The background is purple and the seals are in blue water.
, ,

减少权限,使容器更安全。

你可能不知道,Podman 一直在运行着比 Docker 更少的 权限。Podman 不仅默认以无根模式运行,即使在无根模式下,它也比 Docker 运行得更严格。Docker 以 14 个 root 权限运行,而 Podman 以 10 个权限运行。

然而,这始终是通过发行版默认值而不是内置默认值实现的。Fedora、RHEL、Centos 和其他基于 Fedora containers-common rpm 的发行版一直在 /usr/share/containers/containers.conf 中附带以下权限列表。

default_capabilities = ["CHOWN",  "DAC_OVERRIDE", "FOWNER",  "FSETID",  "KILL",  "NET_BIND_SERVICE",  "SETFCAP",  "SETGID",  "SETPCAP",  "SETUID"]


其他发行版可以附带他们自己的默认值。本周,我在 container/common 中更改了默认值,因此内置默认值现在将只有 10 个权限。这意味着,当 Podman 4.4 发布时,所有发行版都将使用这些默认值,除非他们在他们的 containers.conf 文件中覆盖它们。

我们删除了哪些权限?

CAP_CHROOT:允许容器内的进程设置 chroot。多年来,我们看到很少有容器需要此权限。

CAP_AUDIT_WRITE:允许进程修改和写入审计子系统。当人们试图在容器内运行 sshd 时,可能需要此权限。

CAP_MKNOD:这允许容器进程创建设备节点。设备节点由 Podman 创建,允许进程创建设备节点被认为是危险的。

CAP_NET_RAW:这允许容器进程制定自己的网络数据包。这是非常危险的,因为它可能会触发网络堆栈中的错误。以前需要使用 ping,但我们添加了一个 sysctl 以允许在没有 CAP_NET_RAW 的情况下 ping。


#默认情况下在容器中设置的 sysctl 列表,
#指定为“name=value”
#例如:“net.ipv4.ping_group_range=0 0”。
#
default_sysctls = [
“net.ipv4.ping_group_range=0 0”,
]

如果您的容器需要这些权限之一,则可以轻松地添加回来。

podman run –cap-add NET_RAW …


发表评论

订阅

使用您的电子邮件地址注册,以便从本网站通过电子邮件接收更新。


分类


搜索