使用 Docker 环境变量作为凭据
Use Docker environment variables for credentials
最近我们正在尝试找到一种正确的方法,通过环境变量将凭据注入我们在容器中 运行 基于 spring 的应用程序。
具体过程包括
- 一个bootstrapshell脚本,其中dockerCMD运行s作为入口点
- 在脚本中导出一堆凭据
- 运行脚本文件末尾的应用程序
通过这种方式,docker inspect
、docker exec [container_id] env
或bash的none进入docker容器和运行env
将看到这些环境变量,即。我们用 bootstrap 脚本注入的内容是不透明的。
那么问题来了:对于这个解决方案,我们还应该考虑其他什么吗?任何明显的故障?
我们是 docker 世界的新手,所以这种关于让 shell 脚本注入环境变量的行为在之后是不可见的,有没有文档解释为什么?我们还没有找到一个好的文档,但只是发现它以这种方式工作
PS。 docker 将来会改变这种行为吗?
提前致谢!
有趣的发现。我认为这是因为环境变量是 shell 会话的本地变量,您的应用程序是 运行。参见 https://help.ubuntu.com/community/EnvironmentVariables
Process locality
The values of environment variables are local, which means they are
specific to the running process in or for which they were set. This
means that if we open two terminal windows (which means we have two
separate bash processes running), and change a value of an environment
variable in one of the windows, that change will not be seen by the
shell in the other window or any other program currently on the
desktop.
关于风险,这里有很好的讨论https://github.com/docker/docker/pull/9176#issuecomment-99542089。例如,您可能在打印或记录环境的同一会话中有调试应用程序,任何子进程也会看到环境变量。
总的来说,这看起来是一个非常好的方法。
但是,我认为您无法对有权检查进程环境的人完全隐藏环境变量。在我看来,如果您找到应用程序进程的进程 ID(在容器内或从主机中),您应该能够在 /proc
中找到它的环境。不会显示为 docker env
,但它仍然存在于某处。
此外,无论如何,任何这样的人都可能直接连接到您的 Vault。
意思是,是的,这确实不会使子进程的环境出现在容器环境中,但它并没有真正对任何人隐藏它(谁已经可以访问你的主机并控制 docker ).
不过,恭喜这个设置。比在图像中内置凭据要好得多。
最近我们正在尝试找到一种正确的方法,通过环境变量将凭据注入我们在容器中 运行 基于 spring 的应用程序。
具体过程包括
- 一个bootstrapshell脚本,其中dockerCMD运行s作为入口点
- 在脚本中导出一堆凭据
- 运行脚本文件末尾的应用程序
通过这种方式,docker inspect
、docker exec [container_id] env
或bash的none进入docker容器和运行env
将看到这些环境变量,即。我们用 bootstrap 脚本注入的内容是不透明的。
那么问题来了:对于这个解决方案,我们还应该考虑其他什么吗?任何明显的故障?
我们是 docker 世界的新手,所以这种关于让 shell 脚本注入环境变量的行为在之后是不可见的,有没有文档解释为什么?我们还没有找到一个好的文档,但只是发现它以这种方式工作
PS。 docker 将来会改变这种行为吗?
提前致谢!
有趣的发现。我认为这是因为环境变量是 shell 会话的本地变量,您的应用程序是 运行。参见 https://help.ubuntu.com/community/EnvironmentVariables
Process locality
The values of environment variables are local, which means they are specific to the running process in or for which they were set. This means that if we open two terminal windows (which means we have two separate bash processes running), and change a value of an environment variable in one of the windows, that change will not be seen by the shell in the other window or any other program currently on the desktop.
关于风险,这里有很好的讨论https://github.com/docker/docker/pull/9176#issuecomment-99542089。例如,您可能在打印或记录环境的同一会话中有调试应用程序,任何子进程也会看到环境变量。
总的来说,这看起来是一个非常好的方法。
但是,我认为您无法对有权检查进程环境的人完全隐藏环境变量。在我看来,如果您找到应用程序进程的进程 ID(在容器内或从主机中),您应该能够在 /proc
中找到它的环境。不会显示为 docker env
,但它仍然存在于某处。
此外,无论如何,任何这样的人都可能直接连接到您的 Vault。
意思是,是的,这确实不会使子进程的环境出现在容器环境中,但它并没有真正对任何人隐藏它(谁已经可以访问你的主机并控制 docker ).
不过,恭喜这个设置。比在图像中内置凭据要好得多。