我尝试在 Azure DevOps 管道中使用图像,但该图像不符合 the following requirement of Linux-based containers :
USER
has access togroupadd
and other privileges commands withoutsudo
因此,Azure 无法注入(inject)其片段,因为该功能不可用,并且管道失败。
这不是我故意对图像做的事情。我将如何允许用户访问groupadd
等而不需要sudo
?
最佳答案
第一个答案是以 root 身份运行镜像。这根本不安全。
Josh Channings 给出了另一个答案,或更准确地说是一种解决方法。上Github 。在你的 Dockerfile 中,你应该...
...
chmod u+s /usr/sbin/groupadd /usr/sbin/usermod && \
touch /etc/sudoers && \
chmod u+w /etc/sudoers && \
rm -f /bin/su && \
echo '#!/usr/bin/env bash' > /bin/su && \
echo "echo 'su' has been disabled in this container" >> /bin/su && \
chmod +x /bin/su && \
...
基本上,我们覆盖/bin/su并更新权限,以便我们可以使用groupadd和usermod。这一点都不方便,但确实有效。答案还涵盖了基础镜像中不存在 /etc/sudoers 的情况。
关于azure - 容器应该如何在没有 sudo 的情况下授予对 groupadd 的访问权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75534971/