简体   繁体   English

使用kubernetes使用敏感信息填充Docker容器

[英]Populating Docker containers with sensitive information using kubernetes

I have a pod that runs containers which require access to sensitive information like API keys and DB passwords. 我有一个运行容器的容器,需要访问API密钥和数据库密码等敏感信息。 Right now, these sensitive values are embedded in the controller definitions like so: 现在,这些敏感值嵌入在控制器定义中,如下所示:

env:
- name: DB_PASSWORD
  value: password

which are then available inside the Docker container as the $DB_PASSWORD environment variable. 然后在Docker容器中作为$DB_PASSWORD环境变量提供。 All fairly easy. 一切都相当容易。

But reading their documentation on Secrets , they explicitly say that putting sensitive configuration values into your definition breaches best practice and is potentially a security issue. 但是,阅读他们关于Secrets的文档,他们明确表示将敏感配置值放入您的定义中会违反最佳实践,并且可能是一个安全问题。 The only other strategy I can think of is the following: 我能想到的唯一其他策略如下:

  • create an OpenPGP key per user community or namespace 为每个用户社区或命名空间创建一个OpenPGP密钥
  • use crypt to set the configuration value into etcd (which is encrypted using the private key) 使用crypt将配置值设置为etcd(使用私钥加密)
  • create a kubernetes secret containing the private key, like so 创建一个包含私钥的kubernetes秘密, 就像这样
  • associate that secret with the container (meaning that the private key will be accessible as a volume mount), like so 将该秘密与容器相关联(意味着私钥可以作为卷安装访问), 就像这样
  • when the container is launched, it will access the file inside the volume mount for the private key, and use it to decrypt the conf values returned from etcd 当容器启动时,它将访问私有密钥的卷挂载内的文件,并使用它来解密从etcd返回的conf值
  • this can then be incorporated into confd , which populates local files according to a template definition (such as Apache or WordPress config files) 然后可以将其合并到confd中confd根据模板定义(例如Apache或WordPress配置文件)填充本地文件

This seems fairly complicated, but more secure and flexible, since the values will no longer be static and stored in plaintext. 这似乎相当复杂,但更安全和灵活,因为值不再是静态的并以明文形式存储。

So my question, and I know it's not an entirely objective one, is whether this is completely necessary or not? 所以我的问题,我知道这不是一个完全客观的问题,这是否完全是必要的? Only admins will be able to view and execute the RC definitions in the first place; 只有管​​理员才能首先查看和执行RC定义; so if somebody's breached the kubernetes master, you have other problems to worry about. 所以,如果有人违反了kubernetes大师,你还有其他问题需要担心。 The only benefit I see is that there's no danger of secrets being committed to the filesystem in plaintext... 我看到的唯一好处是没有明文提交到文件系统的秘密的危险......

Are there any other ways to populate Docker containers with secret information in a secure way? 有没有其他方法以安全的方式使用秘密信息填充Docker容器?

Unless you have many megabytes of config, this system sounds unnecessarily complex. 除非你有很多兆字节的配置,否则这个系统听起来不必要地复杂。 The intended usage is for you to just put each config into a secret, and the pods needing the config can mount that secret as a volume. 预期用途是让您将每个配置放入一个秘密,并且需要配置的pod可以将该秘密作为卷安装。

You can then use any of a variety of mechanisms to pass that config to your task, eg if it's environment variables source secret/config.sh; ./mybinary 然后,您可以使用各种机制中的任何一种将该配置传递给您的任务,例如,如果它是环境变量source secret/config.sh; ./mybinary source secret/config.sh; ./mybinary is a simple way. source secret/config.sh; ./mybinary是一种简单的方法。

I don't think you gain any extra security by storing a private key as a secret. 我认为通过将私钥存储为秘密,您不会获得任何额外的安全性。

I would personally resolve to user a remote keymanager that your software could access across the net over a HTTPS connection. 我个人决定使用远程密钥管理器,您的软件可以通过HTTPS连接通过网络访问。 For example Keywhiz or Vault would probably fit the bill. 例如KeywhizVault可能适合该法案。

I would host the keymanager on a separate isolated subnet, and configure firewall to only allow access to ip addresses which I expected to need the keys. 我会将密钥管理器托管在一个单独的隔离子网上,并将防火墙配置为仅允许访问我希望需要密钥的IP地址。 Both KeyWhiz and Vault comes with an ACL mechanism, so you may not have to do anything with firewalls at all, but it does not hurt to consider it -- however the key here is to host the keymanager on a separate network, and possible even a separate hosting provider. KeyWhiz和Vault都带有ACL机制,所以你可能根本不需要对防火墙做任何事情,但考虑它并没有什么坏处 - 但是这里的关键是在一个单独的网络上托管密钥管理器,甚至可能一个单独的托管服务商

You local configuration file in the container would contain just the URL of the key service, and possible a credentials to retrieve the key from the keymanager -- the credentials would be useless to an attacker if he didn't match the ACL/IP addresses. 容器中的本地配置文件将仅包含密钥服务的URL,并且可能是从密钥管理器检索密钥的凭证 - 如果攻击者与ACL / IP地址不匹配,则凭据对于攻击者将是无用的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM