简体   繁体   English

如何管理微服务/容器/云环境中的秘密?

[英]How to manage secrets in a Microservice / Container / Cloud environment?

Microservices and Cloud is a thing. 微服务和云是一件事。 Everyone is talking and writing about. 每个人都在谈论和写作。 Personally i am thinking a lot about this topics: How this can be used to benefit from? 就我个人而言,我正在考虑这个话题:如何利用它来获益? What are possible challenges? 有哪些可能的挑战? How can this speedup the daily development? 这怎么能加速日常发展? And how to manage all things? 以及如何管理所有事情? One question that bothers me since a few days is "How to manage secrets in a Microservice / Cloud environment?". 几天之后困扰我的一个问题是“如何管理微服务/云环境中的秘密?”。

Imagine a company with 150 software engineers and various teams with various products. 想象一家拥有150名软件工程师和各种团队的公司。 Every team is creating a software and every service needs various amounts of secrets (API-Keys, Passwords, SSH-Keys, whatever). 每个团队都在创建一个软件,每个服务都需要各种秘密(API密钥,密码,SSH密钥等等)。 The "old fashion" way was to create a few configuration files in a ini / yaml / txt format and read it from. “旧时尚”方式是以ini / yaml / txt格式创建一些配置文件并从中读取。 12Factor apps say: Do it per env vars. 12个因子应用程序说:按照env vars进行。

Env vars can be set per machine and the config files can be placed there as well. 可以为每台机器设置Env变量,也可以将配置文件放在那里。 This works if you got a hand full of machines and the deployment is done by a few system admins. 如果你手持一台机器并且部署由一些系统管理员完成,这就有效。 One of the general rules say: "Don`t store secrets in a Git repo.". 一般规则说:“不要在Git回购中存储秘密。”

Now the new world comes in. Ever team is responsible for the application they produce itself. 现在,新的世界进入了。团队负责他们自己生产的应用程序。 They should be deployed and run by the team. 它们应该由团队部署和运行。 So our company is moving to a container and self-service way (eg Mesos and Marathon or Kubernetes). 所以我们公司正在转向集装箱和自助服务方式(例如Mesos和Marathon或Kubernetes)。

Of course, Dockerfiles can set env vars as well. 当然,Dockerfiles也可以设置env变量。 And yes, you can ADD your config file into the Docker container during build. 是的,您可以在构建期间将配置文件添加到Docker容器中。 But with this everyone can access the secrets (eg from other teams). 但有了这个,每个人都可以访问秘密(例如来自其他团队)。 And no one knows who uses this secrets and do something dangerous. 没有人知道谁使用这个秘密并做了一些危险的事情。

You want to versionize your Dockerfiles as well. 您还希望对Dockerfiles进行版本化。 And applications you want to run on Marathon should be versionized (Git or whatever) as well (and applied by REST API). 您希望在Marathon上运行的应用程序也应该进行版本化(Git或其他)(并由REST API应用)。 So where to store and manage all the secrets for this containers / apps? 那么在哪里存储和管理这个容器/应用程序的所有秘密? Because with scheduler frameworks like Swarm and Machine (for Docker), Mesos and Marathon (usable for Docker as well) or Kubernetes you don`t know where your app will be running. 因为使用Swarm和Machine(对于Docker),Mesos和Marathon(也可用于Docker)或Kubernetes等调度程序框架,您不知道应用程序将在何处运行。 This will be scheduled over several machines. 这将安排在几台机器上。 And most of this tools have no authentification (by default, of course this can be added by a Nginx proxy or something). 并且大多数此类工具都没有身份验证(默认情况下,当然可以通过Nginx代理或其他方式添加)。

One idea to manage secrets is using a tool like Vault . 管理机密的一个想法是使用像Vault这样的工具。 But i never saw "native" support in an app. 但我从来没有在应用程序中看到“原生”支持。 The same applies for Blackbox . Blackbox也是如此 And i don`t know how configuration management can solve this. 我不知道配置管理如何解决这个问题。 I know that Chef supports encrypted databags, but afaik it is not possible to use Chef to setup/build Docker containers. 我知道Chef支持加密的数据库,但是不能使用Chef来设置/构建Docker容器。

How do you manage secrets in a multi team env with several engineers in a Microservice / Container / Cloud environment? 您如何在微服务/容器/云环境中与多名工程师一起管理多个团队环境中的秘密?

There are several solutions. 有几种解决方案。

First, DO NOT put your secrets into the image. 首先, 不要把你的秘密放入图像中。 That's just a bad idea, as you've realized. 你已经意识到,这只是个坏主意。 If you don't add your secrets at build time, you have to do it at run-time. 如果您不在构建时添加秘密,则必须在运行时执行此操作。 This leaves us with a few options: 这给我们留下了一些选择:

  • Use environment variables as suggested by the 12 Factor App . 使用12 Factor App建议的环境变量。 You will then need to write a script that will populate the config files with values of these variables when the container starts up. 然后,您需要编写一个脚本,在容器启动时使用这些变量的值填充配置文件。 This works, but I don't really like it, as environment variables are easily leaked (they can be seen in linked containers and docker inspect and are often included in bug reports). 这有效,但我不是很喜欢它,因为环境变量很容易泄露(它们可以在链接容器和docker inspect看到,并且通常包含在bug报告中)。 Also see Summon . 另见Summon

  • Use volumes. 使用卷。 Just mount the config file with the secrets at run-time. 只需在运行时安装配置文件和秘密。 This works, but does mean you have a file with the secrets lying about on the host. 这有效,但确实意味着你有一个文件,其中包含主机上的秘密。 This gets more complicated when you don't know on which host your container will run, such as when using frameworks like Swarm and Mesos. 当您不知道容器将在哪个主机上运行时,例如使用Swarm和Mesos等框架时,这会变得更加复杂。

  • Use a secure k/v store such as Vault / Keywhiz . 使用安全的k / v商店,例如Vault / Keywhiz As you point out, you will need to do some scripting to get the values into the application (as with env vars). 正如您所指出的,您需要执行一些脚本来将值传入应用程序(与env变量一样)。 You also need to authenticate to the k/v store somehow (you may want to look at the volume drivers for Keywhiz and Vault , or use a one-use token passed via an env var). 您还需要以某种方式对k / v存储进行身份验证(您可能需要查看KeywhizVault的卷驱动程序,或使用通过env var传递的一次性令牌)。

Kubernetes already has fairly advanced support for secrets , and I would expect to see other frameworks adopt their own solutions. Kubernetes已经拥有相当高级的秘密支持 ,我希望看到其他框架采用自己的解决方案。

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

相关问题 在 GitHub 操作中管理机密 - Manage secrets in GitHub Actions 如何在 package.json 中使用环境变量或屏蔽机密? - How do I use environment variables or mask secrets in package.json? 如何使用环境变量进行Git和云部署 - How to use environment variables for Git and cloud deployment 在git上管理微服务问题或bug的最佳方法是什么 - What is the best way to manage microservice issue or bug on git Git 管理环境特定配置 - Git manage environment specific configuration 部署云 function 时如何在描述/环境中包含提交号? - How to include commit number in description/environment when deploying a cloud function? 如何在云无状态托管环境中处理用户可编辑模板? - How to handle user editable templates in a cloud stateless hosting environment? 如何在kubernetes / openshift的init容器args中使用环境变量? - How to use environment variables in init container args in kubernetes/openshift? 如何在Google App Engine标准环境(manage.py,…)中运行文件Django / python我的文件 - How to run files my files Django/python in Google App Engine Standard Environment ( manage.py, … ) git几个开发容器环境 - several development container environment with git
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM