<p>If i create a secret from an id_rsa file using kubectl as:</p>

<pre><code>kubectl create secret generic hcom-secret --from-file=ssh-privatekey=./.ssh/id_rsa
</code></pre>

<p>And then mount the secret into the container</p>

<pre><code>"volumeMounts": [
        {"name": "cfg", "readOnly": false, "mountPath": "/home/hcom/.ssh"}
      ]

"volumes": [
      {"name": "cfg", "secret": { "secretName": "hcom-ssh" }}
    ],
</code></pre>

<p>The resultant file is not id_rsa but ssh-privatekey and the permits that are on it are not 600 which ssh expects</p>

<p>Is this a correct approach, or can anyone please detail how this should be done?</p>

<p>The official Kubernetes docs for secrets cover <a href="https://kubernetes.io/docs/concepts/configuration/secret/#use-case-pod-with-ssh-keys" rel="nofollow noreferrer">this exact use-case</a>.</p>
<p>To create the secret, use:</p>
<pre><code>$ kubectl create secret generic my-secret --from-file=ssh-privatekey=/path/to/.ssh/id_rsa --from-file=ssh-publickey=/path/to/.ssh/id_rsa.pub
</code></pre>
<p>To mount the secret in your containers, use the following Pod config:</p>
<pre><code>{
  &quot;kind&quot;: &quot;Pod&quot;,
  &quot;apiVersion&quot;: &quot;v1&quot;,
  &quot;metadata&quot;: {
    &quot;name&quot;: &quot;secret-test-pod&quot;,
    &quot;labels&quot;: {
      &quot;name&quot;: &quot;secret-test&quot;
    }
  },
  &quot;spec&quot;: {
    &quot;volumes&quot;: [
      {
        &quot;name&quot;: &quot;secret-volume&quot;,
        &quot;secret&quot;: {
          &quot;secretName&quot;: &quot;my-secret&quot;
        }
      }
    ],
    &quot;containers&quot;: [
      {
        &quot;name&quot;: &quot;ssh-test-container&quot;,
        &quot;image&quot;: &quot;mySshImage&quot;,
        &quot;volumeMounts&quot;: [
          {
            &quot;name&quot;: &quot;secret-volume&quot;,
            &quot;readOnly&quot;: true,
            &quot;mountPath&quot;: &quot;/etc/secret-volume&quot;
          }
        ]
      }
    ]
  }
}
</code></pre>
<p>Kubernetes doesn't actually have a way to control file permissions for a secret as of now, but <a href="https://github.com/kubernetes/kubernetes/pull/25285" rel="nofollow noreferrer">a recent Pull Request</a> did add support for changing the path of secrets. This support was added with <code>1.3</code> as per <a href="https://github.com/kubernetes/kubernetes/issues/26663#issuecomment-223346911" rel="nofollow noreferrer">this comment</a></p>
<p>Here are the permissions related Github Issues:</p>
<ul>
<li><a href="https://github.com/kubernetes/kubernetes/issues/4789" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/4789</a></li>
<li><a href="https://github.com/kubernetes/kubernetes/issues/28317" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/28317</a></li>
</ul>
