简体   繁体   English

在 Cirrus/Kubernetes 环境中以特定的非 root 用户身份运行 Docker 容器

[英]Run Docker container in Cirrus/Kubernetes environment as specific non-root user

When I run the entrypoint using a docker-compose statement locally, I can get the system to act as the bluecost user.当我在本地使用 docker-compose 语句运行入口点时,我可以让系统充当 bluecost 用户。 However, when I do this on IBM Hybrid Cloud, it runs it as a random user with a root GID.但是,当我在 IBM Hybrid Cloud 上执行此操作时,它以具有根 GID 的随机用户身份运行它。

Below is my Dockerfile, I doubt all of this is relevant, but I wanted to be complete in case I mis-understood something.下面是我的 Dockerfile,我怀疑所有这些都是相关的,但我想完整一些,以防我误解了某些东西。

My thought was, the USER statement switches the user the ENTRYPOINT runs as.我的想法是,USER 语句会切换 ENTRYPOINT 运行的用户。 If I needed to switch when actually building the container, I could have just done sudo or su .如果我在实际构建容器时需要切换,我可以只执行sudosu My intent and desire is that it runs /ssc/bin/put-and-submit-ssh.sh as USER bluecost.我的意图和愿望是能够运行/ssc/bin/put-and-submit-ssh.sh为用户bluecost。

Is it possible to run su ssc/bin/put-and-submit-ssh.sh somehow to force it to do this?是否可以以某种方式运行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"]

OpenShift docs have an article on Creating images . OpenShift 文档中有一篇关于创建图像的文章。 Section OpenShift Container Platform-specific guidelines > Support arbitrary user ids states部分OpenShift Container Platform 特定指南 > 支持任意用户 ID状态

By default, OpenShift Container Platform runs containers using an arbitrarily assigned user ID.默认情况下,OpenShift Container Platform 使用任意分配的用户 ID 运行容器。 This provides additional security against processes escaping the container due to a container engine vulnerability and thereby achieving escalated permissions on the host node.这为防止进程因容器引擎漏洞而逃逸容器提供了额外的安全性,从而实现了对主机节点的升级权限。

So it seems running as user with root GID is by design.因此,它似乎以具有根 GID 的用户身份运行是设计使然。

For an image to support running as an arbitrary user, directories and files that are written to by processes in the image must be owned by the root group and be read/writable by that group.对于支持以任意用户身份运行的映像,映像中进程写入的目录和文件必须归根组所有,并且可由该组读取/写入。 Files to be executed must also have group execute permissions.要执行的文件还必须具有组执行权限。

Adding the following to your Dockerfile sets the directory and file permissions to allow users in the root group to access them in the built image:将以下内容添加到您的 Dockerfile 设置目录和文件权限,以允许 root 组中的用户在构建的映像中访问它们:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以非root用户身份运行Docker容器以及如何与他人共享Docker映像? - How to run docker container as non-root user and how to share the docker image to others? 以非 root 用户身份在 Docker 容器内运行 tcpdump - Running tcpdump inside a Docker container as non-root user Ubuntu以非root用户身份运行脚本 - Ubuntu run script as non-root user 如何以非root用户身份运行Kafka? - How to run Kafka as non-root user? 在 Ubuntu Docker 容器内运行非 root Docker - Running non-root Docker within Ubuntu Docker container 以非root用户身份启动容器与以root用户身份启动然后降级为非root用户身份 - Starting container as a non-root user vs starting as root and then downgrade to non-root 在 Docker 映像中以非 root 用户身份运行 cronjob 的正确方法是什么? - What is the proper way to run a cronjob as a non-root user in a Docker image? 在 kubernetes 中授予非 root 用户 kubectl 的访问权限 - Granting a non-root user the access of kubectl in kubernetes 你能否以root身份在Docker容器内启动进程,而exec调用的默认用户是非root用户? - Can you start a process inside a Docker container as root, while having the default user of an exec call be non-root? 为非 root 用户创建工作 Docker 映像的问题 - Issues with creating working Docker image for non-root user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM