<p>I am trying to pass user credentials via Kubernetes secret to a mounted, password protected directory inside a Kubernetes Pod.
The NFS folder <code>/mount/protected</code> has user access restrictions, i.e. only certain users can access this folder.</p>

<p>This is my Pod configuration:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  volumes:
  - name: my-volume
    hostPath:
      path: /mount/protected
      type: Directory
    secret:
      secretName: my-secret
  containers:
  - name: my-container
    image: &lt;...&gt;
    command: ["/bin/sh"]
    args: ["-c", "python /my-volume/test.py"]
    volumeMounts:
    - name: my-volume
      mountPath: /my-volume
</code></pre>

<p>When applying it, I get the following error:</p>

<pre><code>The Pod "my-pod" is invalid:
* spec.volumes[0].secret: Forbidden: may not specify more than 1 volume type
* spec.containers[0].volumeMounts[0].name: Not found: "my-volume"
</code></pre>

<p>I created my-secret according to the following guide:<br>
<a href="https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-secret" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-secret</a><br>
So basically:</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: my-secret
data:
  username: bXktYXBw
  password: PHJlZGFjdGVkPg==
</code></pre>

<p>But when I mount the folder <code>/mount/protected</code> with:</p>

<pre><code>spec:
  volumes:
  - name: my-volume
    hostPath:
      path: /mount/protected
      type: Directory
</code></pre>

<p>I get a permission denied error <code>python: can't open file '/my-volume/test.py': [Errno 13] Permission denied</code> when running a Pod that mounts this volume path.</p>

<p>My question is how can I tell my Pod that it should use specific user credentials to gain access to this mounted folder?</p>

Jonas
<p>I eventually figured out how to pass user credentials to a mounted directory within a Pod by using CIFS Flexvolume Plugin for Kubernetes (<a href="https://github.com/fstab/cifs" rel="nofollow noreferrer">https://github.com/fstab/cifs</a>).
With this Plugin, every user can pass her/his credentials to the Pod.
The user only needs to create a Kubernetes secret (<code>cifs-secret</code>), storing the username/password and use this secret for the mount within the Pod.
The volume is then mounted as follows:</p>

<pre><code>  (...)
  volumes:
  - name: test
    flexVolume:
      driver: "fstab/cifs"
      fsType: "cifs"
      secretRef:
        name: "cifs-secret"
      options:
        networkPath: "//server/share"
        mountOptions: "dir_mode=0755,file_mode=0644,noperm"
</code></pre>
