Confine symlinks to root during Windows unpack - #33
Closed
rzlink wants to merge 1 commit into
Closed
Conversation
Windows has no chroot, so chrootarchive unpacks inline against the real filesystem. As a result an archive symlink whose target escapes the extraction root was rejected outright, which breaks `ADD <tar> /` builds that Linux handles fine inside its chroot (moby/moby#47107). Add a TarOptions.ConfineSymlinksToRoot flag, set by chrootarchive's Windows invokeUnpack, that scope-confines symlink resolution to the extraction root (secureJoinScope). With it, an escaping symlink is created rather than rejected, and any entry written through it resolves back inside the root instead of breaking out - the Windows analogue of the containment the Linux path gets from chroot. Plain archive.Unpack is unchanged: without the flag it still rejects escaping symlinks, so the existing TestUntarInvalidSymlink breakout guarantees are preserved. Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Windows has no
chroot, sochrootarchiveunpacks inline against the real filesystem (seechrootarchive/archive_windows.go). As a result, an archive symlink whose target escapes the extraction root is rejected outright by thestrings.HasPrefix(targetPath, extractDir)check increateTarFile. That breaksADD <tar> /style builds on Windows that Linux handles fine, because on Linux the same unpack runs inside a chroot that simply contains the escaping symlink.This is the BuildKit/Windows-containers manifestation of moby/moby#47107 (
TestBuildSymlinkBreakout, currentlyskip.If(UsingSnapshotter, ...)).Approach
Add an opt-in
TarOptions.ConfineSymlinksToRootflag:chrootarchive's WindowsinvokeUnpack. It scope-confines symlink resolution to the extraction root via a newsecureJoinScopehelper (traversal semantics ported fromcontainerd/continuityfs.RootPath): an escaping symlink is created rather than rejected, and any entry written through it resolves back inside the root instead of breaking out — the Windows analogue of the containment the Linux path gets from chroot.archive.Unpack/Untarare unchanged: without the flag they still reject escaping symlinks, so the existingTestUntarInvalidSymlink/TestApplyLayerInvalidSymlinkbreakout guarantees are fully preserved.Tests
chrootarchive/archive_windows_test.go: TestUntarSymlinkScopeConfine— an escaping symlink (/../../..chain) plus a file written through it: asserts the unpack succeeds, the symlink is created, the file is contained at the extraction root, and nothing escapes above it.TestUntarInvalidSymlink,TestUntarInvalidHardlink,TestApplyLayerInvalid*,TestUntarHardlinkToSymlink) continue to pass on Windows.Validated end-to-end on a Windows containerd/BuildKit worker:
ADD symlink.tar /(escaping symlink) that previously failed withinvalid symlink ...now builds successfully with the file contained.Release notes