<p>I would like to access a Windows file share share (SMB3) from a docker container, but I do not want to compromise the security of the host machine.  All the guides I have read state that I need to use either the <code>--privileged</code> flag or <code>--cap-add SYS_ADMIN</code> capability.</p>
<p>Here is the command I use:</p>
<blockquote>
<p>mount -t cifs -o
username='some_account@mydomain.internal',password='some_password'
//192.168.123.123/MyShare /mnt/myshare</p>
</blockquote>
<p>Which results in the message:</p>
<blockquote>
<p>Unable to apply new capability set.</p>
</blockquote>
<p>When I apply the <code>--cap-add SYS_ADMIN</code> capability the mount command works fine, but I understand this exposes the host to obvious security vulnerabilities.</p>
<p>I have also read the suggestion in this StackOverflow question (<a href="https://stackoverflow.com/questions/27989751/mount-smb-cifs-share-within-a-docker-container">Mount SMB/CIFS share within a Docker container</a>) to mount the volume locally on the server that runs docker. This is undesirable for two reasons, firstly, the container is orchestrated by a Rancher Kubernetes cluster and I don't know how to achieve what is described by nPcomp using Rancher, and two, this means the volume is accessible to the docker host. I'd prefer only the container have access to this share via the credentials given to it via secrets.</p>
<p>My question is: is there way to mount a CIFS/SMB3 share in a docker container (within Kubernetes) without exposing the host to privilege escalation vulnerabilities and protecting the credentials? Many thanks.</p>

<p>After more research I have figured out how to do this.   There is a Container Storage Interface (CSI) driver for SMB called <strong>SMB CSI Driver for Kubernetes</strong> (<a href="https://github.com/kubernetes-csi/csi-driver-smb" rel="noreferrer">https://github.com/kubernetes-csi/csi-driver-smb</a>).</p>
<p>After installing the CSI driver using helm (<a href="https://github.com/kubernetes-csi/csi-driver-smb/tree/master/charts" rel="noreferrer">https://github.com/kubernetes-csi/csi-driver-smb/tree/master/charts</a>) you can follow the example at <a href="https://github.com/kubernetes-csi/csi-driver-smb/blob/master/deploy/example/e2e_usage.md" rel="noreferrer">https://github.com/kubernetes-csi/csi-driver-smb/blob/master/deploy/example/e2e_usage.md</a> (<strong>Option #2 Create PV/PVC</strong>) to create a Persistent Volume (PV) and Persistent Volume Claim (PVC) which mounts the SMB3 share.</p>
<p>Then you create your container and give it the relevant Persistent Volume Claim, specifying you want to mount it as /mnt/myshare etc.</p>
<p>I tested this and it gets deployed to multiple worker nodes automatically and  works well, without needing the <code>privileged</code> flag or <code>--cap-add SYS_ADMIN</code> to be given to the containers.</p>
<p>This supports SMB3 and even authentication &amp; encryption. To enable encryption go to your Windows Server &gt; File and Storage Services, select the share, Properties &gt; Settings &gt; Encrypt Data Access.</p>
<p>Wireshark shows all the SMB traffic is encrypted. Only thing I don't recall is if you have to install <code>cifs-utils</code> manually first, since I had already done this on all my nodes I wasn't able to test.</p>
<p>Hope this helps somebody.</p>
