gpt4 book ai didi

security - 非特权执行从头开始

转载 作者:IT王子 更新时间:2023-10-29 02:22:18 27 4
gpt4 key购买 nike

我正在从头开始在图像上构建/部署 go/golang 微服务。

是否可以在以这种方式构建的图像上指定非特权执行——图像上只有两个文件——go 可执行文件和根证书文件——所以似乎没有任何特权的概念在容器内。

我也使用只读容器和 --selinux-enabled=true --icc=false --iptables=true,但如果我知道可执行文件作为“普通”非运行时会感觉更温暖和模糊-特权用户。

最佳答案

在从“FROM scratch”构建的镜像启动的容器中运行 CMD 的用户(root)似乎没有任何选择。

但是根据容器的定义,该用户只能影响其自己的(磁盘、内存、资源)空间,而不能影响主机。所以应该没关系。

唯一的另一种选择是从头开始定义一个容器,仅用于声明一个卷容器,您将在能够与非根用户一起运行的完整图像中使用它。
参见“Running as a non-root inside a container

$ echo 'FROM scratch
ADD data.tar /
VOLUME ["/data"]' > Dockerfile

$ docker build -t minimal .
$ docker create --name minimal minimal :

The container that mounts this minimal volume container needs to create the user with id 1000:

$ docker run --rm --volumes-from minimal  -it debian:jessie /bin/bash -c 'useradd postgres && ls -l /data'

这不是您所需要的(因为 Go 程序不需要任何动态库,并且可以仅通过系统调用运行)。但这说明了非根用户如何使用“FROM scratch”容器(此处作为卷)

关于security - 非特权执行从头开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42237002/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com