-
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
named volume created when running with userns=keep-id has wrong ownership #5698
Comments
@mheon This means that the volume was created to be owned by root of the user namespace rather then the default user of the container. Since --userns=keep-id implies --user CURRENTUSER we need to make sure this is passed down the stack. @stintel If you executed the same command but added |
@rhatdan it seems we are always creating volumes as root, even without user namespaces involved. |
Inspect on the volume says that the UID/GID the volume was created with was 1 - are we sure this isn't a volume as the first non-root UID/GID? |
@stintel Can you provide an |
|
So the bug is builtin volumes are not being created based on the user of the container, but always as root of the container. I thought we fixed this, maybe it works as root. |
Broken as root as well.
|
@sujil02 or someone else looking to contribute. @kunalkushwaha ??? The basic idea is builtin volumes should be created with the owneship of the user of the container. In the example above the /test should have been owned by UID 1000 GID 1000. In the --userns keep-id case, it should be created owned by the user creating the container. |
I know we have code for this. Looks like it got broken at some point. |
Looking into it. |
@mheon However, What I am not sure of is can I pick the user flag params from |
I believe you can pick the ctr.config.User |
A friendly reminder that this issue had no activity for 30 days. |
@sujil02 Did you ever fix this problem? |
I did try a lot working around it. The current |
There are calls in buildah that translate the User field to a UID, by reading the /etc/passwd inside of the container. uid, gid, _, err := chrootuser.GetUser(s.mountPoint, s.builder.User()) |
oh wow, this is great certainly helps. On it. |
@sujil02 What is the scoop on this one? |
Looks like the behaviour changed. --userns=keep-id
--user=1000
@rhatdan how do you want it to behave? |
The newly created directory should be owned by User 1000 (Relative to the User Namespace) |
Any volume that is created for a container should be owned by the "user" for pid1, So if you run as root, then it owned by root of the usernamespace. If you do --userns=keep-id, then the container will run as your UID, so the volume should be owned by your UID. |
Already on it. Writing tests at the moment :) |
When setting up the volumes for a container, make sure that new volumes are created with the correct uid/gid which we're looking up in the container config. Fixes: containers#5698 Signed-off-by: Valentin Rothberg <[email protected]>
move the chown for newly created volumes after the spec generation so the correct UID/GID are known. Closes: containers#5698 Signed-off-by: Giuseppe Scrivano <[email protected]>
move the chown for newly created volumes after the spec generation so the correct UID/GID are known. Closes: containers#5698 Signed-off-by: Giuseppe Scrivano <[email protected]>
As part of a fix for an earlier bug (containers#5698) we added the ability for Podman to chown volumes to correctly match the user running in the container, even in adverse circumstances (where we don't know the right UID/GID until very late in the process). However, we only did this for volumes created automatically by a `podman run` or `podman create`. Volumes made by `podman volume create` do not get this chown, so their permissions may not be correct. I've looked, and I don't think there's a good reason not to do this chwon for all volumes the first time the container is started. I would prefer to do this as part of volume copy-up, but I don't think that's really possible (copy-up happens earlier in the process and we don't have a spec). There is a small chance, as things stand, that a copy-up happens for one container and then a chown for a second, unrelated container, but the odds of this are astronomically small (we'd need a very close race between two starting containers). Fixes containers#9608 Signed-off-by: Matthew Heon <[email protected]>
As part of a fix for an earlier bug (containers#5698) we added the ability for Podman to chown volumes to correctly match the user running in the container, even in adverse circumstances (where we don't know the right UID/GID until very late in the process). However, we only did this for volumes created automatically by a `podman run` or `podman create`. Volumes made by `podman volume create` do not get this chown, so their permissions may not be correct. I've looked, and I don't think there's a good reason not to do this chwon for all volumes the first time the container is started. I would prefer to do this as part of volume copy-up, but I don't think that's really possible (copy-up happens earlier in the process and we don't have a spec). There is a small chance, as things stand, that a copy-up happens for one container and then a chown for a second, unrelated container, but the odds of this are astronomically small (we'd need a very close race between two starting containers). Fixes containers#9608 Signed-off-by: Matthew Heon <[email protected]>
As part of a fix for an earlier bug (containers#5698) we added the ability for Podman to chown volumes to correctly match the user running in the container, even in adverse circumstances (where we don't know the right UID/GID until very late in the process). However, we only did this for volumes created automatically by a `podman run` or `podman create`. Volumes made by `podman volume create` do not get this chown, so their permissions may not be correct. I've looked, and I don't think there's a good reason not to do this chwon for all volumes the first time the container is started. I would prefer to do this as part of volume copy-up, but I don't think that's really possible (copy-up happens earlier in the process and we don't have a spec). There is a small chance, as things stand, that a copy-up happens for one container and then a chown for a second, unrelated container, but the odds of this are astronomically small (we'd need a very close race between two starting containers). Fixes containers#9608 Signed-off-by: Matthew Heon <[email protected]>
/kind bug
Description
When running podman with userns=keep-id and a named volume, the volume ownership is wrong.
Steps to reproduce the issue:
podman volume rm test
podman run --rm -it --userns=keep-id --mount 'type=volume,src=test,dst=/home/user' --workdir /home/user ubuntu:18.04
touch test
Describe the results you received:
Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
When running with --userns=keep-id, the volume should be created with the real UID/GID of the user calling podman, so that it is writeable inside the container.
Output of
podman version
:Output of
podman info --debug
:Package info (e.g. output of
rpm -q podman
orapt list podman
):NA (Gentoo)
Additional environment details (AWS, VirtualBox, physical, etc.):
Running on physical Gentoo, rootless mode. No SELinux.
The text was updated successfully, but these errors were encountered: