daemon: fix docker cp when container source is /

Before 7a7357da, archive.TarResourceRebase was being used to copy files
and folders from the container. That function splits the source path
into a dirname + basename pair to support copying a file:
if you wanted to tar `dir/file` it would tar from `dir` the file `file`
(as part of the IncludedFiles option).

However, that path splitting logic was kept for folders as well, which
resulted in weird inputs to archive.TarWithOptions:
if you wanted to tar `dir1/dir2` it would tar from `dir1` the directory
`dir2` (as part of IncludedFiles option).

Although it was weird, it worked fine until we started chrooting into
the container rootfs when doing a `docker cp` with container source set
to `/` (cf 3029e765).

The fix is to only do the path splitting logic if the source is a file.

Unfortunately, 7a7357da added support for LCOW by duplicating some of
this subtle logic. Ideally we would need to do more refactoring of the
archive codebase to properly encapsulate these behaviors behind well-
documented APIs.

This fix does not do that. Instead, it fixes the issue inline.

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 171538c190ee3a1a8211946ab8fa78cdde54b47a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 file changed
tree: cb62330d4205ca2b91674a29fdd06dd1681642f2
  1. .github/
  2. api/
  3. builder/
  4. cli/
  5. client/
  6. cmd/
  7. container/
  8. contrib/
  9. daemon/
  10. distribution/
  11. dockerversion/
  12. docs/
  13. errdefs/
  14. hack/
  15. image/
  16. integration/
  17. integration-cli/
  18. internal/
  19. layer/
  20. libcontainerd/
  21. migrate/
  22. oci/
  23. opts/
  24. pkg/
  25. plugin/
  26. profiles/
  27. project/
  28. reference/
  29. registry/
  30. reports/
  31. restartmanager/
  32. runconfig/
  33. vendor/
  34. volume/
  35. .DEREK.yml
  36. .dockerignore
  37. .gitignore
  38. .mailmap
  39. AUTHORS
  40. CHANGELOG.md
  41. codecov.yml
  42. CONTRIBUTING.md
  43. Dockerfile
  44. Dockerfile.e2e
  45. Dockerfile.simple
  46. Dockerfile.windows
  47. LICENSE
  48. MAINTAINERS
  49. Makefile
  50. NOTICE
  51. poule.yml
  52. README.md
  53. ROADMAP.md
  54. TESTING.md
  55. vendor.conf
  56. VENDORING.md
README.md

The Moby Project

Moby Project logo

Moby is an open-source project created by Docker to enable and accelerate software containerization.

It provides a “Lego set” of toolkit components, the framework for assembling them into custom container-based systems, and a place for all container enthusiasts and professionals to experiment and exchange ideas. Components include container build tools, a container registry, orchestration tools, a runtime and more, and these can be used as building blocks in conjunction with other tools and projects.

Principles

Moby is an open project guided by strong principles, aiming to be modular, flexible and without too strong an opinion on user experience. It is open to the community to help set its direction.

  • Modular: the project includes lots of components that have well-defined functions and APIs that work together.
  • Batteries included but swappable: Moby includes enough components to build fully featured container system, but its modular architecture ensures that most of the components can be swapped by different implementations.
  • Usable security: Moby provides secure defaults without compromising usability.
  • Developer focused: The APIs are intended to be functional and useful to build powerful tools. They are not necessarily intended as end user tools but as components aimed at developers. Documentation and UX is aimed at developers not end users.

Audience

The Moby Project is intended for engineers, integrators and enthusiasts looking to modify, hack, fix, experiment, invent and build systems based on containers. It is not for people looking for a commercially supported system, but for people who want to work and learn with open source code.

Relationship with Docker

The components and tools in the Moby Project are initially the open source components that Docker and the community have built for the Docker Project. New projects can be added if they fit with the community goals. Docker is committed to using Moby as the upstream for the Docker Product. However, other projects are also encouraged to use Moby as an upstream, and to reuse the components in diverse ways, and all these uses will be treated in the same way. External maintainers and contributors are welcomed.

The Moby project is not intended as a location for support or feature requests for Docker products, but as a place for contributors to work on open source code, fix bugs, and make the code more useful. The releases are supported by the maintainers, community and users, on a best efforts basis only, and are not intended for customers who want enterprise or commercial support; Docker EE is the appropriate product for these use cases.


Legal

Brought to you courtesy of our legal counsel. For more context, please see the NOTICE document in this repo.

Use and transfer of Moby may be subject to certain restrictions by the United States and other governments.

It is your responsibility to ensure that your use and/or transfer does not violate applicable laws.

For more information, please see https://www.bis.doc.gov

Licensing

Moby is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.