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

'podman cp' copy between host and container #2151

Merged
merged 1 commit into from
Feb 14, 2019

Conversation

QiWang19
Copy link
Contributor

fix #613 Copy files/folders between a container and the local filesystem
Signed-off-by: Qi Wang [email protected]

cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated
}

if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
Copy link
Member

Choose a reason for hiding this comment

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

On the rootless code here - can we possibly make this work with rootless by leaking the file descriptor for whatever we want to copy into the userns? Wouldn't work for folders, but might be enough to let us copy stuff into rootless containers without using vfs. @giuseppe

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'd need to join the user namespace, once we have joined the user+mount namespace we can also access the storage.

@QiWang19 would you like to take care of it in this PR or would you prefer me to work on it as a followup patch?

Basically we need to use rootless.JoinDirectUserAndMountNS()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@giuseppe sure 👌 , I prefer you work on that

Copy link
Member

Choose a reason for hiding this comment

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

could we just add an error for now? cp should fail when running in rootless mode

cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated
if err != nil {
return err
}
idmappingopts, err := ctr.IDMappings()
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 ctr.IDMappings ever returns an err, so we should probably change the interface.

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 it might return nil sometimes, though - do we need to check if it's non-nil?

Copy link
Member

Choose a reason for hiding this comment

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

Camelcase the idmappingsopts identifier - idMappingOpts

cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
@mheon
Copy link
Member

mheon commented Jan 14, 2019

I think we need to make sure the cases listed in https://docs.docker.com/engine/reference/commandline/cp/ right after the line beginning with Assuming a path separator are properly handled

cmd/podman/cp.go Outdated
}

for _, gsrc := range glob {
esrc, err := filepath.EvalSymlinks(gsrc)
Copy link
Member

Choose a reason for hiding this comment

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

Need to make sure this is scoped into the container if source is container

@mheon
Copy link
Member

mheon commented Jan 14, 2019

Also, I'd love more comments, the code is very hard to follow in places right now

@QiWang19 QiWang19 force-pushed the cp branch 2 times, most recently from 4719679 to b385c3d Compare January 18, 2019 16:51
@QiWang19
Copy link
Contributor Author

libpod/docs/podman-cp.1.md, how to change the current description 😐

cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
cmd/podman/cp.go Outdated Show resolved Hide resolved
@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #2184) made this pull request unmergeable. Please resolve the merge conflicts.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 22, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 1, 2019
@mheon
Copy link
Member

mheon commented Feb 7, 2019

It helps when I press the right button and don't accidentally close PRs

@4383
Copy link
Contributor

4383 commented Feb 7, 2019

@mheon thanks for the explanations :)

So yeah I running containers as a non-root user

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2019

We should through an error right now when they run rootless until @giuseppe Fixes the issues.

@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #2274) made this pull request unmergeable. Please resolve the merge conflicts.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 9, 2019
@openshift-ci-robot openshift-ci-robot added size/L and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL labels Feb 9, 2019
cmd/podman/cp.go Outdated
srcPath = filepath.Join(mountPoint, ctr.WorkingDir(), srcPath)
}
}
glob, _ = filepath.Glob(srcPath)
Copy link
Member

Choose a reason for hiding this comment

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

Don't drop the error here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
}

copyFileWithTar := chrootarchive.CopyFileWithTarAndChown(chownOpts, digest.Canonical.Digester().Hash(), idMappingOpts.UIDMap, idMappingOpts.GIDMap)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a comment here explaining that these return functions for copying items?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

cmd/podman/cp.go Outdated
if err != nil {
return err
}
if srcfi.IsDir() || dest[len(dest)-1] == os.PathSeparator {
Copy link
Member

Choose a reason for hiding this comment

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

Use strings.HasSuffix() instead of the len(dest)-1 here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@rhatdan
Copy link
Member

rhatdan commented Feb 13, 2019

@QiWang19 Lets finish this up tomorrow, I am back in office.

@rhatdan
Copy link
Member

rhatdan commented Feb 14, 2019

LGTM

@mheon
Copy link
Member

mheon commented Feb 14, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 14, 2019
@QiWang19
Copy link
Contributor Author

needs approve label to test tide?

@mheon
Copy link
Member

mheon commented Feb 14, 2019

Oh, nobody approved
/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon, QiWang19

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 Feb 14, 2019
@rhatdan
Copy link
Member

rhatdan commented Feb 14, 2019

/lgtm

@openshift-merge-robot openshift-merge-robot merged commit 18bf883 into containers:master Feb 14, 2019
@QiWang19 QiWang19 deleted the cp branch June 26, 2020 15:09
@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. 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.

cp support
9 participants