canonical / canonical/multipass
Should multipass bypass permissions on Read Only Bind Mounts mounted into the vm?
- Dominant language
- C++
- Stars
- 9.2k
- Forks
- 828
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 44
Description
I have a desire to start moving development to virtual machines while mounting configuration files shared between multiple environments as read only in the VM. This is so files could not be modified by code running in the VM and possibly pushing a vulnerability to the host or other VMs. The research I had done led me to conclude that the most straight forward and secure way to do this would be to create a read only bind mount on the host and mount this into the virtual machine. However, once implemented I found that while the host respected the the RO permissions on the bind mount even for root, the VM ignored the RO permissions and was able to update the files within the bind mount.
**Is this expected?**
Perhaps I am missing some deeper knowledge on mounts and what is expected here. The following script will demonstrate the exact steps to replicate this.
```sh
#!/bin/bash
set -euo pipefail
set -x
# Step 1
mkdir -p test/read-write-src test/read-only-bind-mount
# Step 2
sudo mount -o bind,ro test/read-write-src test/read-only-bind-mount
sleep 1
# Step 3
touch test/read-write-src/{a,b,c}.txt || { echo "Error: Failed to create files in read-write-src directory"; exit 1; }
# Step 4
if touch test/read-only-bind-mount/d.txt 2>/dev/null; then
echo "Error: Successfully touched a file in read-only-bind-mount directory. This should have failed."
else
echo "Correct: Cannot write to read-only-bind-mount directory. This is expected."
fi
# Step 5
multipass launch --name vm-bypass-ro-bm
# Step 6
multipass mount "${PWD}/test/read-only-bind-mount" vm-bypass-ro-bm:/read-only-bind-mount
# Step 7
multipass exec vm-bypass-ro-bm -- touch /read-only-bind-mount/security-breach-from-multipass.txt
# Step 8
if [[ -f "test/read-write-src/security-breach-from-multipass.txt" ]]; then
echo "Error: Security breach! A file was written from inside the VM to the read-only-bind-mount directory on the host."
else
echo "Correct: No file was written from inside the VM to the read-only-bind-mount directory on the host. This is expected."
fi
```
#!/bin/bash
set -euo pipefail
set -x
# Step 1
mkdir -p test/read-write-src test/read-only-bind-mount
# Step 2
sudo mount -o bind,ro test/read-write-src test/read-only-bind-mount
sleep 1
# Step 3
touch test/read-write-src/{a,b,c}.txt || { echo "Error: Failed to create files in read-write-src directory"; exit 1; }
# Step 4
if touch test/read-only-bind-mount/d.txt 2>/dev/null; then
echo "Error: Successfully touched a file in read-only-bind-mount directory. This should have failed."
else
echo "Correct: Cannot write to read-only-bind-mount directory. This is expected."
fi
# Step 5
multipass launch --name vm-bypass-ro-bm
# Step 6
multipass mount "${PWD}/test/read-only-bind-mount" vm-bypass-ro-bm:/read-only-bind-mount
# Step 7
multipass exec vm-bypass-ro-bm -- touch /read-only-bind-mount/security-breach-from-multipass.txt
# Step 8
if [[ -f "test/read-write-src/security-breach-from-multipass.txt" ]]; then
echo "Error: Security breach! A file was written from inside the VM to the read-only-bind-mount directory on the host."
else
echo "Correct: No file was written from inside the VM to the read-only-bind-mount directory on the host. This is expected."
fi
Software versions are:
```bash
2002$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
2110$ uname -a
Linux ad-linux 5.4.0-148-generic #165-Ubuntu SMP Tue Apr 18 08:53:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
2111$ multipass --version
multipass 1.11.0
multipassd 1.11.0
```
Contributor guide
Assessment
This issue has not been assessed yet.