大网数据广告活动
服务器运维问答

Any point in running containers as non-root on openshift

· 52CE 我爱测

The openshift documentation reads : To further protect RHCOS systems in OpenShift Container Platform clusters, most containers, except those managing or monitoring the host system itself, should run as a non-root user. Dropping t…

问题原文

原帖链接 · bryan hunt · CC BY-SA 4.0

The openshift documentation reads :

To further protect RHCOS systems in OpenShift Container Platform clusters, most containers, except those managing or monitoring the host system itself, should run as a non-root user. Dropping the privilege level or creating containers with the least amount of privileges possible is recommended best practice for protecting your own OpenShift Container Platform clusters.

The container in question is going to run as a read-only, non-privileged, on cri-o runtime, with UID remapping, selinux, and secomp profile.

I’m wondering at this stage whether running the containers as non-root user is a cargo cult throwback from the days of docker daemon running as root.

If the container is running with all those constraints already is there any conceivable point in running as non-root user?

已采纳解答

原帖链接 · Erik Sjölund · CC BY-SA 4.0

Running a rootless container as root inside the container

Running as the root user is the default:

podman run --user 0:0 ...

(Adding --user 0:0 is not needed as it is the default)

If you haven't used the command-line option --uidmap, the root user will be mapped to the user's UID on the host.

The root user also has the permissions to run setuid() to change its effective UID so it has access to all the users UIDs (i.e. the user's normal UID and all the sub UIDs from the file /etc/subuid).

Running a rootless container as a non-root user inside the container

Running as a non-root user (for instance a user with UID=1000, GID=1000):

podman run --user 1000:1000 ...

If you haven't used the command-line options --uidmap or --userns=keep-id, the non-root user will not be mapped to the user's UID on the host but instead to one of the sub UIDs from user's UIDs in the file /etc/subuid.

Comparing the two alternatives (i.e. root and non-root)

In case Podman would have a security vulnerability, it would be safer if the container process would run as a non-root user that is not mapped to the user's UID on the host.

If such a container process would escape the container, it would only have file access as one of the users's sub UIDs. The process would not have any access to the directory ~/.ssh (that normally has the permission chmod 700 ~/.ssh).

Additional reading

The Red Hat blog post Running rootless Podman as a non-root user by Dan Walsh explains why it's more secure to run rootless containers as a non-root user than as the root user.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-05-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。