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 dereferences symlink in host context after filepath.Glob(srcPath) #3829

Closed
eriksjolund opened this issue Aug 15, 2019 · 5 comments
Closed
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@eriksjolund
Copy link
Contributor

eriksjolund commented Aug 15, 2019

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

podman cp mycontainer:/testfile /tmp/test

may resolve a symlink in the host context (e.g. the file /tmp/hostdir/hello.txt) and copy it into
the directory /tmp/test

Steps to reproduce the issue:

erik@laptop:/tmp$ mkdir /tmp/hostdir
erik@laptop:/tmp$ echo hello > /tmp/hostdir/hello.txt
erik@laptop:/tmp$ cat /tmp/build.sh 
container=$(buildah from scratch)                                                                                                    
mnt=$(buildah mount $container)

touch "$mnt/file*"
ln -s "/file*" "$mnt/testfile"
ln -s "/tmp/hostdir/hello.txt" "$mnt/file_symlink_to_hostfile"

buildah umount $container
buildah commit $container glob1

erik@laptop:/tmp$ buildah unshare bash /tmp/build.sh && container=$(podman create localhost/glob1 dummycmd) 
442548187b2cb9fb3ee953a1987b643d50e7c42549b731aacc8a5ac9ebef083e
Getting image source signatures
Copying blob d3c1b073cbdd done
Copying config 6492f94e90 done
Writing manifest to image destination
Storing signatures
6492f94e909731586eecbd470ad2a9c378dc87fc2eb7e3d89712dfd4011170b4
erik@laptop:/tmp$ rm -rf /tmp/test && mkdir /tmp/test && podman cp $container:/testfile /tmp/test

Describe the results you received:

erik@laptop:/tmp$ ls -l /tmp/test
total 4
-rw-rw-r-- 1 erik erik 0 Aug 15 20:43 'file*'
-rw-rw-r-- 1 erik erik 6 Aug 15 20:34  hello.txt
erik@laptop:/tmp$ 

Describe the results you expected:

I would not have expected to see the files /tmp/test/hello.txt and /tmp/test/file*

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

erik@laptop:/tmp$ podman --version
podman version 1.5.0
WARN[0000] unable to find /home/erik/.config/containers/registries.conf. some podman (image shortnames) commands may be limited 
erik@laptop:/tmp$

Output of podman info --debug:

erik@laptop:/tmp$ podman info --debug
debug:
  compiler: gc
  git commit: ""
  go version: go1.10.4
  podman version: 1.5.0
host:
  BuildahVersion: 1.10.1
  Conmon:
    package: 'conmon: /usr/bin/conmon'
    path: /usr/bin/conmon
    version: 'conmon version 2.0.0, commit: unknown'
  Distribution:
    distribution: ubuntu
    version: "18.04"
  MemFree: 199711514624
  MemTotal: 201407889408
  OCIRuntime:
    package: Unknown
    path: /home/erik/crun/crun/static-build/crun
    version: |-
      crun 0.7
      spec: 1.0.0
      +SELINUX +CAP +SECCOMP +EBPF +YAJL
  SwapFree: 107374178304
  SwapTotal: 107374178304
  arch: amd64
  cpus: 32
  eventlogger: journald
  hostname: laptop
  kernel: 5.0.0-23-generic
  os: linux
  rootless: true
  uptime: 36h 26m 18.07s (Approximately 1.50 days)
registries:
  blocked: null
  insecure: null
  search: null
store:
  ConfigFile: /home/erik/.config/containers/storage.conf
  ContainerStore:
    number: 195
  GraphDriverName: overlay
  GraphOptions:
  - overlay.mount_program=/usr/bin/fuse-overlayfs
  GraphRoot: /home/erik/.local/share/containers/storage
  GraphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  ImageStore:
    number: 102
  RunRoot: /run/user/1000
  VolumePath: /home/erik/.local/share/containers/storage/volumes

erik@laptop:/tmp$ 

Additional environment details (AWS, VirtualBox, physical, etc.):

erik@laptop:/tmp$ buildah --version
buildah version 1.10.1 (image-spec 1.0.1, runtime-spec 1.0.1-dev)
erik@laptop:/tmp$ cat /etc/issue
Ubuntu 18.04.3 LTS \n \l
@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 15, 2019
@mheon
Copy link
Member

mheon commented Aug 15, 2019

/etc/host is always a bind-mount to a container-local copy of the host's /etc/host. I would expect that if you passed --dns to that podman create you'd find the contents were suddenly different.

Still, podman cp is definitely doing the wrong thing here, I think - albeit it's doing it entirely in container context.

@mheon
Copy link
Member

mheon commented Aug 15, 2019

Sorry, replace --dns with --add-host - oops

@eriksjolund
Copy link
Contributor Author

Sorry, I used some other file path and did a replace string in my editor to get /etc/hosts . That was not a good idea I realize now. I thought the actual file path was irrelevant.
Anyway I have now edited the original bug description and changed
the file path to /tmp/hostdir/hello.txt and re-run the example again on the computer.

@eriksjolund
Copy link
Contributor Author

And I verified that the file /tmp/hostdir/hello.txt was not included in the container,
by running podman unshare and podman mount $container

erik@laptop:/tmp# ls -l $mnt 
total 0
-rw-rw-r-- 1 root root  0 Aug 15 20:59 'file*'
lrwxrwxrwx 1 root root 22 Aug 15 20:59  file_symlink_to_hostfile -> /tmp/hostdir/hello.txt
lrwxrwxrwx 1 root root  6 Aug 15 20:59  testfile -> '/file*'
erik@laptop:/tmp# 

jwhonce added a commit to jwhonce/podman that referenced this issue Aug 16, 2019
jwhonce added a commit to jwhonce/podman that referenced this issue Aug 16, 2019
jwhonce added a commit to jwhonce/podman that referenced this issue Aug 16, 2019
@eriksjolund
Copy link
Contributor Author

eriksjolund commented Aug 18, 2019

Another thing (not strictly this bug but closely related) is the handling of "-". The check to see if such a command line argument is given should be done on the actual command line arguments given (not on the result of symlink dereferencing or filepath.Base(destPath)).

jwhonce added a commit to jwhonce/podman that referenced this issue Aug 19, 2019
jwhonce added a commit to jwhonce/podman that referenced this issue Aug 19, 2019
jwhonce added a commit to jwhonce/podman that referenced this issue Aug 21, 2019
jwhonce added a commit to jwhonce/podman that referenced this issue Aug 21, 2019
edsantiago added a commit to edsantiago/libpod that referenced this issue Aug 26, 2019
podman cp has had some unexpected bugs, and still has
some surprising behavior. It looks like this part of
the code is fragile. Add tests to try to prevent
future breakages.

Note that two of the new tests are disabled (skipped)
until containers#3829 gets fixed.

Signed-off-by: Ed Santiago <santiago@redhat.com>
edsantiago added a commit to edsantiago/libpod that referenced this issue Aug 26, 2019
podman cp has had some unexpected bugs, and still has
some surprising behavior. It looks like this part of
the code is fragile. Add tests to try to prevent
future breakages.

Note that two of the new tests are disabled (skipped)
until containers#3829 gets fixed.

Signed-off-by: Ed Santiago <santiago@redhat.com>
@jwhonce jwhonce self-assigned this Sep 4, 2019
jwhonce added a commit to jwhonce/podman that referenced this issue Sep 4, 2019
* Do not repeatedly follow symlinks
* Do not support wildcards

Fixes containers#3829
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1741709

Signed-off-by: Jhon Honce <jhonce@redhat.com>
weirdwiz pushed a commit to weirdwiz/libpod that referenced this issue Sep 5, 2019
podman cp has had some unexpected bugs, and still has
some surprising behavior. It looks like this part of
the code is fragile. Add tests to try to prevent
future breakages.

Note that two of the new tests are disabled (skipped)
until containers#3829 gets fixed.

Signed-off-by: Ed Santiago <santiago@redhat.com>
@jwhonce jwhonce closed this as completed Sep 25, 2019
edsantiago added a commit to edsantiago/libpod that referenced this issue Oct 2, 2019
Issue containers#3829 (cp symlinks) has been fixed: enable tests for it

And, it looks like podman-remote is now handling exit status
of a force-rm'ed container. Enable that test too.

Signed-off-by: Ed Santiago <santiago@redhat.com>
@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 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. 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 a pull request may close this issue.

4 participants