大网数据广告活动
服务器运维问答

How to prevent attach or exec in a docker container

· 52CE 我爱测

How do a prevent a user of my pre-built docker container from being able to access a shell within a running instance of that container? I have googled and read all the posts that are related to this scenario and have come up with…

问题原文

原帖链接 · Paul Gregoire · CC BY-SA 3.0

How do a prevent a user of my pre-built docker container from being able to access a shell within a running instance of that container? I have googled and read all the posts that are related to this scenario and have come up without a working solution. I am trying to prevent access to a given resource in the container, for the sake of this inquiry, let's say its a serial number in a configuration file. I am building upon the java:7 image which is based upon an ubuntu image.

To test your solution, do the following:

  1. Create and run your docker container

  2. Export your container

    docker export [container name] | gzip -c > mycontainer.tar.gz

  3. Import your container on an external system

    gzip -dc mycontainer.tar.gz | docker import - [container name]

  4. Run the container

  5. Shell into the running container using any / all of the following methods:

    docker exec -it [container name] bash

    docker attach [container name]

    docker run -ti --entrypoint=/bin/bash [container name]

[container name] is the name of your container

bash, dash, and sh are all valid shells

社区高分解答

原帖链接 · Dr.Knowitall · CC BY-SA 3.0

To add on to Jose's answer, another solution is to...

docker exec :id -it /bin/rm -R /bin/*

That gets rid of sh and any bin useful command in linux. I'm unsure what you'd do to get into the container at that point. Though I know that you might be able to use a memory debugger to get environment variables of the running container, but it makes it that much more annoying... I wonder if theres a way to lock down that memory in ring 0 and take away ssh access altogether to the host.

If anyone knows how to crack that, I would be interested in knowing how.

EDIT

You want to use docker secrets if you're protecting sensitive information. Check out:

https://docs.docker.com/engine/swarm/secrets/

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-09-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。