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

ADD/COPY: create the destination directory first, chroot to it #3015

Merged
merged 5 commits into from
Mar 3, 2021

Conversation

nalind
Copy link
Member

@nalind nalind commented Feb 16, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

When extracting archives that include symbolic links and paths accessed through those links, we would chroot to the root of the container's filesystem rather than the destination directory. While we didn't write outside of the container's root directory, this allowed for cases where we put things in different locations than docker build would.

How to verify it

New conformance tests!
Additions to unit tests!

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

None

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 16, 2021
@nalind
Copy link
Member Author

nalind commented Feb 16, 2021

/cc @vrothberg

@rhatdan
Copy link
Member

rhatdan commented Feb 16, 2021

LGTM

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @nalind

GIDMap: destGIDMap,
ChownNew: chownDirs,
}
if err := copier.Mkdir(mountPoint, extractDirectory, mkdirOptions); 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.

Would it be possible to move that down into the copier package? podman cp would benefit from it, also when copying from a container to the host.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not without pretty drastic restructuring - in cases where the destination doesn't exist yet, and the path can include components which are symbolic links, we have to chroot to the rootfs first, then evaluate the path for symbolic links, then create the target directory, and then chroot to the target directory, and trying to stuff all of that into Put() broke just about every other unit test and several integration tests. In the end, having Add() do both an Eval() and a Mkdir() explicitly looks much easier to test.

@TomSweeneyRedHat
Copy link
Member

LGTM, but may need a rebase.
A good candidate for the first update of RHEL 8.4.

@rhatdan
Copy link
Member

rhatdan commented Feb 24, 2021

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nalind, 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

nalind added 2 commits March 1, 2021 16:55
If the subprocess exits with an error, but we can't decode its stdout as
a proper status result, check if it produced error output.  If it did,
then return its error output as the error.

Signed-off-by: Nalin Dahyabhai <[email protected]>
When attempting to handle renames, we'd fail to correctly handle renames
of prefixes of a given item's path because of a string handling error,
and add a unit test for the rename logic (finally).

Signed-off-by: Nalin Dahyabhai <[email protected]>
@nalind nalind force-pushed the copier-mkdir-first branch from c9dd9ce to 42d2f42 Compare March 2, 2021 21:22
nalind added 3 commits March 2, 2021 16:29
Add copier.Eval(), for expanding paths using symbolic links in a
chrooted scope, without failing if a path component doesn't exist.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Add a NoDerefSymlinks flag to force items that are matched to the Globs
we're given to be treated as symlinks, rather than dereferencing them as
we would need to do for sources for ADD or COPY.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Always create the destination directory first when ADDing or COPYing
content into a container, then extract contents into it using the
destination directory as the chroot instead of the container's root
directory.

Signed-off-by: Nalin Dahyabhai <[email protected]>
@nalind nalind force-pushed the copier-mkdir-first branch from 42d2f42 to effb375 Compare March 2, 2021 21:29
@nalind
Copy link
Member Author

nalind commented Mar 2, 2021

Added copier.Eval() and the copier.GetOptions.NoDerefSymlinks flag.

@rhatdan
Copy link
Member

rhatdan commented Mar 3, 2021

/lgtm

@vrothberg
Copy link
Member

Can we backport the changes? I need them in Podman 3.0.

@TomSweeneyRedHat
Copy link
Member

@vrothberg But not for RHEL 8.4 right?

@vrothberg
Copy link
Member

@TomSweeneyRedHat, especially for 8.4. This will help fix the reported podman cp bugs.

@rhatdan
Copy link
Member

rhatdan commented Mar 4, 2021

Do we have a bugzilla for this? I have opened a PR to podman to vendor in the latest buildah 1.19.7.

@vrothberg
Copy link
Member

Do we have a bugzilla for this? I have opened a PR to podman to vendor in the latest buildah 1.19.7.

Not yet. There is a number of podman cp bugs that we've fixed (and continue fixing). I prefer to have one BZ that addresses these at once. Some of these fixes depend on another, so it would very tough to untangle them.

@vrothberg
Copy link
Member

vrothberg commented Mar 5, 2021

There are some challenges in Podman since we have to create the destination directory in some cases. It works well in Buildah but with the remote client in Podman, it's tricky.

@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
approved kind/bug Categorizes issue or PR as related to a bug. lgtm locked - please file new issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants