Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding of Kubernetes Secrets fails when Secret has both data and stringData #520

Closed
johanfleury opened this issue Sep 12, 2024 · 1 comment · Fixed by #543
Closed

Decoding of Kubernetes Secrets fails when Secret has both data and stringData #520

johanfleury opened this issue Sep 12, 2024 · 1 comment · Fixed by #543
Labels
bug Something isn't working

Comments

@johanfleury
Copy link

johanfleury commented Sep 12, 2024

When a Secret has both data and stringData, vals fails to decode it with mapping key "stringData" already defined at line x.

My guess from the error message is that vals tries to add a new stringData key instead of merging data with the existing one.

  • With only data or stringData, vals works well:

    $ cat secret.yaml
    ---
    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
      name: test
    data:
      MY_SUPER_SECRET: "[REDACTED]"
    
    $ vals eval --decode-kubernetes-secrets < secret.yaml
    apiVersion: v1
    data:
      MY_SUPER_SECRET: MTIzYWJj
    kind: Secret
    metadata:
      name: test
    type: Opaque
    
    $ cat secret.yaml
    ---
    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
      name: test
    stringData:
      MY_SUPER_SECRET: "[REDACTED]"
    
    $ vals eval --decode-kubernetes-secrets < secret.yaml
    apiVersion: v1
    data:
      MY_SUPER_SECRET: MTIzYWJj
    kind: Secret
    metadata:
      name: test
    type: Opaque
    
  • With both data and stringData, regardless of where the reference is set, vals fails:

    $ cat secret.yaml
    ---
    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
      name: test
    data:
      foo: YmFy
    stringData:
      MY_SUPER_SECRET: "[REDACTED]"
    
    $ vals eval --decode-kubernetes-secrets < secret.yaml
    yaml: unmarshal errors:
      line 9: mapping key "stringData" already defined at line 7
    
    $ vals ksdecode -f secret.yaml
    yaml: unmarshal errors:
      line 9: mapping key "stringData" already defined at line 7
    
    $ cat secret.yaml
    ---
    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
      name: test
    data:
      MY_SUPER_SECRET: "[REDACTED]"
    stringData:
      foo: bar
    
    $ vals eval --decode-kubernetes-secrets < secret.yaml
    yaml: unmarshal errors:
      line 9: mapping key "stringData" already defined at line 7
    
    $ vals ksdecode -f secret.yaml
    yaml: unmarshal errors:
      line 9: mapping key "stringData" already defined at line 7
    

I’m running the latest version:

$ vals version
Version: 0.37.5
Git Commit: 4e977c561c3f09b8f16845e55cb8b72f1ae4d8b6
@johanfleury johanfleury changed the title Decoding of Kubernetes Secrets fails when Secrets has both data and stringData Decoding of Kubernetes Secrets fails when Secret has both data and stringData Sep 12, 2024
@yxxhero
Copy link
Member

yxxhero commented Oct 13, 2024

@johanfleury I will try to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants