Closed ensc closed 2 years ago
@giuseppe PTAL
Rootless always uses recursive because that is enforced from the kernel.
Have you made the mount shared or slave? Please show the output of findmnt -R -o PROPAGATION,TARGET /
.
@giuseppe it is shared; from the example above
shared /
...
shared ├─/tmp
shared │ └─/tmp/foo/bar
When I mount it with rbind
, it works as before (mount --rbind /proc /tmp/foo/bar
). Probably the kernel prevents the unwanted behaviour only in this case.
But there is still a difference between --userns=keep-id
and the default userns which did not exist before podman 3.4.7.
could it be a timing issue.
If you create the bind mount after the podman user+mount namespace was created, then it might not be propagated.
Could you try running podman system migrate
after you create the bind mount? Does it make any difference?
I think the difference is that when the mount namespace is created then all the mounts there are rbind
so it is not possible to look beneath a mount, but if that happens later and the new mount is propagated then it doesn't matter to hide what is beneath it, since it could already be possible to grab a open file descriptor to the previous path.
I am closing the issue as I am able to reproduce the same behavior both with 4.0, 3.4.7 and 3.4.1 but feel free to comment further
I suspect that this is the same as https://github.com/containers/toolbox/issues/1073
This is how I usually run my containers:
$ podman run -it --rm --security-opt label=disable --userns keep-id -v $HOME:$HOME:rslave -v /run/media:/run/media:rslave registry.fedoraproject.org/fedora:36 bash
If I mount something on the host after starting the container, then everything is good. However, if I mount something on the host before starting the container, then things get interesting.
For example, I plugged in a USB stick with the Fedora 36 Workstation Live ISO before starting the container, and then once I ran it:
$ ls /run/media/rishi/Fedora-WS-Live-36-1-5/
ls: cannot open directory '/run/media/rishi/Fedora-WS-Live-36-1-5/': Permission denied
$ ls -l /run/media/rishi
total 0
drwx------. 2 nobody nobody 40 Oct 27 16:55 Fedora-WS-Live-36-1-5
I don't know why the Fedora-WS-Live-36-1-5
directory is owned by nobody:nobody
, because on the host it's owned by me:
$ ls -l /run/media/rishi/
total 2
drwxr-xr-x. 1 rishi rishi 2048 May 4 23:36 Fedora-WS-Live-36-1-5
I exited the container, and tried a simpler mount:
$ mkdir ~/tmp
$ sudo mount -t tmpfs none ~/tmp
$ echo "hello world" >~/tmp/hello-world
$ ls -ld ~/tmp
drwxrwxrwt. 2 root root 60 Oct 27 19:04 /home/rishi/tmp
$ ls -l ~/tmp/hello-world
-rw-r--r--. 1 rishi rishi 12 Oct 27 19:04 /home/rishi/tmp/hello-world
Then I ran the container again:
$ cat ~/tmp/hello-world
cat: /home/rishi/tmp/hello-world: No such file or directory
$ ls ~/tmp
$ ls -ld ~/tmp
drwxr-xr-x. 2 rishi rishi 4096 Oct 27 16:31 /home/rishi/tmp
$ id
uid=1000(rishi) gid=1000(rishi) groups=1000(rishi)
It looks like the container doesn't know about the mount on the host at ~/tmp
at all.
However, as mentioned before, things work as expected, if I run the container before the mounts are created.
It starts to work if I drop --userns keep-id
and run my containers as:
$ podman run -it --rm --security-opt label=disable -v $HOME:$HOME:rslave -v /run/media:/run/media:rslave registry.fedoraproject.org/fedora:36 bash
With the USB stick:
# ls /run/media/rishi/Fedora-WS-Live-36-1-5/
EFI Fedora-Legal-README.txt LICENSE LiveOS images isolinux
# ls -l /run/media/rishi/
total 2
drwxr-xr-x. 1 root root 2048 May 4 21:36 Fedora-WS-Live-36-1-5
With the tmpfs
mount at ~/tmp
:
# cat /home/rishi/tmp/hello-world
hello world
# ls -l /home/rishi/tmp
total 4
-rw-r--r--. 1 root root 12 Oct 27 17:14 hello-world
# ls -ld /home/rishi/tmp
drwxrwxrwt. 2 nobody nobody 60 Oct 27 17:14 /home/rishi/tmp
With both mounts present on the host:
$ findmnt --submounts --output PROPAGATION,TARGET /
PROPAGATION TARGET
shared /
shared ├─/run
shared │ └─/run/media/rishi/Fedora-WS-Live-36-1-5
shared ├─/home
shared │ └─/home/rishi/tmp
I tried to reproduce this with bind mounts in the host's mount and user namespaces, without any containers or child namespaces around, with:
$ sudo mount --rbind -o rslave /run/media ~/devel/foo
Things work as expected regardless of whether I plug in the USB stick before I create the bind mount or after:
$ ls ~/devel/foo/rishi/Fedora-WS-Live-36-1-5/
EFI Fedora-Legal-README.txt images isolinux LICENSE LiveOS
/kind bug
Description
When using
--userns=keep-id
, mounts are not recursive anymore. This seems to be a regression because it worked in previous podman versions (I think podman-3.4.7-1.fc35.x86_64 broke it). I have not tested it with podman-4NOTE: this can be a security issue because it allows to break recursive mounts and reveal the original content.
Steps to reproduce the issue:
--userns=keep-id
Describe the results you received:
In step 3, the procfs is not mounted.
Output of
podman version
:Output of
podman info --debug
:Package info (e.g. output of
rpm -q podman
orapt list podman
):Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)
No
Additional environment details (AWS, VirtualBox, physical, etc.):