<p>I have this kubeconfig file</p>
<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: ***
    server: ***
  name: ***
contexts:
- context:
    cluster: ***
    user: webhook
  name: *****
current-context: *****
kind: Config
preferences: {}
users:
- name: webhook
  user:
    token: ${MY_APIKEY}
</code></pre>
<p>I am storing it in secret in github that is named <code>DEV_CLUSTER_KUBECONF</code></p>
<p>I am also storing MY_APIKEY in GitHub secrets</p>
<p>Then I have this actions workflow file whose purpose is the write the content into a file and then populate it with a token coming form github actions.</p>
<pre><code>name: wfl

on:
  push:
env:
  DEV_CLUSTER_KUBECONF: ${{ secrets.DEV_CLUSTER_KUBECONF }}

jobs:
  j1:
    needs: build
    runs-on: ....
    container:
      image: .....
    steps:
      - name: pull kubeconfig
        run: |
          mkdir kubeconf
          touch kubeconf.conf
          echo $DEV_CLUSTER_KUBECONF &gt;&gt; kubeconf/kubeconf.conf

      - name: envsub kube.conf
        run: |
          cat kubeconf/kubeconf.conf | envsubst &gt; populated_kube.conf
        env:
          MY_APIKEY: ${{ secrets.MY_APIKEY }}
      - name: export KUBECONFIG path
        run: echo &quot;KUBECONFIG=populated_kube.conf&quot; &gt;&gt; $GITHUB_ENV
      - name: kubectl
        run: kubectl get po
</code></pre>
<p>This is a simplified version of my work. I prefer to keep it three steps. I mean I want to store the kubeconfig with the api key placeholder separate from the api key in the github secrets.</p>
<p>However, right now it is not connecting to k8s.</p>
<p>I used to keep kubeconf/kubeconf.conf in the repo and after checkout, do the envsubt on that file and it was working. I am not sure why it is not working now. seems like <code>kubeconf/kubeconf.conf</code> is not correct but when I try to print it and debug it is showing *******.</p>
<p>Any idea how to fix this?</p>

Amin Ba
<p>You need to properly quote your variables. Consider what happens if I create a multiline environment variable:</p>
<pre><code>MVAR='this
is
a
test'
</code></pre>
<p>And then try to echo it without using quotes:</p>
<pre><code>$ echo $MYVAR
this is a test
</code></pre>
<p>Compare that to the result when using quotes:</p>
<pre><code>$ echo &quot;$MYVAR&quot;
this
is
a
test
</code></pre>
<hr />
<p>So you need to edit your action to read:</p>
<pre><code>      - name: pull kubeconfig
        run: |
          mkdir kubeconf
          echo &quot;$DEV_CLUSTER_KUBECONF&quot; &gt; kubeconf/kubeconf.conf
</code></pre>
<p>(I've removed an unnecessary <code>touch kubeconf.conf</code> here, because that wasn't creating the file in the correct path and wasn't necessary in any case.)</p>
<p>If that doesn't work, the first thing you should do is add a <code>cat kubeconf/kubeconf.conf</code> to your workflow so you can inspect the generated file.</p>
