Fix COPY --from=stage when running with user-namespaces #1448
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.
Issue was reported in moby/moby#34645 (comment), and relates to moby/moby#38599, which addressed this issue for the classic builder.
When copying files between stages, file ownership should be preserved;
However, when running with user namespaces enabled:
# grep dockremap /etc/sub*id /etc/subgid:dockremap:500000:65536 /etc/subuid:dockremap:500000:65536
A build would fail, because BuildKit is trying to map the container's UID/GID to the host:
When looking at the code, I found that
(fb *Backend) Copy()
takes aaction
argument (
pb.FileActionCopy
), one of its options is wether or not the ownershould be overridden:
buildkit/solver/pb/ops.pb.go
Lines 1457 to 1458 in 226a5db
That argument is passed on to
docopy()
(which is called from(fb *Backend) Copy()
), however insidedocopy()
, user-mapping is performed, irregardless ifOwner
was set or not:buildkit/solver/llbsolver/file/backend.go
Lines 182 to 189 in 226a5db
This patch makes that step optional, and only performs
mapUserToChowner
ifaction.Owner
is specified, hopefully addressing the issue.