Fix empty build context for symlinked context paths - #2124
Open
rupinajay wants to merge 1 commit into
Open
Conversation
BuildFSSync initializes the context root by resolving symlinks to enforce containment boundaries. However, Archiver.compress enumerates physical paths using the unresolved prefix, causing relativeChildPath() to reject valid files. Canonicalize the URLs returned by the archive walk before checking them against the canonicalized context root, while preserving the existing containment security boundary. Fixes apple#2037
3 tasks
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.
Description
Fixes #2037.
When
container buildis run on macOS from a context path located under asymlinked directory such as
/tmp,BuildFSSynccanonicalizes the contextroot to enforce containment.
However,
Archiver.compressenumerates files using the unresolved physicalpath prefix. This caused the existing containment check to reject valid
context files, resulting in an empty build context being transferred to
BuildKit and causing
COPYoperations to fail.This change canonicalizes URLs returned by the archive walk before checking
them against the canonicalized context root, while preserving the existing
containment and security boundary.
Type of Change
Motivation and Context
The context root and the paths returned by the archive walk could represent
the same filesystem location using different path prefixes on macOS.
For example:
/tmp/context->/private/tmp/contextThe canonicalized context root was therefore compared against an
unresolved archive path, causing
relativeChildPath()to reject validfiles.
Canonicalizing the enumerated URL before the existing containment check
makes both paths comparable without weakening the containment boundary.
Testing
Production build:
swift build --target ContainerBuildcompleted successfully.Formatting & linting:
make fmtandgit diff --checkcompleted successfully.Unit tests:
make testpassed locally with Xcode 26.6: 757 tests in 81 suites passed.Regression tests:
Added
testWalkTarIncludesFilesWhenContextDirUsesSymlinkedPrefixinBuildFSSyncTests.swift; it passed successfully.Integration tests:
Executed
make APP_ROOT=test-data container integration.The new end-to-end
testBuildContextSingleFileCOPYregression test passed successfully, including building the image, running a container from the image, and verifying/run.shexists in the container.The integration suite completed with 273/276 tests passing. The 3 unrelated failures were caused by temporary HTTP mirror timeouts while Alpine attempted to fetch packages from
dl-cdn.alpinelinux.org; the #2037 regression test passed.