【问题标题】:Change rights of `/etc/passwd` in Dockerfile在 Dockerfile 中更改 `/etc/passwd` 的权限
【发布时间】:2021-12-06 04:57:01
【问题描述】:

我正在为 Openshift 构建 Podman 映像,但存在权限问题。

this guide 之后,并且由于 Openshift 在运行容器时分配了一个随机 UID 和一个 GID“0”,我尝试将 chmod /etc/passwd 使其组可写,并在运行时将我的 Openshift 用户添加到其中;但似乎我不能总是chmod 那个/etc/passwd 文件。

最小的 Dockerfile:

FROM ubuntu:20.04

USER root

RUN ls -l /etc/passwd
RUN chmod g+w /etc/passwd
RUN ls -l /etc/passwd

在构建 (sudo podman build . -t test-image) 时,我在 /etc/passwd 上看到了正确的权限:

STEP 1: FROM ubuntu:20.04
STEP 2: USER root
--> Using cache 2cb48e4f8eed907e057017011e20ddc47ec8f152bb7afe34ecf6be23413cd08b
STEP 3: RUN ls -l /etc/passwd
-rw-r--r--. 1 root root 926 Sep 21 16:48 /etc/passwd
     ^
     ^
     ^
79f60398d64ece1b413fd904681ad5fd0725bae4b283abce7b7a9ea017d4ebe7
STEP 4: RUN chmod g+w /etc/passwd
6ed13401ab693dbc362ec90b9c3767c1cd2244074ca4e92bd1b31b72b3e80868
STEP 5: RUN ls -l /etc/passwd
-rw-rw-r--. 1 root root 926 Sep 21 16:48 /etc/passwd
     ^
     ^
     ^
STEP 6: COMMIT test
d667b2c05818b5af3c9db85a5e7179c8e7b1c21281e31c34a871e97268716f39

当我使用root 用户运行我的容器时,没有问题:

[user@server]$ sudo podman run -it test-image /bin/bash
root@295ab7b72a4d:/# ls -l /etc/passwd
-rw-rw-r--. 1 root root 926 Sep 21 16:48 /etc/passwd
     ^
     ^
     ^

但是当我使用随机用户运行时,/etc/passwd 权限不再更改...

[user@server]$ sudo podman run -it -u 1000701200:0 test-image /bin/bash
1000701200@a63d9bf9f53a:/$ ls -l /etc/passwd
-rw-r--r--. 1 root root 977 Oct 19 08:51 /etc/passwd
     ^
     ^
     ^

为什么/etc/passwd 的权限取决于运行容器的用户?

提前致谢。

编辑 1:我创建的随机文件不是这种情况,它按预期工作。所以/etc/passwd 文件有一些特别之处。

【问题讨论】:

  • 刚刚尝试过,并且通过我的设置,该文件具有组写入权限 - 我使用 3.4.0
  • Podman 似乎会自动将用户添加到 /etc/passwd - 有趣
  • 感谢您的帮助。我使用 1.4.4 版...可能是问题所在。与此同时,我发现this 说这是一种不好的做法,推荐的方法是使用nss_wrapper...所以我会试一试
  • 嗨,没有更新。我已经看到与我最初使用的指南相关联的 Git 已被弃用,所以我想这不再是最佳实践了......但我没有时间进一步调查
  • 我无法通过podman version 3.4.1 重现此问题,无论是通过 sudo 还是不使用 sudo 执行 podman。

标签: docker kubernetes openshift podman passwd


【解决方案1】:

podman 版本是有原因的 - 更新到 3.x 版本解决了这个问题。

【讨论】:

    猜你喜欢
    • 2022-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 2022-10-17
    • 2020-09-23
    • 1970-01-01
    • 2016-08-22
    相关资源
    最近更新 更多