问题描述
简单的场景是这样的;在本教程中:
-
Using
podman
withoutsudo
-
update #1 ... 该问题似乎与在 Ubuntu 上正确激活
cgroups2
相关>.
在 Ubuntu 容器中运行 bash
,而无需 root/sudo
特权。命令行是:
podman run --rm --interactive --tty ubuntu bash
此命令带来以下结果:
$ podman run --rm --interactive --tty ubuntu:20.10 bash
Completed short name "ubuntu" with unqualified-search registries (origin: /etc/containers/registries.conf)
Trying to pull docker.io/library/ubuntu:20.10...
Getting image source signatures
copying blob 79e7e9027772 done
copying blob eed86eef5a46 done
copying blob 1b553362680b done
copying config deb373a625 done
Writing manifest to image destination
Storing signatures
Error processing tar file(exit status 1): potentially insufficient UIDs or GIDs
available in user namespace (requested 0:42 for /etc/gshadow):
Check /etc/subuid and /etc/subgid: lchown /etc/gshadow: invalid argument
Error: Error committing the finished image: error adding layer with
blob "sha256:eed86eef5a4687135cb1ba7c55da6af79c9182e8bf59b53a880d1b334515c8e3":
Error processing tar file(exit status 1): potentially insufficient UIDs or GIDs
available in user namespace (requested 0:42 for /etc/gshadow): Check /etc/subuid
and /etc/subgid: lchown /etc/gshadow: invalid argument
这让我们相信一些进一步的特权是必要的(可能不是 root,而是...)。这已经通过使用 sudo
运行相同的命令得到确认——它工作得非常愉快,除了 popdman Ubuntu
图像在我的 PC 上作为 root
运行。不是我期望的快乐结果。
目前这台机器上的 /etc/subuid
和 /etc/subgid
文件只有少数 samba
用户和 wireshark
用户的条目,如下所示:
/etc/subgid /etc/subgid
tsmith:100000:65536 tsmith:100000:65536
demo:165536:65536 demo:165536:65536
smbguest:231072:65536 smbguest:231072:65536
wireshark:296608:65536 wireshark:296608:65536
此时我真的没有指导。我意识到我需要对 subuid
-s 和 subgid
-s 做一些事情才能使这个示例工作。到目前为止,我还没有找到一些关于需要什么的提示或文档。除了不直接编辑文件 - 足够了。
同样在上面提到的教程中,是一个查看 sudo
-s 的非 subuid
示例:
$ podman unshare cat /proc/self/uid_map
0 1000 1
1 100000 65536
我问自己这是用户 #1 只是一个例子还是我错过了一步?当我在这台电脑上做同样的事情时,我看到的是:
$ podman unshare cat /proc/self/uid_map
0 1000 1
没有用户#1,只有用户#0。我要采取什么行动?现在的问题是:
- 如何让 Ubuntu
bash
shell 在容器中无根运行?- 最小的改动就足以让
bash
无根运行。
- 最小的改动就足以让
- 我从哪里开始?
- 我需要做什么?
- 我该怎么做?
解决方法
请参阅此链接,了解如何在 Redhat 上设置无根访问:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/building_running_and_managing_containers/starting-with-containers_building-running-and-managing-containers
,通过应用本文中的所有步骤,我最终让 Ubuntu 使用了一个无根容器......
这几乎就像我以前开始的原始文章中的观点一样,所以我真的不能说第一次没有做对。那篇文章中的步骤绝对可以胜任。
确认您的容器是无根的非常重要 (imho)。有时您仍然可以以 root 身份运行,但认为它“有效”。