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 can overwrite existing files/directories #14420

Closed
Luap99 opened this issue May 30, 2022 · 9 comments · Fixed by #14526
Closed

podman cp can overwrite existing files/directories #14420

Luap99 opened this issue May 30, 2022 · 9 comments · Fixed by #14526
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

@Luap99
Copy link
Member

Luap99 commented May 30, 2022

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

/kind bug

Description

using podman cp incorrect can lead to very easy data loss.
Currently it is possible to overwrite an existing file/directory on the host without any warnings.

I noticed this while looking at #14393.
So my question is why is this an option, and why it is not the default? I cannot imagine that somebody actually would want this and if they do it is simple to just remove the file/directory beforehand.

Steps to reproduce the issue:

podman run --name test alpine touch /test1
$ bin/podman cp ^C
$ mkdir test1
$ bin/podman cp test:/test1 .
$ ls -l test1 
-rw-r--r--. 1 pholzing pholzing 0 May 30 17:36 test1
$ podman run --name test alpine mkdir /test1
$ touch test1
$ bin/podman cp test:/test1 .
$ ls -ld test1
drwxr-xr-x. 1 pholzing pholzing 0 May 30 17:39 test1

Describe the results you received:
The original file/directory is gone.

Describe the results you expected:
An error like the one from cp:
cp: cannot overwrite non-directory './test1' with directory 'test/test1'

Additional information you deem important (e.g. issue happens only occasionally):
Looks like we regressed on this one, I already reported this a long time ago: #7790

Also I verified that docker cp works as I would expect and errors correctly in both cases.

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label May 30, 2022
@vrothberg
Copy link
Member

It screams for regression tests.

@vrothberg
Copy link
Member

I think we need to provide a flag for that on the CLI and let it default to the Docker behavior. There is a risk that we may break certain use cases; having a flag will allow for a quick work around.

@rhatdan @baude WDYT?

@Luap99
Copy link
Member Author

Luap99 commented Jun 1, 2022

An option is fine for me but the default should be to not overwrite.

@rhatdan
Copy link
Member

rhatdan commented Jun 1, 2022

SGTM

@vrothberg
Copy link
Member

@nalind, buildah's copy options NoOverwriteDirNonDir blocks dirs from being replaced with files. But we need the same the other way around. Do you want a new option for that or can we extend NoOverwriteDirNonDir?

@nalind
Copy link
Member

nalind commented Jun 1, 2022

It needs to be a separate option. This logic backends our handling of COPY and ADD instructions in Dockerfiles, and we definitely don't want to change how they behave.

@nalind
Copy link
Member

nalind commented Jun 1, 2022

Correcting myself: we don't set the flag for ADD/COPY, so overloading it wouldn't break them. It's still my preference.

vrothberg added a commit to vrothberg/buildah that referenced this issue Jun 7, 2022
Similar to the `NoOverwriteDirNonDir` one, add an option that disables
non-directories from being overwritten by directories.

Required-for: containers/podman/issues/14420
Signed-off-by: Valentin Rothberg <[email protected]>
@vrothberg
Copy link
Member

-> containers/buildah#4043

vrothberg added a commit to vrothberg/buildah that referenced this issue Jun 7, 2022
Similar to the `NoOverwriteDirNonDir` one, add an option that disables
non-directories from being overwritten by directories.

Required-for: containers/podman/issues/14420
Signed-off-by: Valentin Rothberg <[email protected]>
vrothberg added a commit to vrothberg/buildah that referenced this issue Jun 7, 2022
Similar to the `NoOverwriteDirNonDir` one, add an option that disables
non-directories from being overwritten by directories.

Required-for: containers/podman/issues/14420
Signed-off-by: Valentin Rothberg <[email protected]>
vrothberg added a commit to vrothberg/buildah that referenced this issue Jun 7, 2022
Similar to the `NoOverwriteDirNonDir` one, add an option that disables
non-directories from being overwritten by directories.

Required-for: containers/podman/issues/14420
Signed-off-by: Valentin Rothberg <[email protected]>
@vrothberg
Copy link
Member

-> #14526

vrothberg added a commit to vrothberg/libpod that referenced this issue Jun 10, 2022
Add a new `--overwrite` flag to `podman cp` to allow for overwriting in
case existing users depend on the behavior; they will have a workaround.
By default, the flag is turned off to be compatible with Docker and to
have a more sane behavior.

Fixes: containers#14420
Signed-off-by: Valentin Rothberg <[email protected]>
nalind pushed a commit to nalind/buildah that referenced this issue Aug 3, 2022
Similar to the `NoOverwriteDirNonDir` one, add an option that disables
non-directories from being overwritten by directories.

Required-for: containers/podman/issues/14420
Signed-off-by: Valentin Rothberg <[email protected]>
@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 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 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