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

Do not chown newly created volume sources #16782

Closed
wants to merge 1 commit into from

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Dec 7, 2022

When running containers with

podman run --userns=keep-id --userns $UID:$GID -v test:/tmp/test ...

The volumes directory ends up being owned by root within the user namespace, which is not root of the general namespace nor the users uid.

If we just allow podman to create these directories with the same UID that is running podman, IE don't chown, they end up with the correct UID in all cases.

The actual volume will be chowned to the UID of the container.

Fixes: #16741

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

Does this PR introduce a user-facing change?

Builtin volumes with --userns=keep-id will get proper permissions.

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 7, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Dec 9, 2022

@containers/podman-maintainers PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

@edsantiago PTAL

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan, 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

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM, @mheon PTAL

@@ -151,9 +151,6 @@ func (r *Runtime) newVolume(ctx context.Context, noCreatePluginVolume bool, opti
if err := os.MkdirAll(volPathRoot, 0700); err != nil {
return nil, fmt.Errorf("creating volume directory %q: %w", volPathRoot, err)
}
if err := idtools.SafeChown(volPathRoot, volume.config.UID, volume.config.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.

This isn't going to work, volume.config.UID and volume.config.GID are actual options that can be set during volume creation.

Should we stop defaulting them to the container's UID/GID instead, and make this happen if and only if they were deliberately set?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the tests checks that case.
The problem was the higher level directories were being set incorrectly. We just want them to default to the users uid running podman.

Copy link
Member Author

Choose a reason for hiding this comment

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

BTW, the answer is yes they should only be set if the user sets them. but not sure how that info can be recorded, I guess we could default the UID/GID to -1?

@mheon
Copy link
Member

mheon commented Dec 12, 2022 via email

@rhatdan rhatdan force-pushed the volume branch 2 times, most recently from 686e37a to 11cbb28 Compare December 22, 2022 14:17
@rhatdan
Copy link
Member Author

rhatdan commented Dec 22, 2022

@mheon PTAL

@rhatdan rhatdan force-pushed the volume branch 3 times, most recently from 0c54ae9 to d609f69 Compare December 26, 2022 12:38
return os.Getuid(), gid
case gid == -1:
return uid, os.Getgid()
}
Copy link
Member

Choose a reason for hiding this comment

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

Personal nit, YMMV.
In general, I've not been a fan of equality tests for -1. Can we convert these to uid > -1 or uid < 0 or some such?

@TomSweeneyRedHat
Copy link
Member

@rhatdan tests are still being touchy.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 7, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2023
@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@rhatdan rhatdan removed the stale-pr label Feb 19, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 13, 2023
When running containers with

podman run --userns=keep-id --userns $UID:$GID -v test:/tmp/test ...

The volumes directory ends up being owned by root within the user
namespace, which is not root of the general namespace nor the users
uid.

If we just allow podman to create these directories with the same UID
that is running podman, IE don't chown, they end up with the correct
UID in all cases.

The actual volume will be chowned to the UID of the container.

Fixes: containers#16741

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@vrothberg
Copy link
Member

Friendly ping, @rhatdan.

I am going through open PRs and this one seems to have fallen off the radar.

@rhatdan
Copy link
Member Author

rhatdan commented Apr 4, 2023

Yup. this one I think we really should have @mheon take over, since he understands this the best and I have little time to look into it.

@vrothberg
Copy link
Member

Going through old inactive PRs...
Feel free to re-open when reviving it.

@vrothberg vrothberg closed this Jul 31, 2023
@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 Oct 30, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 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. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman run is not honoring --userns=keep-id --user=1000:1000 settings while creating volumes
6 participants