简体   繁体   English

如何在 Kubernetes pod/container 中以非 root 用户身份登录

[英]How to logon as non-root user in Kubernetes pod/container

I am trying to log into a kubernetes pod using the kubectl exec command.我正在尝试使用 kubectl exec 命令登录到 kubernetes pod。 I am successful but it logs me in as the root user.我成功了,但它以 root 用户身份登录。 I have created some other users too as part of the system build.作为系统构建的一部分,我也创建了一些其他用户。

Command being used is "kubectl exec -it /bin/bash".使用的命令是“kubectl exec -it /bin/bash”。 I guess this means that run /bin/bash on the pod which results into a shell entry into the container.我想这意味着在 pod 上运行 /bin/bash 会导致进入容器的 shell 条目。

Can someone please guide me on the following -有人可以指导我以下 -

  1. How to logon using a non-root user?如何使用非root用户登录?
  2. Is there a way to disable root user login?有没有办法禁用root用户登录?
  3. How can I bind our organization's ldap into the container?如何将我们组织的 ldap 绑定到容器中?

Please let me know if more information is needed from my end to answer this?请让我知道是否需要更多信息来回答这个问题?

Thanks,谢谢,

Anurag阿努拉格

You can use su - <USERNAME> to login as a non-root user.您可以使用su - <USERNAME>以非 root 用户身份登录。

Run cat /etc/passwd to get a list of all available users then identify a user with a valid shell compiler eg运行cat /etc/passwd以获取所有可用用户的列表,然后使用有效的 shell 编译器识别用户,例如

/bin/bash or /bin/sh /bin/bash/bin/sh

Users with /bin/nologin and /bin/false as the set compiler are used by system processes and as such you can't log in as them.使用/bin/nologin/bin/false作为设置编译器的用户被系统进程使用,因此您无法以他们的身份登录。

I think its because the container user is root, that is why when you kubectl exec into it, the default user is root.我认为这是因为容器用户是 root,这就是为什么当你 kubectl exec 进入它时,默认用户是 root。 If you run your container or pod with non root then kubectl exec will not be root.如果您使用非 root 运行容器或 pod,则 kubectl exec 将不是 root。

In most cases, there is only one process that runs in a Docker container inside a Kubernetes Pod.在大多数情况下,只有一个进程在 Kubernetes Pod 内的 Docker 容器中运行。 There are no other processes that can provide authentication or authorization features.没有其他进程可以提供身份验证或授权功能。 You can try to run a wrapper with several nested processes in one container, but this way you spoil the containerization idea to run an immutable application code with minimum overhead.您可以尝试在一个容器中运行具有多个嵌套进程的包装器,但这样会破坏容器化思想,以最小的开销运行不可变的应用程序代码。

kubectl exec runs another process in the same container environment with the main process, and there is no option to set the user ID for this process. kubectl exec在与主进程相同的容器环境中运行另一个进程,并且没有选项可以为该进程设置用户 ID。

However, you can do it by using docker exec with the additional option:但是,您可以使用带有附加选项的docker exec来实现:

--user , -u    Username or UID (format: <name|uid>[:<group|gid>])

In any case, these two articles might be helpful for you to run IBM MQ in Kubernetes cluster无论如何,这两篇文章可能对您在 Kubernetes 集群中运行 IBM MQ 有所帮助

暂无
暂无

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

相关问题 以非root用户身份启动容器与以root用户身份启动然后降级为非root用户身份 - Starting container as a non-root user vs starting as root and then downgrade to non-root 如何让 Docker 容器中的非 root 用户访问安装在主机上的卷 - How to give non-root user in Docker container access to a volume mounted on the host 如何以root身份启动Java程序,但降级为非root用户 - How to start Java program as root but downgrade to non-root user 以非 root 用户身份在 Docker 容器中运行不受信任的代码有哪些潜在的安全问题? - What are the potential security problems running untrusted code in a Docker container as a non-root user? 在Openshift上以非root用户身份运行nginx并在端口80上侦听 - Running nginx as non-root user on Openshift and listening on port 80 Docker - 在 ENTRYPOINT 中切换到非 root 用户是否安全? - Docker - is it safe to switch to non-root user in ENTRYPOINT? 将权限作为沙盒的常规非root用户删除? - Drop privileges as regular non-root user for sandboxing? 为什么我们要以非root用户身份运行tomcat? - why should we run tomcat as non-root user? 以非root用户身份运行系统守护程序PID文件的首选位置 - Preferred location for PID file of system daemon run as non-root user 在 Docker 映像中以非 root 用户身份运行 cronjob 的正确方法是什么? - What is the proper way to run a cronjob as a non-root user in a Docker image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM