Skip to content
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

set correct uid/gid on volumes #6730

Closed
wants to merge 1 commit into from

Conversation

vrothberg
Copy link
Member

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: #5698
Signed-off-by: Valentin Rothberg [email protected]

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 23, 2020
@vrothberg
Copy link
Member Author

@rhatdan PTAL

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]>
@@ -308,8 +309,15 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai

logrus.Debugf("Creating new volume %s for container", vol.Name)

// Get the uid/gid of the container user to create the volume
// with the correct uid/gid. See github.com/containers/libpod/issues/5698.
uid, gid, _, err := chrootuser.GetUser(ctr.state.Mountpoint, ctr.config.User)
Copy link
Member

Choose a reason for hiding this comment

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

This is not safe - ctr.state.Mountpoint is unset at this point, because the container has not been mounted.

Copy link
Member

Choose a reason for hiding this comment

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

If you pass a user by name instead of UID, this will break horribly and use the host's /etc/passwd instead of the container's.

Copy link
Member

Choose a reason for hiding this comment

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

When I went over this with Sujil when he was working on it, we agreed that mounting the container this early in creation is prohibitively difficult, so he was investigating chown'ing the volume as part of copy-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eek. What shall we do?

Copy link
Member

Choose a reason for hiding this comment

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

The best of a series of bad options was to do it as part of this block: https://github.com/containers/libpod/blob/f4c3b718eb22a161a897a6ed55d10f3a07e31aa8/libpod/container_internal.go#L1457-L1487

This only happens once, on first creation of the volume

Copy link
Member Author

Choose a reason for hiding this comment

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

If you pass a user by name instead of UID, this will break horribly and use the host's /etc/passwd instead of the container's.

Can we support by name here at all?

Copy link
Member

Choose a reason for hiding this comment

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

If that's OK, it makes things much simpler

Copy link
Member

Choose a reason for hiding this comment

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

can we move the chown later (container_internal_linux.go generateSpec)? We already parse once the /etc/passwd and /etc/group files

Copy link
Member

@giuseppe giuseppe Jun 24, 2020

Choose a reason for hiding this comment

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

looking at it more in details, I think a possible solution is to have an operation like ChownIfEmpty on the volumes that we can use once we read /etc/passwd from the image. We can use it on new volumes that didn't exist before we created the container.

for _, uidmap := range c.config.IDMappings.UIDMap {
if uidmap.ContainerID == 0 {
if uidmap.ContainerID == uid {
Copy link
Member

Choose a reason for hiding this comment

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

is the function supposed to be used only with findUID(0) as it seems in the current version? Otherwise it needs to check if the uid is in the [idmap.ContainerID; idmap.ContainerID+idmap.Size) range and the offset must be added to the return value.

for _, gidmap := range c.config.IDMappings.GIDMap {
if gidmap.ContainerID == 0 {
if gidmap.ContainerID == gid {
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above

@vrothberg
Copy link
Member Author

Closing in favour of #6747.

@vrothberg vrothberg closed this Jun 24, 2020
@vrothberg vrothberg deleted the fix-5698 branch June 24, 2020 14:07
@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 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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.

named volume created when running with userns=keep-id has wrong ownership
4 participants