-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Volume for container with custom user is not writeable #3990
Comments
I assume the As such, it's running as a non-0 user in the container, which is mapped to a user on the host through You may want to just remove |
@mheon |
We really can't handle this ourselves - these are separate users from the perspective of the kernel, and normal filesystem permissions apply. |
It is possible to configure filesytem layer to ignore host permissions? If a container is already isolated through filesystem path, why impose additional Maybe it is possible to implement two layer writes? The first layer enforces permissions, so that container won't escape the defined path, but final writes to disk are ignoring the permissions. If container needs a separate user with volume mapping, maybe |
You can change the ownership on the volume with the |
`java` user creates problems when mounting volumes. See containers/podman#3990
@rhatdan I also checked
|
I've got a thought overnight.
When I run container with custom USER as non-privileged, then there is no |
By default podman as non root, runs as root within the container. This means the processes in the container have full Namespaced Capabilities. This also means that if the container process escaped the container, it would have full access to files in your homedir (Based on UID, SELinux would still block it, but I have heard that some people disable SELinux). If you run the processes within the container as a different non root UID, then those processes will run as that UID and if they escape they would only have world access to content in your homedir. |
@abitrolly I am writing a blog based on these issues. Send me your email and I can expose an early copy to you. [email protected] Just needs to be reviewed and then I can get it published. |
@rhatdan people disable SELinux, because not all builds scripts add My email is [email protected]. I sent email titled "Early copy" from this address. Given that even with |
People running with containers not separated by SELinux are taking a big risk, since it is the main tool to protect their file system from containers. Escape for Docker allows access to all keys, rootless podman only to the users uid. |
@abitrolly But bottom line, I tell people to always run their containers as non-root, even in the rootless container. |
Not sure if this is a "true" solution or more of a workaround, but would not For example:
This mounts tmp inside the container at Perhaps Note: you cannot use |
This issue had no activity for 30 days. In the absence of activity or the "do-not-close" label, the issue will be automatically closed within 7 days. |
@rhatdan, what's your take on this issue. Shall we pursue your upper proposal? |
I don't think so, I am hesitant to make this more complicated. I think it is up to the user to set up the permissions correctly on the volume. |
`java` user creates problems when mounting volumes. See containers/podman#3990
I still don't understand what What is the proposed solution? Is the following correct?
Is that right? |
Wow, this stuff is way too complicated. I've the same issue as @abitrolly (running podman as non-root, having a user inside the container that is not "root" and I cannot write to the mounted directory). I've read every comment here and I still don't have an idea how to make this work. |
So, it seems like I can make it "work" be "chown"ing (on the host) the shared directory to the user-id that the non-root-container-user (in my case called "jenkins", because I'm using the jenkins:jenkins image from Docker hub) is mapped to on the host system. In my case, this jenkins-user from inside the container has the UID 559751 on the host system. (Btw, what is the easiest way to find this out?). So, doing
I need to share this image with my coworkers (who don't have root privileges), so both of these points are unacceptable. |
Okay, but how? |
Root should not be necessary - For the second issue... That is definitely a concern, and one I don't think we have an easy solution to as yes. There is talk of adding UID/GID mappings to LDAP for use across multiple systems, but they will still be unique to the user running the container for security reasons, so not portable between users Running rootless containers as non-root and mounting in volumes is proving to be quite complicated. I think a review of how things are right now and a discussion of how we can improve (maybe a blog?) is definitely warranted here. |
@mheon Thank you very much for your detailed comment!
I definitely needed "sudo" to execute
Well, this seems portable in the sense that I should be able to write a simple shellscript to automate this process for my coworkers every time they want to use my image.
I will tinker around with this some more tomorrow. |
I agree that |
@ChristianCiach have you been able to come up with tutorial for your colleagues? |
@abitrolly Sorry for the late reply. Yes, creating a simple wrapper that calls "podman unshare" before calling "podman run" works as expected. This is good enough for my use case. |
Now how do you chown the directory back to the host user though?
|
It might not work in all use cases but another work around is to run the command in the container with the host's user ID and GUID by using
while without it it fails:
|
I wonder if giving the container host user ID and GUID makes the contaner unprivileged? |
Containers by default are unprivileged. (Depending on your definition of unprivileged) |
i'm battling this same thing. i am using a bitnami image of postgresql from docker hub. it has a baked in user id of 1001. on my arch linux system my uid is 1000. I would like to make a directory in my home directory for postgres to persist its data to, and be able to poke around in that directory without having to chown it all the time when i want to. |
Well for now you can do $ podman unshare chown 1001:1001 PATHTODIR We could add something to the volume command to do this, but I am not sure how ugly the syntax would be. |
I would love to have this feature, even if it looks ugly :) |
Thanks for writing this up, it really helped me to understand what is going on here. Unfortunately the container I am using and want to deploy and regularly update has 43 different user, and their associated group relationships. So If I understand the situation I would need to parse out all 43 entries from /etc/passwd using podman mount, then create a wrapper script that calls podman unshare with each of those. Then when the container gets updated to add a new user, I'm then broken and need to go update the script. I know it would be complex from an implementation perspective, but it would be great if podman could inspect /etc/passwd itself from within the image and pull out the appropriate non-root users all within the --volume command option without a need for further user options. |
Why not mount /home into the container then? |
I would appreciate if |
this is needed to solve the issue containers/podman#3990 when running on Podman. Podman by default is not matching the container user when bind mounting volumes. So we have to explicitly say this.
How hard it could be to write a nice blog post series for the simple users which follows the Podman mantra of not running root-full containers, but wants just to mount some volumes. For the most common use-cases.
IMO there is not so much different flavors of the setups which are used by the mainstream users. This volumes question is like Top 1 asked question and yet, in Podman (which "coined" the root-less idioms) website can't be found any article for "simple users". Every article i saw is like - "Guys, in order to run your quick container idea in rootless, please first learn whole SELinux labeling and type enforcement, then learn Linux namespacing and then feel free to read this article and to run your container in rootless." I understand that this is fairly complex topic. And the tooling is tailored to match pretty low level requirements and thus it is kinda flexible and complex at the same time. |
Thanks @rhatdan for the excellent article series where you explain things like This works fine for a single container trying to access a host folder, but how about two containers which potentially use two different users both trying to access the same host folder (e.g. one writing, the other reading files)? |
Well they should be in the same group or one have root ownership and the other group read access. Using --group-add keep-groups. |
I am having a similar problem that is described here, but the solutions proposed do not work for my use case, because I am running two rootless containers in a pod. I hope I am not doing something silly, but this is the minimum example to reproduce the problem I see: Note:
What would be a good way to solve this? I cannot use I also cannot use |
Does --userns=keep-id when creating the pod work?
|
@rhatdan No unfortunately not. If I pass the keep-id flag into the pod creation at step 2 like you suggested, then in step 3 the container fails to initialize, giving the following error:
Like I said before, setting it at the pod level messes up the behaviour of the first container. |
Please open a new issue for this and we can get others to comment, we are trying to prevent people from discussing issues on older issues. |
/kind bug
Description
When running a container with explicitly set user, such as
https://github.com/schemaspy/schemaspy/blob/a28c9fc932cc6f85c7780050a678b3a3d7f595e9/Dockerfile#L44 the volume mounted by
podman
is not writeable.Steps to reproduce the issue:
Get some PostreSQL host (192.168.4.1) and port (5432)
Create dir to mount as a volume
podman
Describe the results you received:
Container is unable to write to
/output
, most likely because it is running withjava
user.Describe the results you expected:
Volumes work
rw
regardless of user settings inside of conainer.Output of
podman version
:The text was updated successfully, but these errors were encountered: