3

I'm trying to store a string array as a secret; I have this secrets.yml file that I'm using in my local environment and works perfectly (values are for explanation purposes only):

secrets.yml

passwordz:
  - pass_001
  - pass_002
  - pass_003

The idea is to be able to store multiple passwords, and I want to use them as part of a k8s secret but had no luck so far; something like this:

k8s-secrets.yml

apiVersion: v1
kind: Secret
metadata:
  name: master-passwordz
type: Opaque
data:
  secrets.yml: |-
    passwordz: CiAgLSBwYXNzXzAwMQogIC0gcGFzc18wMDIKICAtIHBhc3NfMDAz

At the time to try to apply this secret:

kubectl apply -f ./k8s-secrets.yml

I'm getting the following error:

Error from server (BadRequest): error when creating "k8s-secrets.yml": Secret in version "v1" cannot be handled as a Secret: v1.Secret.ObjectMeta: v1.ObjectMeta.TypeMeta: Kind: Data: decode base64: illegal base64 data at input byte 3

Any idea if it's possible to accomplish this?

Cas1337
  • 141
  • 15

3 Answers3

3

Could you try using "stringData" instead of "data". AFAIK this key should be used when you don't provide complete base64 encoded data in Secrets.

alexzimmer96
  • 996
  • 6
  • 14
2

No, the values must be a []byte, i.e. a string of some kind. You would have to store your array with some kind of encoding (usually JSON) so it's a simple string.

coderanger
  • 52,400
  • 4
  • 52
  • 75
0
apiVersion: v1
kind: Secret
metadata:
  name: master-passwordz
type: Opaque
data:
    passwordz__0: pass_001
    passwordz__1: pass_002
    passwordz__2: pass_003

How about doing it this way?