【问题标题】:Run Docker container in Cirrus/Kubernetes environment as specific non-root user在 Cirrus/Kubernetes 环境中以特定的非 root 用户身份运行 Docker 容器
【发布时间】:2023-03-31 01:51:01
【问题描述】:

当我在本地使用 docker-compose 语句运行入口点时,我可以让系统充当 bluecost 用户。但是,当我在 IBM Hybrid Cloud 上执行此操作时,它会以具有根 GID 的随机用户身份运行它。

下面是我的 Dockerfile,我怀疑所有这些都是相关的,但我想完整一点,以防我误解了某些东西。

我的想法是,USER 语句切换了 ENTRYPOINT 运行的用户。如果在实际构建容器时需要切换,我可以直接完成 sudosu。我的意图和愿望是它以 USER bluecost 的身份运行 /ssc/bin/put-and-submit-ssh.sh

是否有可能以某种方式运行su ssc/bin/put-and-submit-ssh.sh 来强制它执行此操作?

FROM registry.access.redhat.com/ubi8
RUN yum update
RUN yum install -y git
RUN yum install -y openssh-clients
RUN yum module reset -y perl
RUN yum module enable -y perl:5.30
RUN yum install -y --nobest --allowerasing perl
RUN yum install -y openssl-devel
RUN yum install -y iputils
ENV PERL_MM_USE_DEFAULT 1
RUN cpan install -f Net::SSL 
RUN cpan install -f inc:latest 
RUN cpan install -f Net::FTPSSL
RUN cpan install -f Net::SCP
RUN cpan install -f Net::SSH::Perl::Kex
RUN cpan install -f Net::SSH::Perl
RUN cpan install -f IPC::Run
RUN cpan install -f IPC::Run3
RUN yum install -y wget
RUN cpan install -f App::cpanminus
RUN curl -L https://cpanmin.us/ -o /bin/cpanm
RUN chmod +x /bin/cpanm
RUN useradd -r -u 1000 -g root bluecost
RUN mkdir /ssc
RUN mkdir /host-dirs
RUN chown --recursive bluecost:root ssc host-dirs 
RUN mkdir /home/bluecost
RUN mkdir /home/bluecost/.ssh
RUN echo "StrictHostKeyChecking no" > /home/bluecost/.ssh/config
RUN mkdir /root/.ssh
RUN echo "StrictHostKeyChecking no" > /root/.ssh/config
RUN chown -R bluecost:root /home/bluecost
RUN yum install -y sudo
RUN echo "bluecost ALL=(ALL) NOPASSWD: ALL"  >>/etc/sudoers
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
RUN yum install -y sshpass
RUN yum install -y rsh
USER bluecost
COPY --chown=bluecost:root . /ssc
RUN chmod --recursive 555 ./ssc 
RUN chmod a+x /ssc/bin /ssc/tls /ssc/tls/certs
RUN chmod g+rx host-dirs 
ENTRYPOINT ["/ssc/bin/put-and-submit-ssh.sh"]

【问题讨论】:

标签: linux docker kubernetes


【解决方案1】:

OpenShift 文档在Creating images 上有一篇文章。部分OpenShift Container Platform-specific guidelines > Support arbitrary user ids状态

默认情况下,OpenShift Container Platform 使用任意分配的用户 ID 运行容器。这为由于容器引擎漏洞而逃逸容器的进程提供了额外的安全性,从而在主机节点上实现了升级的权限。

所以它似乎以具有根 GID 的用户身份运行是设计使然。

对于支持以任意用户身份运行的映像,映像中的进程写入的目录和文件必须归根组所有,并且可由该组读取/写入。要执行的文件还必须具有组执行权限。

将以下内容添加到您的 Dockerfile 设置目录和文件权限,以允许 root 组中的用户在构建的映像中访问它们:

RUN chgrp -R 0 /some/directory && \
    chmod -R g=u /some/directory

【讨论】:

    猜你喜欢
    • 2017-02-05
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-02
    • 2019-06-24
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    相关资源
    最近更新 更多