Secrets cannot be assigned as environment variables

My purpose is to assign secrets as key-value pairs as environment variables.
I checked the the example but it doesn’t work as explained; so I changed a bit.

Here is my config:

  podAnnotations: "/run/secrets/" 'true' "update" 'myproject-microservices' 'kv/data/myproject/keycloak/access.env' |
      {{ with secret "kv/data/myproject/keycloak/access.env" -}}
        export KEYCLOAK_MYPROJECT_ISSUERXXX="{{ index "keycloak-myproject-issuer" }}"
      {{- end }}


            ["bash", "-c", ". /vault/secrets/keycloak"]

I check the path:

$ POD=myproject-backend-common-dms-6995f5bd54-jtvzf

$ k exec -n myproject $POD -c "$CONTAINER" -- \
>   printenv | grep XXX

$ k exec -n myproject $POD -c "$CONTAINER" -- \
>   cat /vault/secrets/keycloak

$ k exec -n myproject $POD -c "$CONTAINER" -- \
>   ls -aln /vault/secrets/keycloak
-rw-r--r-- 1 100 1000 82 Dec  6 04:33 /vault/secrets/keycloak

Everything looks fine but there is no environment variables. :frowning:

I am pulling my hairs here; could you please advise what I am missing?

Thanks & Regards

I also tried that one but it didn’t work too.

KEYCLOAK_MYPROJECT_ISSUERXXX="{{ index "keycloak-myproject-issuer" }}"


["bash", "-c", "export /vault/secrets/keycloak"]

export KEYCLOAK_MYPROJECT_ISSUERXXX="{{ index "keycloak-myproject-issuer" }}"


["bash", "-c", "/vault/secrets/keycloak"]

no luck :unamused:

Hi @tirelibirefe, the environment variables will not show up when you run printenv in the container, because they’re only set for the entrypoint command (probably process 1). So to see what its environment variables are, exec into the container and take a look at /proc/1/environ:

k exec -n myproject $POD -c "$CONTAINER" -- cat /proc/1/environ

The output will be a little squished but that’ll tell you for sure what’s set.

And so that the container stays up to inspect it, you may want to do something like this for cmd and args:

          ['bash', '-c']
          ['. /vault/secrets/keycloak' && /bin/sleep 600']

Hello @tvoran
Thanks for your reply.
I cannot use…

          ['bash', '-c']

…because it overrides ENTRYPOINT in Dockerfile. My Dockerfile ends with that:

[ENTRYPOINT ["dotnet", "WebAPI.dll"]

I tried …

          ['. /vault/secrets/keycloak' && /bin/sleep 600']

…but it didn’t work.

I tried…

          args: [bash; -c; . /vault/secrets/keycloak && /bin/sleep 60]

…it didn’t work, too.

@tvoran could you please advise?

The problem here is that you are randomly guessing various permutations of YAML and shell syntax which are incorrect.

Instead you should be more closely following the example you referenced. Taking into account what you have said about the existing entrypoint, I think you are going to need:

command: ['sh', '-c', '. /vault/secrets/keycloak && dotnet WebAPI.dll']

Yes, you will need to redefine the full command, overriding the Dockerfile ENTRYPOINT - that’s an unavoidable feature of this injection technique.

You reprimand me but no problem…

Wish to able to say it worked but sorry, it didn’t work what you advised.

Sorry, I meant it not as a reprimand, but an explanation of part of why you’re finding it difficult to get useful answers from this forum.

This is a community help forum where people answering questions are doing so not for any financial reward, but just for the satisfaction of having helped someone.

The point being, the easier you make it for people to help you, the more likely you are to be helped.

You are currently doing two things which make it seem it will be very hard to provide help via a forum:

  • You’re making up lots of syntaxes, seemingly at random (you’re not saying why you’re trying these syntaxes).

  • When something doesn’t work, all you’re saying is “it didn’t work” - no details, no error messages, nothing that would provide insight into how and why it didn’t work.

Please remember that we cannot see your screen and we cannot read your mind - you need to tell us what you see on your screen and what you’re thinking, to make it possible to help you.