-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Mounted volume changes user ID's of files #7052
Comments
Could you give us a simple reproducer of the command, is this because you are comparing rootless versus rootful. podman unshare ls -l PodmanFolder |
For some reason some of the description is missing from what i wrote. Additional details bellow: I have made the following steps:
Ran the script and started the container. Looking into /mnt/Data/SyncthingTest
Output of command " podman unshare ls -l ":
My take from what i see there is that "config" is used by container as it initialises and takes ownership and "data" folder is kept as root due to it not being utilised. This is cofnirmed by:
The above test is done via rootless podman. Running as root podman as far as i understand the command "--userns=keep-id" is ignored. (http://docs.podman.io/en/latest/markdown/podman-create.1.html) I can try the test in root mode as well. The environment uses more than one container on the same set of data and each having their own user and group is not ideal i think. Additionally this whole mount is shared via Samba over the network which uses GID and UID 1000. |
I'm pretty sure that Docker does not support |
Corect, for Docker i would map the user ID like this: However this does not work in Podman :( |
Is the user running the container UID/GID 1000? The default Podman user mapping maps root in the container to the user running the container, and it sounds like that's what you're looking for?
|
The user running the container is UID/GID 1000. I am aware of this behavior that the user running the container becomes root in the container. |
In general, there isn't much security benefit to running as non-root in a rootless container. Root inside a rootless container isn't special - it doesn't have any privileges your user outside the container does not have. Running as a non-root user can deny access to files outside the container that are owned by your user, but then you run into situations like this - you actually want the container to be able to access files owned by your user, so we can't do that. In general, running as non-root in a rootless container is only useful if you don't need to touch files outside of the container - for something like a webapp that doesn't require anything volume-mounted in, it works perfectly fine and can improve security by a bit. |
Well the security benefit, is that files in your homedir are protected from processes in the container that are not running as your UID. So running non root inside of a container is still important. I wrote a blog on this. |
I've read that, however it does not help me out in my case where i need to have a consistent storage area for more than one container. I think i'll just need to figure out how to properly map a fixed user group where all container users have access and just use the mask of 007 mask on all files and directories. Then even if the UID's are weird it should maybe work. I'll have to see how samba works then. |
Podman running as root will work exactly the same was as Docker. The difference you are seeing is because you are running rootless podman with the user namespace. You would face the same problem is you ran Docker rootless. Are all of the containers being run by the same user? If yes then they will all have the same UID mapped into the container and ti should not be a problem. |
I've been using rootless podman with default namespace options which maps the host user to root in the container.
When the container is run as root inside the container then the bind mount works as expected. The directory does not have to exist on the image.
Now for example if the container contains a user UID 3000 then default ACL on the host side can ensure all files are kept writable by host user and the container user. The same can be done with groups.
EDIT: The setfacl Assuming there is an image which has a "user" with UID 3000.
Non-root volumes work fine as long as the directory in the image is owned by the user. Haven't tried shared volumes. |
This works wonders! It's basically what i needed the host user to maintain access to those files, the ACLs work. I would have liked to have a feature in podman to allow this to be done easier that it was done here and maybe give the files back to the host, maybe this could work with a mount feature inside the container where a mask is applied? :( I find this way a bit too complicated for a container to just work. I think i solved my issue. The shared access not sure if it will work, but it works as it is for this purpose, common access i would just do container->container communication and be done with it. |
A friendly reminder that this issue had no activity for 30 days. |
I found another solution using The effect is that host files appear as owned by container UID inside the container and new files created by the container UID will be chowned to the host user (I'm using the default podman settings of mapping host user to container root but running as another user in the container). I'm not sure if this is possible with the podman edit: typo |
@giuseppe PTAL |
This actually sounds usefull, for my usecase the solutions don't really work well as i would expect so i'm reverting to docker as that fits my bill a lot better. Will run docker in a VM and be done with it, for my purposes having the data as such it's just not worth the time and effort. I would consider this to be a basic functionality, working with data outside of the container and podman just doesn't offer a straight option for this in shared cases. |
I'm also using docker in a VM to run some legacy stuff but for dev/tinkering I prefer podman. I looked into lowerdir and upperdir are the same since I only use it for the UID shifting. The only issue is that it leaves some junk files around (which are only visible to the host). I'm guessing this could be a little more documented and integrated. |
@mgnsk Thank you, this solution seems to be what I was looking for! However, I don't think I have the namespaces mapped quite right yet and wanted to make sure I was actually headed in the right direction. If one is running a container where the default account is a non-root user, will this allow writing files without both the --privileged tag and bouncing between file ownership? Am I assuming correctly that the first uid is how it appears within the container and the second the one you want to share with your host user? Or should I factor in the longer uids that are generated that the host perceives. I was also running the subsequent call to start the image within "podman unshare" does this file uid mapping remove the need to do that? All of the namespace caveats are new to me, and I haven't found a good beginner friendly resource for a getting a strong grasp on what is happening under the hood in respect to those. Hoping this is the way that rootless containers can just work as expected without needing to invoke privileged. |
This is a lot to digest, but I believe the issue is solved. Closing, reopen if I am mistaken. |
This bug wasn't solved or am I missing something? There's a workaround of This is a deal-breaker for |
I really do not know what you are expecting. Docker does not have a --userns flag at all, so not sure why this is not a replacement. Show me a command in Docker which does not work the same was as Podman. |
Sure
This causes problems like |
You are comparing apples and oranges. The files are owned by the same user but Podman is in a user namespace, while Docker is running as root in the hosts user namespace. So you are compilin as user 998 within the container, which in the case of a user namespace is not the correct user. You can create a file like |
Oh, so there is an option to make that default, the
Thanks! That works for me |
I just found an unpleasant surprise: the
@rhatdan what you mention is just an implementation detail. But from the user POV there's a difference in behavior of Podman and Docker, which actually matters, which is what this bug is about. Adding the |
It's an implementation detail, but it is a critical part of how rootless actually works. Without user namespaces, none of this would be possible; unfortunately, that requires understanding and working with them. There is no way to accomplish what you seem to be asking for (1:1 user and group mappings for a rootless container) without completely removing the security advantages of rootless containers. |
@mheon is correct, if you want to run like Docker, then you need to run as root or run your commands through sudo. |
Turns out, since 4.3.0 release there is a new functional that solves that problem: the |
/kind bug
Volumes mounted inside of containers change ownership of actual files.
Steps to reproduce the issue:
Create a container that takes ownership of files
Add to the container external storage with -v
Files within the volume mounted via -v will have the owner from inside the container.
Describe the results you received:
Docker would keep the user ID's consistent:
drwxr-xr-x 2 pingu pingu 4096 Jul 15 12:04 DockerFolder
drwxrwxrwx 2 100910 100910 4096 Jul 22 20:16 PodmanFolder
Describe the results you expected:
I would expect that at least the ID's of files are kept.
Additional information you deem important (e.g. issue happens only occasionally):
Output of
podman version
:Output of
podman info --debug
:Package info (e.g. output of
rpm -q podman
orapt list podman
):Additional environment details (AWS, VirtualBox, physical, etc.):
Running on baremetal Fedora 32.
The text was updated successfully, but these errors were encountered: