Repository navigation
Fix host UID/GID leakage in copyFileToContainer TAR entries - #11929
Gautam-aman wants to merge 1 commit into
Conversation
|
This revives the approach from #11488, which was |
|
We hit the same bug on rootless Podman, where it fails harder than on rootless Docker: the copy itself is rejected and the container never starts. Setup: Testcontainers 2.0.5, commons-compress 1.28.0, Podman 5.8.2 rootless (API socket), RHEL 9.9. The host user is a directory (AD) account with a large UID (9-digit), far outside the 65536 IDs mapped into the user namespace. Reproduction:
Workaround: copying the same bytes with Happy to test a snapshot build. |
myroch
left a comment
There was a problem hiding this comment.
Thanks for picking this up again. The change itself looks right to me: recursiveTar is the only place MountableFile creates entries, so files, nested files and directory entries are all covered, and resetting the owner after new TarArchiveEntry(File, …) is the right order, since that constructor is what reads unix:uid/unix:gid.
A few points that might help get it merged:
-
Behaviour change on rootful Docker. Today the host UID is kept. When it happens to match the container user (often 1000), a
0600file copied in stays readable for that user. With root ownership it no longer is, for any image that doesn't run as root. That's probably the main thing to decide, and worth a note in the PR description and changelog. Whether it needs an opt-out is for the maintainers, butMountableFile.forHostPath(path, mode)already lets users widen the mode, which could be the suggested migration. -
Test:
- Please drop the
System.out.printlnlines. - The assertion also passes without the fix when the build runs as root (UID 0). It's fine on the GitHub runners, but checking that the source file's
unix:uidis non-zero first (orassumeTrueon it) would make the test meaningful everywhere. - A case for a copied directory (nested file plus directory entry) would cover the recursive path.
- Optionally assert
getUserName()/getGroupName()too, since the PR sets them.
- Please drop the
-
Branch: it's quite a bit behind
main. A rebase would let the full CI run once a maintainer approves the workflow.
Fixes #11487
When copyFileToContainer copies a MountableFile,
TAR entries may carry host UID/GID values into
the container.
On rootless Docker setups these IDs may be
unmapped, causing permission and ownership issues.
This change normalizes TAR entry ownership to
uid=0 and gid=0 and adds a regression test.