Read vault secrets as an environment variable inside k8s pod

Hi,

I’ve a bunch of microservices based on NodeJs. I would like to read the secrets where I injected them via vault-agent as a sidecar as an environment variable.

I can able to access the secrets into vault’s pod but when I deploy my application it throws a below error. Can it be related with helm template somehow ?

kubectl logs -f docuplatform-backend-stage-cdd559c8f-7vs2 -n docu-platform -c vault-agent-init
`2021-04-27T15:25:45.879Z [ERROR] runtime error encountered: error="template server: (dynamic): execute: template: :2:39: executing "" at <.Data.data.auth_client_id_stage>: nil pointer evaluating interface {}.auth_client_id_stage"`

secrets

/ $ vault kv get secret/data/docuplatform-backend
============== Data ==============
Key                         Value
---                         -----
auth_client_id_stage        12312313123
auth_client_secret_stage    12314234234

deployment.yaml

  template:
    metadata:
      annotations:
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-inject-secret-config: "secret/data/docuplatform-backend"
        vault.hashicorp.com/agent-inject-template-config: |
      {{`{{ with secret "secret/data/docuplatform-backend" -}}
        export auth_client_id_stage="{{ .Data.data.auth_client_id_stage }}",
        export auth_client_secret_stage="{{ .Data.data.auth_client_secret_stage }}"
      {{- end }}`}}
        vault.hashicorp.com/role: docuplatform-backend
    spec:
      serviceAccountName: vault-auth
      containers:
        - name: docuplatform-backend1"
          command: ["/bin/sh", "-c"]
          args: [" ./vault/secrets/config && printenv"]

Did you ever solve this ? ran into the same issue here

This is the behaviour that results if .Data.data evaluates to nil because there was no nested data in the response.