8000 Fix folder access and mount problems with image volumes by marcov · Pull Request #951 · containers/podman · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix folder access and mount problems with image volumes #951

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

Closed
wants to merge 1 commit into from

Conversation

marcov
Copy link
Collaborator
@marcov marcov commented Jun 15, 2018

Fixes and improvements for container images with attached volumes:

  1. Set the correct mount point path ownership and permissions when the path does not exist in the image root FS.
  2. Fix initialization of spec.Mount Source field (fixes Podman with image volume fails to create directory after restart #844).
  3. Set the mount point path with the same permissions as the ones found in the image root FS.

@rh-atomic-bot
Copy link
Collaborator

Can one of the admins verify this patch?
I understand the following commands:

  • bot, add author to whitelist
  • bot, test pull request
  • bot, test pull request once

@mheon
Copy link
Member
mheon commented Jun 15, 2018

bot, add author to whitelist

return err
}

if err = os.Chown(volumePath, int(uid), int(gid)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the logic we want to use - we should use the owner and permissions of the parent folder in the image (parent path of filepath.Join(mountPoint, k))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the way I did may not be optimal.

But I don't think that using the parent folder stats is correct, because it's likely that the parent folder has stricter permissions. E.g. when mounting a volume as sub folder of /mnt, if we use the same permissions of /mnt (root - 755), we end up again with a non-accessible folder for the container user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should follow what Docker does in this situation. Create a container image with a volume owned by non root, and how does it

# cat Dockerfile
FROM alpine
RUN mkdir /data; chown 3267:3267 /data
VOLUME /data

# docker build -t volumetest .
# docker run --rm volumetest ls -lad /data
drwxr-xr-x    2 3267     3267             6 Jun 16 10:17 /data
# docker run --user 1234 --rm volumetest ls -lad /data
drwxr-xr-x    2 3267     3267             6 Jun 16 10:17 /data
# podman build -t volumetest .
# podman run --rm volumetest ls -lad /data
drwxr-xr-x    2 root     root             6 Jun 16 10:22 /data
# podman run --user 1234 --rm volumetest ls -lad /data
drwxr-xr-x    2 root     root             6 Jun 16 10:23 /data

Docker is definately getting the ownership/permissions from the image.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhatdan, my implementation mimics Docker in this regard:

# ./bin/podman run --rm volumetest ls -lad /data      
drwxr-xr-x    1 3267     3267             0 Jun 18 16:29 /data
# ./bin/podman run --user 1234 --rm volumetest ls -lad /data
drwxr-xr-x    1 3267     3267             0 Jun 18 16:29 /data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mheon Does that look good to you?

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

@mheon PTAL

@mheon
Copy link
Member
mheon commented Jun 20, 2018

@rhatdan I'm still a little iffy on the logic for ownership of the directories, but it's definitely an improvement over what we have, and we can always adjust the algorithm for chown/chmod at a later date

@mheon
Copy link
Member
mheon commented Jun 20, 2018

Let me just do a quick test with user namespaces first before we merge, want to make sure it won't mess up our chown

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

Yes I guess the question would be is the chown happening within the User Namespace @giuseppe PTAL

@mheon
Copy link
Member
mheon commented Jun 20, 2018

Just looking at the code, I'm strongly suspecting this won't handle user namespaces correctly. We'll need to translate the UID we get out of the chrootuser package using the UID/GID mappings, if they're present. Unfortunately, we don't already have code to do this (we have a very limited implementation that will only work for UID/GID 0).

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

Lets merge and we can deal with that separately.

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

The chroot stuff will not fix this. We need the chmod to happen in the user namespace so when it sees the underlying UID, it will be mapped to what it is setting it too. No need to look into the chroot of the container image.

@mheon
Copy link
Member
mheon commented Jun 20, 2018

@rhatdan I'm looking more into this, and I think we may not be handling the case where user namespaces are enabled and we're not running as UID 0 in the container at all.

@mheon
Copy link
Member
mheon commented Jun 20, 2018

Still, this PR will break image volumes on user namespace enabled containers.

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

Their broken now. This PR fixes the broken issue for the vast majority of use cases.
Without this fix containers which have voumes owned by entities other then root will fail. I am not sure that user ns is any better. Since the volume will be created as root on the host and mounted into the container, which means root inside of the container will not be able to write there.

@mheon
< 8000 clipboard-copy aria-label="Copy link" for="issuecomment-398860869-permalink" role="menuitem" data-view-component="true" class="dropdown-item btn-link"> Copy link
Member
mheon commented Jun 20, 2018

Fair enough...
LGTM, but we should really fix the userns-related issues. And start doing more testing on user namespaces, if we can.

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

Yup @giuseppe Could you check this with some of your work.

@rhatdan
Copy link
Member
rhatdan commented Jun 20, 2018

@rh-atomic-bot r+

@rh-atomic-bot
Copy link
Collaborator

📌 Commit 4a659f7 has been approved by rhatdan

@giuseppe
Copy link
Member

yes, I am currently working (and struggling) on getting tests done well with userNS. For example: #936 is failing because it needs a newer runc (https://bodhi.fedoraproject.org/updates/FEDORA-2018-afddf09bfb).

I'll rebase the other PR once this is merged and manually test it.

@rh-atomic-bot
Copy link
Collaborator

🔒 Merge conflict

@marcov
Copy link
Collaborator Author
marcov commented Jun 21, 2018

Squashed commits into a single one and rebased.

srcPath := filepath.Join(mountPoint, k)
67E6
if _, err := os.Stat(srcPath); os.IsNotExist(err) {
logrus.Infof("Volume image mount point %s does not exits in root FS, need create it", k)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Volume image mount point %s does not exist in root FS, need to create it"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Signed-off-by: Marco Vedovati <mvedovati@suse.com>

- Set srcPath permissions so that the container user can R/W it.

- Fix uninitialized spec.Mount when restarting a container.

- Check for srcPath instead of volumePath existence when setting up a
  
A3E2
volume mount point for a container.

- Set the overlay volumePath with the same owner and permissions as
  srcPath to allow proper access by the container user.

Closes containers#844
@mheon
Copy link
Member
mheon commented Jun 22, 2018

bot, retest this please

@rhatdan
Copy link
Member
rhatdan commented Jun 22, 2018

@rh-atomic-bot r+

@rh-atomic-bot
Copy link
Collaborator

📌 Commit 4830608 has been approved by rhatdan

@rh-atomic-bot
Copy link
Collaborator

⌛ Testing commit 4830608 with merge bb4db6d...

@rh-atomic-bot
Copy link
Collaborator

☀️ Test successful - status-papr
Approved by: rhatdan
Pushing bb4db6d to master...

@marcov
Copy link
Collaborator Author
marcov commented Jun 22, 2018

@mheon, I did some tests with user namespaces as I was curious of the results.

In the test I did this change is not breaking support for user NS. This is for images with volume path already there in the root FS and for those without volume path already existing.

You can see the tests and the results here: https://github.com/marcov/userns-test

@rhatdan
Copy link
Member
rhatdan commented Jun 22, 2018

@marcov We have some tests that can be run outside of the test framework by humans to make sure things are good. I know we have these for buildah, but I am sure we could use stuff like this in podman as well. @TomSweeneyRedHat Could you take a look at what @marcov has done and see if this is something we should add to our "demos"

@TomSweeneyRedHat
Copy link
Member

We've a test file that I run on each proposed kit at tests/test_podman_baseline.sh. We've a similar one for Buildah. I'll see if I can massage some or all of these in there and also want to add some ONBUILD and possibly CNI tests to both. Thanks for the pointer!

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Podman with image volume fails to create directory after restart
6 participants
0