Securing Kubernetes secret files for source control?

2/28/2016

According to the Kubernetes secrets docs, creating a secret is as easy as base64-encoding the data and placing it in a file.

How then, if base64 can be decoded as easily as it's encoded, can we secure/encrypt the secret values in the file? It would be nice to be able to commit the secret files into source control, however simply committing the file with base64-encoded data is in no way secure.

For example, here is the example given in the docs:

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  password: dmFsdWUtMg0K
  username: dmFsdWUtMQ0K

If you went to base64decode.org, you would see that those password/username values simply are "value-2". This file is unfit for source control. How can we secure the data in the file so that it is safe for source control? Or is this considered bad practice, and we should just add the file to .gitignore?

-- dcgoss
base64
deployment
encryption
kubernetes
security

3 Answers

4/9/2019

I'd deploy them with ansible, and encrypt the secrets using ansible-vault, so they could be inside the repository. In addition, they could be stored as text, applying the base64 filter over a template.

Anyway, as it was said before, secrets are not secure. They are just encoded in base64 and could be decoded with:

kubectl get secret mysecret -o jsonpath="{.data.username}" | base64 -d
kubectl get secret mysecret -o jsonpath="{.data.password}" | base64 -d

(what is very useful, by the way)

-- MagMax
Source: StackOverflow

3/1/2016

For confidential secret keys, can you store them in etcd and retrieve them with confd ?

otherwise, if you really want them in scm, then can you use git-crypt? https://github.com/AGWA/git-crypt

-- theRemix
Source: StackOverflow

2/28/2016

It isn't base64 encoded for security, it is to allow binary content to be stored in secrets. You likely should not commit secret definitions to source control.

-- Jordan Liggitt
Source: StackOverflow