RHEL 10 Podman 5.8 rootless:subuid、UID 映射与运行
rootless Podman 的“root”是命名空间里的 root:容器内 uid=0,宿主机上其实是你的普通用户 + 一段 subuid。理解这一点,才能解释权限、端口、存储为什么和 rootful 不一样。
在 PVE 390 rhel10-lab(RHEL 10.2 x86_64)上以 cloud-user 执行:
podman --versionpodman info --format '{{.Host.Security.Rootless}}'grep cloud-user /etc/subuid /etc/subgidpodman unshare cat /proc/self/uid_mappodman pull registry.access.redhat.com/ubi10/ubi-minimalpodman run --rm registry.access.redhat.com/ubi10/ubi-minimal idpodman images --digestspodman system dfE3 记录:plans/content-expansion/evidence/rhel/rhel-podman-rootless/run.json(8 步,含每步输出 sha256)。
先给结论:rootless ≠ 不用 root
Section titled “先给结论:rootless ≠ 不用 root”- 容器内是 root,但只在该 user namespace 里有效;
- 宿主机上对应的是
cloud-user与/etc/subuid分配的 65536 个 UID; - 绑定 1024 以下端口、挂载宿主机文件、访问 rootful 容器存储都会受限制;
- rootless 存储默认在
~/.local/share/containers,不在/var/lib/containers。
subuid / subgid
Section titled “subuid / subgid”$ grep cloud-user /etc/subuid /etc/subgid/etc/subuid:cloud-user:524288:65536/etc/subgid:cloud-user:524288:65536含义:从 524288 开始,给 cloud-user 分配 65536 个从属 UID/GID。没有这两行,rootless Podman 起不来(报 newuidmap: write to uid_map failed)。
UID 映射
Section titled “UID 映射”$ podman unshare cat /proc/self/uid_map 0 1000 1 1 524288 65536- 容器内
0→ 宿主1000(cloud-user); - 容器内
1..65536→ 宿主524288..589823; - 所以容器里的 root 写的文件,在宿主机上属主是
cloud-user或 524288 起的 UID。
拉镜像并运行
Section titled “拉镜像并运行”podman pull registry.access.redhat.com/ubi10/ubi-minimalpodman run --rm registry.access.redhat.com/ubi10/ubi-minimal id# uid=0(root) gid=0(root) groups=0(root)镜像信息:
REPOSITORY TAG DIGEST SIZEregistry.access.redhat.com/ubi10/ubi-minimal latest sha256:c039ecb9… 87.9 MBid 显示 root,是命名空间内的 root;不要据此认为容器逃逸或拥有宿主 root。
$ podman info --format '{{.Store.GraphRoot}}'/home/cloud-user/.local/share/containers/storage$ podman info --format '{{.Store.RunRoot}}'/run/user/1000/containers$ podman system dfImages 1 87.86MB 87.86MB (100% reclaimable)清理:
podman system prune -a注意:rootless 的 prune 只清当前用户的存储,不影响 rootful 的 /var/lib/containers。
| 现象 | 原因 | 处置 |
|---|---|---|
newuidmap: write to uid_map failed | 缺 subuid/subgid 或未安装 shadow-utils | 补 /etc/subuid、/etc/subgid |
| 绑定 80 端口失败 | rootless 不能绑 <1024 | 用 8080 或调 net.ipv4.ip_unprivileged_port_start |
| 看不到 rootful 镜像 | 存储是分开的 | podman images 用同一用户;需要共享用 podman save/load |
| 家目录满 | 镜像/层都在 ~/.local/share | podman system df、迁移 graphroot |
-
Host.Security.Rootless为 true; -
/etc/subuid、/etc/subgid有当前用户; -
podman unshare cat /proc/self/uid_map映射合理; - 镜像 digest 与来源可追溯;
- 知道存储/运行目录在用户家目录;
- 端口、挂载、SELinux 标签按 rootless 规则调整。
未实测与边界
Section titled “未实测与边界”- 未测试
podman generate systemd/ Quadlet 开机自启; - 未测试 rootless 网络(pasta/slirp4netns)与端口转发细节;
- 未测试
:Z/:zSELinux 标签与卷挂载; - 未测试 rootless 与 rootful 镜像迁移。
- RHEL 容器与 UBI — UBI 基础
- RHEL 10 采用评估 — Podman 5.8
- 官方:Building, running, and managing containers