<p>I have a pod that runs containers which require access to sensitive information like API keys and DB passwords. Right now, these sensitive values are embedded in the controller definitions like so:</p>

<pre><code>env:
- name: DB_PASSWORD
  value: password
</code></pre>

<p>which are then available inside the Docker container as the <code>$DB_PASSWORD</code> environment variable. All fairly easy.</p>

<p>But reading their documentation on <a href="http://kubernetes.io/docs/user-guide/secrets/" rel="nofollow noreferrer">Secrets</a>, they explicitly say that putting sensitive configuration values into your definition breaches best practice and is potentially a security issue. The only other strategy I can think of is the following:</p>

<ul>
<li>create an OpenPGP key per user community or namespace</li>
<li>use <a href="https://github.com/xordataexchange/crypt" rel="nofollow noreferrer">crypt</a> to set the configuration value into etcd (which is encrypted using the private key)</li>
<li>create a kubernetes secret containing the private key, <a href="https://github.com/kubernetes/kubernetes/blob/master/docs/user-guide/secrets/secret.yaml" rel="nofollow noreferrer">like so</a></li>
<li>associate that secret with the container (meaning that the private key will be accessible as a volume mount), <a href="https://github.com/kubernetes/kubernetes/blob/master/docs/user-guide/secrets/secret-pod.yaml#L10-L17" rel="nofollow noreferrer">like so</a></li>
<li>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</li>
<li>this can then be incorporated into <a href="https://github.com/kelseyhightower/confd" rel="nofollow noreferrer">confd</a>, which populates local files according to a template definition (such as Apache or WordPress config files)</li>
</ul>

<p>This seems fairly complicated, but more secure and flexible, since the values will no longer be static and stored in plaintext.</p>

<p>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; so if somebody's breached the kubernetes master, you have other problems to worry about. The only benefit I see is that there's no danger of secrets being committed to the filesystem in plaintext...</p>

<p>Are there any other ways to populate Docker containers with secret information in a secure way?</p>

<p>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.</p>

<p>You can then use any of a variety of mechanisms to pass that config to your task, e.g. if it's environment variables <code>source secret/config.sh; ./mybinary</code> is a simple way.</p>

<p>I don't think you gain any extra security by storing a private key as a secret.</p>
