So I just learned a super useful k8s fundamental I missed, and then discovered it has a security vulnerability associated with it, and came up with a resolution.
TLDR:
You can have cleartext multiline strings/textfiles as secret.yaml's in your secret repo !!! :)
2023 Update: I removed recommendation of storing secrets in HashiVault, I no longer recommend it since it has too much overhead. Now my go to recommendations are:
- Storing Cleartext secrets in a manage service equivalent to the secrets management part of HashiVault. Like: AWS Secrest Manager / GCP Secrets Manager / Azure Key Vault
- Using Mozilla Sops and AWS/GCP/Azure KMS to store Sops/KMS Encrypted Secrest in Git Repos
(I personally prefer SOPS as I find it a bit easier to store versioned config and secrets next to each other.)
cleartext-appsettings.secret.yaml
appsettings.Dummy.json is the default file name (key of the secret)
(I use the word default file name as you could override the file name by specifying some rarely used settings in a pod's yaml that mounts the secret as a volume.)
(and the clear text json code is the file contents (value of the secret)
apiVersion: v1
kind: Secret
metadata:
name: appsettings
namespace: api
type: Opaque
stringData:
appsettings.Dummy.json: |-
{
"Dummy": {
"Placeholder": {
"Password": "blank"
}
}
}
When I
kubectl apply -f cleartext-appsettings.secret.yaml
kubectl get secret appsettings -n=api -o yaml
The secret shows up cleartext in the annotation...
apiVersion: v1
data:
appsettings.Dummy.json: ewogICJEdW1teSI6IHsKICAgICJQbGFjZWhvbGRlciI6IHsKICAgICAgIlBhc3N3b3JkIjogImJsYW5rIgogICAgfQogIH0KfQ==
kind: Secret
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Secret","metadata":{"annotations":{},"name":"appsettings","namespace":"api"},"stringData":{"appsettings.Dummy.json":"{\n \"Dummy\": {\n \"Placeholder\": {\n \"Password\": \"blank\"\n }\n }\n}"},"type":"Opaque"}
creationTimestamp: 2019-01-31T02:50:16Z
name: appsettings
namespace: api
resourceVersion: "4909"
selfLink: /api/v1/namespaces/api/secrets/appsettings
uid: f0629027-2502-11e9-9375-6eb4e0983acc
Apparently the yaml used to create the secret showing up in the annotation is expected behavior for kubectl apply -f secret.yaml since 2016/has been posted as a bug report, but issue closed without resolution/they're ignoring it vs fixing it.
If you're original secret.yaml is base64'd the annotation will at least be base64'd but in this scenario it's straight up non-base64'd human readable clear text.
The following counteracts the leak by imperatively deleting the annotation:
kubectl apply -f cleartext-appsettings-secret.yaml -n=api
kubectl annotate secret appsettings -n=api kubectl.kubernetes.io/last-applied-configuration-