libpod: honor volume subpath in cp #29842
Hi! Just a quick follow-up on #29842.
The CI is green now, and the PR includes regression coverage for both copy-in and copy-out with named-volume subpaths across created, running, and stopped containers.
Whenever someone has a chance, I’d really appreciate a review. Thanks!
This PR only fixes named volume subpaths in resolvePath. Image mounts (type=image, subpath=…) still don’t work for podman cp when the container isn’t running. I get ENOENT on created contianer, while running cp works (see repro below).
ctr="img-cp-test"
./bin/podman rm -f "$ctr" 2>/dev/null
./bin/podman create --name "$ctr" --network=none --mount "type=image,source=alpine,dst=/mnt,subpath=/bin" alpine sleep 3600
./bin/podman cp "$ctr:/mnt/ls" /tmp/from-created
# expect: Error: no such file or directory (container not started)
./bin/podman start "$ctr"
./bin/podman cp "$ctr:/mnt/ls" /tmp/from-running
# expect: success
./bin/podman exec "$ctr" ls -l /mnt/ls
./bin/podman rm -f "$ctr"
Otherwise LGTM. It would be good to also fix this for images.
what is preventing mountPoint to be replaced with a symlink after this operation and later mountPoint points on the host?
This can happen, for example, if the volume is shared
Good catch, thanks. You’re right that SecureJoin alone left a race here. I’ve pushed a fix that keeps the volume subpath pinned until the stat or copy finishes, and added a regression test for replacing it with a symlink.
I wonder if we could just do securejoin.SecureJoin(mountPoint, filepath.Join(subPath, pathRelativeToVolume)): one single securejoin on the original mountPoint
would that work?
we need to make sure all callers of resolvePath are closing the safeMount now to avoid a leak
I don’t think that closes the race, unfortunately. Even with one SecureJoin, we’d still get a path string that could change before stat or cp uses it. The open file descriptor and bind mount are what keep the selected subpath in place for the operation.
I confused about where should I answer, so removed twice before :)
Good point. I went through the callers: both copy-in and copy-out keep the mount until the copy is done, and close it on errors too. resolvePath also closes it if the final SecureJoin fails. I don’t see a path where it gets left open.
@Honny1 Thanks for checking this and for the repro. You’re right about image mounts. I’d like to keep this PR focused on #29840 and track the image-mount case separately.
@Honny1 Thanks for checking this and for the repro. You’re right about image mounts. I’d like to keep this PR focused on #29840 and track the image-mount case separately.
Sure, just please create an issue for that case. I don't want to forget about that.
> @Honny1 Thanks for checking this and for the repro. You’re right about image mounts. I’d like to keep this PR focused on #29840 and track the image-mount case separately.
> Sure, just please create an issue for that case. I don't want to forget about that.
Hello, created:
https://github.com/podman-container-tools/podman/issues/29857
Thanks, it seems it will need to be rebased on upstream main.
@Honny1 Thanks for the heads-up. I’ve rebased on upstream main and resolved the conflicts. Could you please review the PR so we can get it merged?
LGTM
once @giuseppe and @pooyanazad come to agreement on the securejoin question.
LGTM
giuseppe
pooyanazad
When copying files from created or stopped containers,
podman cpresolves named volumes on the host instead of using the container mount namespace. The host-side resolution currently starts at the volume root and ignores the mount's configured subpath, socpcan read a different file than the one visible inside the container.Apply the configured volume subpath before resolving the remaining container path. Keep the path within the volume using secure path resolution and add coverage for created, running, and stopped containers.
Fixes: #29840
<!-- Thanks for sending a pull request! -->
Checklist
Ensure you have completed the following checklist for your pull request to be reviewed:
<!-- Use [x] to mark as done, or click the checkbox after opening PR -->
git commit -s). (If needed, usegit commit -s --amend). The author email must match the sign-off email address. See CONTRIBUTING.md for more information.Fixes: #00000in commit message (if applicable)make validatepr(format/lint checks)Noneif no user-facing changes)Does this PR introduce a user-facing change?
<!--
Write
Noneif users do not need to take action. Otherwise enter the release note below.Include "action required" if users need to take action when upgrading.
-->
``
release-note
`podman cp now respects named-volume subpaths when copying files from created and stopped containers.
Validation
passed.did not complete because the validation image was missing the PerlTest::Differences` module.