-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file deleted regardless of permission #5944
Comments
I just updated to Docker 4.0.0.12 I can reproduce this again exactly as described. |
@jsgro thanks for the report. Generally on Unix the ability to The prompt ( /* !ISDIR */
if ((!(flags & FILEUTILS_FORCE)
&& access(path, W_OK) < 0
&& !S_ISLNK(path_stat.st_mode)
&& isatty(0))
|| (flags & FILEUTILS_INTERACTIVE)
) {
fprintf(stderr, "%s: remove '%s'? ", applet_name, path);
if (!bb_ask_y_confirmation())
return 0;
} so the user is prompted for files (
It's the write access check which is causing the issue. We use Linux FUSE to mount the host filesystem. There are 2 permission models: https://elixir.bootlin.com/linux/latest/source/fs/fuse/dir.c#L1197 . We delegate the permission checks to the server (by not setting However we also care about performance. Many filesystem options performed by Linux will be prefixed by a So it's a combination of
results in the loss of the However all is not lost; if you would like 100% native Linux access control checks, you can store your data in a "named volume" which resides inside the Linux filesystem. For example:
Another possibility is to use "dev environments" https://docs.docker.com/desktop/dev-environments/ which store the code in Linux (so 100% native filesystem semantics) while also allowing you to seamlessly access everything from your IDE (as well as push/pull the environment to share it with colleagues etc) |
Good point, I forgot about that one. I think you'll see the same behavior directly on Linux; FROM alpine
RUN mkdir -p /test/readonly-dir /test/writable-dir \
&& chmod -R 0755 /test/readonly-dir \
&& chmod -R 0777 /test/writable-dir \
&& echo "file1" > /test/readonly-dir/readonly-file1.txt \
&& echo "file2" > /test/readonly-dir/readonly-file2.txt \
&& echo "file3" > /test/writable-dir/readonly-file3.txt \
&& echo "file4" > /test/writable-dir/readonly-file4.txt \
&& chmod 0555 /test/*/*.txt
RUN ls -laR /test/*
USER 1000:1000
RUN rm /test/readonly-dir/readonly-file1.txt || true
RUN rm /test/writable-dir/readonly-file3.txt || true
RUN echo "update" > /test/readonly-dir/readonly-file2.txt || true
RUN echo "update" > /test/writable-dir/readonly-file4.txt || true docker build --no-cache --progress=plain .
#6 [3/7] RUN ls -laR /test/*
#6 sha256:02c470a2da32404fde66a1817ada4962acca703499f8f141022e9a3f9526a92b
#6 0.256 /test/readonly-dir:
#6 0.257 total 16
#6 0.257 drwxr-xr-x 2 root root 4096 Sep 3 11:44 .
#6 0.257 drwxr-xr-x 4 root root 4096 Sep 3 11:44 ..
#6 0.257 -r-xr-xr-x 1 root root 6 Sep 3 11:44 readonly-file1.txt
#6 0.257 -r-xr-xr-x 1 root root 6 Sep 3 11:44 readonly-file2.txt
#6 0.257
#6 0.257 /test/writable-dir:
#6 0.257 total 16
#6 0.257 drwxrwxrwx 2 root root 4096 Sep 3 11:44 .
#6 0.257 drwxr-xr-x 4 root root 4096 Sep 3 11:44 ..
#6 0.257 -r-xr-xr-x 1 root root 6 Sep 3 11:44 readonly-file3.txt
#6 0.257 -r-xr-xr-x 1 root root 6 Sep 3 11:44 readonly-file4.txt
#6 DONE 0.3s
#7 [4/7] RUN rm /test/readonly-dir/readonly-file1.txt || true
#7 sha256:0b9cc29596617a08bc27179723a26b7ef7146c2bf26533be8226a3b392450cb8
#7 0.275 rm: can't remove '/test/readonly-dir/readonly-file1.txt': Permission denied
#7 DONE 0.3s
#8 [5/7] RUN rm /test/writable-dir/readonly-file3.txt || true
#8 sha256:a7d587258ab4a4c51eeb2424f855cbb3e768be41a9a54e213bf35781b3b1e553
#8 DONE 0.3s
#9 [6/7] RUN echo "update" > /test/readonly-dir/readonly-file2.txt || true
#9 sha256:833daf528566a591cc8714bf547950c2493fa080517ea041811e2c63681c41b6
#9 0.279 /bin/sh: can't create /test/readonly-dir/readonly-file2.txt: Permission denied
#9 DONE 0.3s
#10 [7/7] RUN echo "update" > /test/writable-dir/readonly-file4.txt || true
#10 sha256:07be4ad9024cc5a12c9adfecb6033fd82283b761c3e3acb475357cafa4952e2d
#10 0.257 /bin/sh: can't create /test/writable-dir/readonly-file4.txt: Permission denied
#10 DONE 0.3s |
Thank you @djs55 and @thaJeztah for the detailed explanations. And thanks for the Stack Exchange link with lots more explanations. Perhaps I should have phrased it differently. It also makes sense that Directory permissions set as read-only would make a big difference. (Perhaps this is why in defunct VAX/VMS they had 4 permissions: RWED where E was the Edit privilege, considered separate to read/write.) While But on the Docker-Mac it does not even ask the question... so a command such as I just wanted to point that out... that perhaps Mac users should be made aware of this "danger" in case they run Docker as a Non-Root user thinking that it is "safe" or "safer" (as obviously the default root user damages can be perhaps even greater.) |
I think that's configurable, and may be set up on a desktop install of some linux distros, but likely not the default, which is what most containers use; https://stackoverflow.com/a/30208934 (answering from my phone, so haven't tried if that's what you mentioned |
Thanks @thaJeztah - Wow from your phone! Yes, With On Docker-Mac the behavior is not what one would expect from experience with Linux/bash elswhere and that is the point I wanted to make. Perhaps users should be warned that it can happen. |
I successfully tried the @djs55
I did see the "normal" behavior when using
I found a very good blog article about volumes: https://blog.container-solutions.com/understanding-volumes-docker But I have not found the answer there about mounting a "docker volume" such as |
Closed issues are locked after 30 days of inactivity. If you have found a problem that seems similar to this, please open a new issue. Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. |
Expected behavior
When sharing a volume folder on the Macintosh using
-v
file permissions should be respected i.e.rm
should not remove files without confirmation when user is NOT root.Actual behavior
Even with permission set to
-r--r--r--
and owned by non-root user file is deleted byrm
without warning.THis is also true if permissions are set from the Macintosh side.
Information
The problem is reproducible on Mac with: Ubuntu (20.04), CentOS (7) and Alpine (latest)
On Ubuntu and CentOS user can be added with
useradd
and a password set to login with commandpasswd
.On Alpine, files can be edited to allow new, unprivileged user by editing
/etc/passwd
,/etc/shadow
, and/etc/group
a password set to login with commandpasswd
.Steps to reproduce the behavior
Docker images used:
ubuntu 20.04 1318b700e415 5 weeks ago 72.8MB
centos 7 8652b9f0cb4c 9 months ago 204MB
alpine 3.10 965ea09ff2eb 22 months ago 5.55MB
How to reproduce. Show below for the Ubuntu docker (but it is the same effect for all 3.)
Test
Now verify presence and permissions of file:
Verify that permission prevents overwriting of file with a
>
redirect command: indeed it is not allowed.Now use
rm
to remove file:FILE IS DELETED and there is not warning. NOTE that the "no write" permission was set from the Mac.
CONCLUSION: User files on the Mac could be deleted.
NOTE: I tried best I could to reproduce this on Windows but the appropriate
response
rm: remove write-protected regular file 'note.txt'? y
was given.Therefore this appears to be a specific Mac issue.
The text was updated successfully, but these errors were encountered: