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

Support volume bind mounts for rootless containers #12687

Merged
merged 1 commit into from
Jan 6, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Dec 22, 2021

Fix handling of "bind" volumes to actually work.
Allow bind volumes to work in rootless mode.

Also removed the string "error" from all error messages that begine with it.
All Podman commands are printed with Error:, so this causes an ugly
stutter.

Fixes: #12013

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 22, 2021
@rhatdan
Copy link
Member Author

rhatdan commented Dec 22, 2021

@mheon PTAL

switch key {
case "device", "o", "type", "UID", "GID", "SIZE", "INODES":
case "device":
if _, err := os.Stat(val); 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 think this might be undesirable - e.g. for tmpfs device can be set to anything, so long as the destination path is valid

libpod/volume.go Outdated
var rootlessVolume = map[string]bool{
"": true,
"local": true,
"bind": true,
Copy link
Member

Choose a reason for hiding this comment

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

tmpfs should also go here

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

Copy link
Member

Choose a reason for hiding this comment

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

Why do we validate this at all? Rootless users could also use fuse based file systems. Can we just skip the check and handle errors from the mount command?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is what I am trying to figure out.

@rhatdan rhatdan force-pushed the volume branch 4 times, most recently from b6a4131 to 8d137ec Compare December 23, 2021 20:20
@rhatdan
Copy link
Member Author

rhatdan commented Dec 26, 2021

@mheon @vrothberg @baude PTAL
@containers/podman-maintainers PTAL

for key, val := range volume.config.Options {
switch strings.ToUpper(key) {
case "DEVICE":
switch volume.config.Options["type"] {
Copy link
Member

Choose a reason for hiding this comment

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

Probably want to ToLower() this to ensure no case-comparison issues

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

return nil, errors.Wrapf(err, "invalid volume option %s for driver 'local'", key)
}
case "tmpfs":
if val != "tmpfs" {
Copy link
Member

Choose a reason for hiding this comment

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

Do we enforce this? I think this might break existing volumes, tmpfs used to be able to use any string here

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the check.

@@ -33,7 +33,7 @@ func (v *Volume) mount() error {
}

// We cannot mount 'local' volumes as rootless.
if !v.UsesVolumeDriver() && rootless.IsRootless() {
if rootless.IsRootless() && v.RequiresRoot() {
Copy link
Member

Choose a reason for hiding this comment

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

You need to retain the !UsesVolumeDriver() - that catches volume plugins

Copy link
Member Author

Choose a reason for hiding this comment

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

@mheon what drivers are not supported in rootless mode?
I think "local", "bind", "tmpfs" and "" are all supported. If all UserVolumeMounts are supported, or at least allow them to fail themselves. I

Copy link
Member

Choose a reason for hiding this comment

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

Bind and tmpfs are not drivers, they're methods the local plugin can use to mount.

The local driver (and "", an alias to it) is supported rootless, in a limited fashion - only the kernel mount types that can be used in a rootless user namespace will work.

Any drivers that aren't local are supported (these would be volume plugins), though we make no promises that a given volume plugin actually works with rootless 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.

I removed both checks, just allow the mount and unmount commands to fail. Don't try to decide what is supported and what is not.

Copy link
Member

Choose a reason for hiding this comment

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

Works for me

Fix handling of "bind" and "tmpfs" olumes to actually work.
Allow bind, tmpfs local volumes to work in rootless mode.

Also removed the string "error" from all error messages that begine with it.
All Podman commands are printed with Error:, so this causes an ugly
stutter.

Fixes: containers#12013

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

mheon commented Jan 5, 2022

LGTM
@containers/podman-maintainers PTAL

@flouthoc
Copy link
Collaborator

flouthoc commented Jan 6, 2022

@rhatdan @mheon

Before this PR does podman volume create -o type=bind -o device=/somepath vol-name worked for root users ? I think not I tried with main branch and we were passing type in the wrong flag.

Following PR fixes this.

One side effect which I found is: Dont know if its expected or not but once we bind mount from root user podman changes UID on the host for specified the path causing the path to become un-useful for rootless users.

Reproducer

Try running same example in test

  • first via root
  • second via rootless for same path.

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM. Just one doubt in above comment.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 6, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, rhatdan

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

@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Jan 6, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Jan 6, 2022

@flouthoc can you give the steps to reproduce.

podman volume create -o type=bind -o device=/somepath vol-name
This should only work iff /somepath exists. If not then when you go to use the mount it will fail. Better to catch this earlier.

@openshift-merge-robot openshift-merge-robot merged commit 755b7aa into containers:main Jan 6, 2022
@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 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 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. lgtm Indicates that a PR is ready to be merged. 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.

Support type=bind mounts for rootless named volumes
5 participants