Bug 1470962 - oc cp a file to container's folder will fail when the path doesn't ended up with slash [NEEDINFO]
oc cp a file to container's folder will fail when the path doesn't ended up w...
Status: ASSIGNED
Product: OpenShift Container Platform
Classification: Red Hat
Component: Command Line Interface (Show other bugs)
3.6.0
Unspecified Unspecified
medium Severity low
: ---
: ---
Assigned To: Juan Vallejo
Xingxing Xia
: Rebase
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-14 03:09 EDT by XiaochuanWang
Modified: 2017-10-30 11:38 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
jvallejo: needinfo? (ffranz)


Attachments (Terms of Use)

  None (edit)
Description XiaochuanWang 2017-07-14 03:09:46 EDT
Description of problem:
Run a pod container, try to copy file from local to a container's folder but not ended up with slash.

Version-Release number of selected component (if applicable):
oc v3.6.141

How reproducible:
Always

Steps to Reproduce:
1. $ touch test
$ oc run mypod --image=aosqe/hello-openshift --generator='run-pod/v1'
Then wait for pod Running.
2. $ oc cp test mypod:/tmp
3. (For compare) $ oc cp test mypod:/tmp/
$ oc rsh mypod ls /tmp
test

Actual results:
2. 
tar: can't open 'test': Permission denied
command terminated with exit code 1


Expected results:
Step 2 should be same with step 3

Additional info:
# oc cp test mypod:/
tar: can't open 'test': Permission denied
command terminated with exit code 1
Comment 1 Juan Vallejo 2017-08-23 17:38:46 EDT
Right now, `oc cp` does not actually check to see if the destination path you provided exists, is a directory, etc. We simply take the "directory" portion of your destination argument as described in https://golang.org/pkg/path/#Dir:

[Example 1]
Local Source File: "test"
Destination: "mypod:/tmp/"
Becomes: <in remote pod>$ tar xf - -C /tmp

Meaning that we first change directory to "/tmp" before extracting the contents specified into the current working directory, using the original source filename "test". So you end up with a new file in the pod "/tmp/test".

or

[Example 2]
Local Source File: "test"
Destination: "mypod:/tmp"
Becomes: <in remote pod>$ tar xf - -c /

Meaning that we first change directory to "/" before extracting the contents into it using the original source name "test".
Since we cannot create a new file named "test" in the root directory of the pod, we end up with the error: "tar: can't open 'test': Permission denied"


A recent PR (https://github.com/openshift/origin/pull/15929) aims to update the copy command, such that the name you specify in your destination path is actually used. For example, given the following:

Local Source File: "test"
Destination: "mypod:/tmp/mycustomname"

You would copy the local file "test" under a new file "/tmp/mycustomname" in the remote pod (right now, the file gets copied under "/tmp/test" in the pod, and "mycustomname" is ignored).


With this in mind, I could update the existing PR (15929) to additionally check for a trailing "/" in the destination path, such that if you have the following:

Local Source File: "test"
Destination: "mypod:/tmp/"

The current behavior of using the Local Source File name is kept. So you would end up with a new file "/tmp/test" in the remote pod.

Because the command does not check if "tmp" already exists and is a directory in the remote pod, without a trailing "/", [Example 2] with the updated `oc cp` command (with patch 15929 applied) would now give the error "tar: tmp: Cannot open: File exists", meaning that in the root directory, there is already a file or directory named "tmp" (your chosen destination) and therefore is unable to proceed.
Comment 2 Juan Vallejo 2017-10-25 15:13:48 EDT
This has been addressed by two related upstream PRs: 

- https://github.com/kubernetes/kubernetes/pull/51215
- https://github.com/kubernetes/kubernetes/pull/52465

Marking as UpcomingRelease

Note You need to log in before you can comment on or make changes to this bug.