<p>I have a secret being used as env var in another env var as follows:</p>
<pre><code>- name: &quot;PWD&quot;
  valueFrom:
    secretKeyRef:
      name: &quot;credentials&quot;
      key: &quot;password&quot;
- name: HOST
  value: &quot;xyz.mongodb.net&quot;
- name: MONGODB_URI 
  value: &quot;mongodb+srv://user:$(PWD)@$(HOST)/db_name?&quot;
</code></pre>
<p>When i exec into the container and run <code>env</code> command to see the values of env i see -</p>
<pre><code>mongodb+srv://user:password123  
@xyz.mongodb.net/db_name?
</code></pre>
<p>The container logs show error as authentication failure.
Is this something that is expected to work in kubernetes ? There <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-interdependent-environment-variables/" rel="nofollow noreferrer">docs</a> talk about dependent env vars but do not give example using secrets. Did not find clear explanation on this after extensive search. Only found <a href="https://joeblogs.technology/2020/12/concatenating-kubernetes-secrets-for-environment-variables/" rel="nofollow noreferrer">this</a> one article doing something similar.</p>
<p>Some points to note -</p>
<ul>
<li>The secret is a sealed secret.</li>
<li>This is the final manifest's contents, but all this is templated using helm.</li>
<li>The value is being used inside a spring boot application</li>
</ul>
<p>Is the new line after <code>123</code> expected ?
If this evaluation of env from a secret in another env is possible then what am I doing wrong here ?</p>

Harshit Nagar
<p>The issue was with the command used to encode the secret - <code>echo &quot;pasword&quot; | base64</code>. The echo adds a newline character at the end of the string. Using <code>echo -n &quot;password&quot; | base64</code> fixed the secret.
Closing the issue.</p>
