Skip to content

Docker Desktop on macOS with VirtioFS maps file permissions incorrectly #6812

@martingd

Description

@martingd

When using VirtioFS to map files from the macOS host filesystem to a Docker container, permissions are not mapped correctly.

  • I have tried with the latest version of Docker Desktop
  • I have tried disabling enabled experimental features
  • I have uploaded Diagnostics
  • Diagnostics ID: 63D33C3F-CAC6-403B-A459-43422AFC78B8/20230419135709

Expected behavior

When bind mounting the local macOS filesystem into a container instance I would expect files permissions (rwx) to be mapped correctly in the container. I would also expect it was possible to change permission on shared files inside the container and see that reflected in the macOS filesystem.

Actual behavior

When using osxfx (legacy) sharing, things work as expected.

When using VirtioFS sharing, I see issues with permissions:

  • If a shared file is readonly in the macOS filesystem, I cannot change its permissions inside the container.
  • If a shared file is writable in the macOS filesystem, I can change it to readonly inside the container. This is seen inside the container but not reflected in the permissions in the macOS filesystem.

Information

  • macOS Version: Ventura, Version 13.2.1 (22D68)
  • Intel chip or Apple chip: Intel
  • Docker Desktop Version: 4.18.0 (104112)

Output of /Applications/Docker.app/Contents/MacOS/com.docker.diagnose check

% /Applications/Docker.app/Contents/MacOS/com.docker.diagnose check 
[2023-04-19T13:41:29.429521000Z][com.docker.diagnose][I] set path configuration to OnHost
Starting diagnostics

[PASS] DD0027: is there available disk space on the host?
[PASS] DD0028: is there available VM disk space?
[PASS] DD0018: does the host support virtualization?
[PASS] DD0001: is the application running?
[PASS] DD0017: can a VM be started?
[PASS] DD0016: is the LinuxKit VM running?
[PASS] DD0011: are the LinuxKit services running?
[PASS] DD0004: is the Docker engine running?
[PASS] DD0015: are the binary symlinks installed?
[PASS] DD0031: does the Docker API work?
[PASS] DD0013: is the $PATH ok?
[PASS] DD0003: is the Docker CLI working?
[PASS] DD0038: is the connection to Docker working?
[PASS] DD0014: are the backend processes running?
[PASS] DD0007: is the backend responding?
[PASS] DD0008: is the native API responding?
[PASS] DD0009: is the vpnkit API responding?
[PASS] DD0010: is the Docker API proxy responding?
[SKIP] DD0030: is the image access management authorized?
[PASS] DD0033: does the host have Internet access?
[PASS] DD0018: does the host support virtualization?
[PASS] DD0001: is the application running?
[PASS] DD0017: can a VM be started?
[PASS] DD0016: is the LinuxKit VM running?
[PASS] DD0011: are the LinuxKit services running?
[PASS] DD0004: is the Docker engine running?
[PASS] DD0015: are the binary symlinks installed?
[PASS] DD0031: does the Docker API work?
[PASS] DD0032: do Docker networks overlap with host IPs?
No fatal errors detected.

Steps to reproduce the behavior

Using osxfx (legacy) sharing

If “osxfx (legacy)” is selected as file sharing implementation, permissions are mapped as expected.

We run a countainer, that maps the folder “macfs" into a container. Inside the container, we create files and manipulate them.

We start the container (in this case Debian Linux) and create two files:

~/tmp/dockerchmod % docker run --rm -it -v$(pwd)/macfs:/root/macfs debian
root@5f0081ad212e:/# cd ~/macfs/
root@5f0081ad212e:~/macfs# (umask 222; touch a)
root@5f0081ad212e:~/macfs# touch b
root@5f0081ad212e:~/macfs# ls -l
total 0
-r--r--r-- 1 root root 0 Apr 14 13:22 a
-rw-r--r-- 1 root root 0 Apr 14 13:22 b

Looking into the macOS host's filesystem we see the same permissions for the two files

~/tmp/dockerchmod % ls -l macfs 
total 0
-r--r--r--  1 mgd  staff  0 Apr 14 15:22 a
-rw-r--r--  1 mgd  staff  0 Apr 14 15:22 b

In the container, we can change the permissions for file a:

root@5f0081ad212e:~/macfs# chmod u+w a
root@5f0081ad212e:~/macfs# ls -l a
-rw-r--r-- 1 root root 0 Apr 14 13:22 a

And we see it reflected in the macOS filesystem:

~/tmp/dockerchmod % ls -l macfs/a
-rw-r--r--  1 mgd  staff  0 Apr 14 15:22 macfs/a

Using VirtioFS sharing

If “VirtioFS” is selected as file sharing implementation, files that are readonly on the macOS host's filesystem cannot have their permissions manipulated in the container.

After removing the files from the previous experiment and switching to “VirtioFS” sharing, we launch a new container instance and create the same two files:

~/tmp/dockerchmod % docker run --rm -it -v$(pwd)/macfs:/root/macfs debian
root@2057dacfa2fa:/# cd ~/macfs/
root@2057dacfa2fa:~/macfs# (umask 222; touch a)
root@2057dacfa2fa:~/macfs# touch b
root@2057dacfa2fa:~/macfs# ls -l  
total 0
-r--r--r-- 1 root root 0 Apr 14 13:29 a
-rw-r--r-- 1 root root 0 Apr 14 13:29 b

The permissions look the same outside the container:

~/tmp/dockerchmod % ls -l macfs 
total 0
-r--r--r--  1 mgd  staff  0 Apr 14 15:29 a
-rw-r--r--  1 mgd  staff  0 Apr 14 15:29 b

However, attempting to modify permissions for file a inside the container fails:

root@2057dacfa2fa:~/macfs# chmod u+w a
chmod: changing permissions of 'a': Permission denied

Changing the permissions of file b is possible:

root@2057dacfa2fa:~/macfs# chmod u-w b
root@2057dacfa2fa:~/macfs# ls -l b
-r--r--r-- 1 root root 0 Apr 14 13:29 b

However, The permissions for b has not changed outside the container:

~/tmp/dockerchmod % ls -l macfs/b
-rw-r--r--@ 1 mgd  staff  0 Apr 14 15:29 macfs/b

Please note that file b now has extended attributes set so we dump them:

~/tmp/dockerchmod % xattr macfs/b
com.docker.grpcfuse.ownership

We can change b back inside the container:

root@2057dacfa2fa:~/macfs# chmod u+w b
root@2057dacfa2fa:~/macfs# ls -l b
-rw-r--r-- 1 root root 0 Apr 14 13:29 b

But if we remove w from file b in the host's filesystem:

~/tmp/dockerchmod % ls -l macfs 
total 0
-r--r--r--  1 mgd  staff  0 Apr 14 15:29 a
-r--r--r--@ 1 mgd  staff  0 Apr 14 15:29 b

Then, this is not reflected inside the container:

root@2057dacfa2fa:~/macfs# ls -l
total 0
-r--r--r-- 1 root root 0 Apr 14 13:29 a
-rw-r--r-- 1 root root 0 Apr 14 13:29 b

Now, neither a nor b can have their permissions changed inside the container:

root@2057dacfa2fa:~/macfs# chmod u+w a b
chmod: changing permissions of 'a': Permission denied
chmod: changing permissions of 'b': Permission denied
root@2057dacfa2fa:~/macfs# ls -l
total 0
-r--r--r-- 1 root root 0 Apr 14 13:29 a
-rw-r--r-- 1 root root 0 Apr 14 13:29 b
root@2057dacfa2fa:~/macfs# chmod u-w a b
chmod: changing permissions of 'a': Permission denied
chmod: changing permissions of 'b': Permission denied
root@2057dacfa2fa:~/macfs# ls -l
total 0
-r--r--r-- 1 root root 0 Apr 14 13:29 a
-rw-r--r-- 1 root root 0 Apr 14 13:29 b

However, we can still delete the files inside the container:

root@2057dacfa2fa:~/macfs# rm a b
root@2057dacfa2fa:~/macfs# ls -l
total 0

And, they are also deleted from the host filesystem:

~/tmp/dockerchmod % ls -l macfs 
total 0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions