Skip to content

core/unpack: don't honor id-mapping labels from image annotations - #13855

Merged
samuelkarp merged 2 commits into
containerd:mainfrom
aysha-afrah26:unpack-strip-idmap-labels
Sep 21, 2026
Merged

samuelkarp merged 2 commits into
containerd:mainfrom
aysha-afrah26:unpack-strip-idmap-labels

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

The unpacker turns each image layer descriptor's annotations into snapshot labels and hands them to the snapshotter's Prepare, and FilterInheritedLabels keeps every containerd.io/snapshot/ key, so it also keeps containerd.io/snapshot/uidmapping and .../gidmapping. The overlay and erofs snapshotters act on those in Prepare by chowning the extracted layer's fs directory to the mapped host uid/gid, and that branch runs whenever the label is present, independent of the snapshotter's remapIDs setting. Layer annotations come straight from the image manifest, so a crafted image can put the mapping labels on a layer and make containerd chown the committed layer directory to an arbitrary host uid/gid during an ordinary pull, with no user-namespace setup involved. Because the committed directory is a shared, reused rootfs lowerdir, that ownership sticks and follows every container built on the layer. I ran into it while tracing where these labels are produced: the id maps are meant to reach the snapshotter from the runtime via WithRemapperLabels at container-prepare time, not from image content. The fix drops only the two id-mapping labels in the unpacker, so the annotation inheritance that remote snapshotters depend on stays intact while image content can no longer reach that chown.

Copilot AI lite review requested due to automatic review settings July 26, 2026 11:15
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jul 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the image unpack path by preventing untrusted image-layer annotations from injecting snapshotter id-mapping labels (UID/GID mapping) into extraction Prepare calls. This ensures ownership-shifting behavior remains controlled by the runtime (via client.WithRemapperLabels) rather than by crafted image content.

Changes:

  • Introduces layerSnapshotLabels to filter inherited snapshot labels while explicitly dropping containerd.io/snapshot/uidmapping and .../gidmapping.
  • Updates the unpacker to use the new helper when building extraction snapshot labels.
  • Adds a unit test to verify id-mapping labels are removed while other inherited snapshot labels still pass through.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/unpack/unpacker.go Centralizes label filtering for layer extraction and drops id-mapping labels from untrusted descriptor annotations.
core/unpack/unpacker_test.go Adds coverage asserting id-mapping labels are stripped while other inherited snapshot labels remain inherited.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AkihiroSuda AkihiroSuda added cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Aug 4, 2026
Copilot AI review requested due to automatic review settings August 4, 2026 18:12
@aysha-afrah26
aysha-afrah26 force-pushed the unpack-strip-idmap-labels branch from 686c5a2 to 46c1902 Compare August 4, 2026 18:12
@aysha-afrah26

Copy link
Copy Markdown
Contributor Author

Rebased onto main. The only conflict was in the test file imports, since core/mount and core/snapshots moved into the grouped import block upstream, so my separate import hunk was redundant. The change itself is unchanged and go build, go vet and go test ./core/unpack/... are clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@aysha-afrah26

Copy link
Copy Markdown
Contributor Author

any update?

@AkihiroSuda
AkihiroSuda requested a review from samuelkarp August 26, 2026 20:30
Comment thread core/unpack/unpacker.go Resolved
Comment thread core/unpack/unpacker.go Resolved
Comment thread core/unpack/unpacker_test.go Resolved
Comment thread core/unpack/unpacker_test.go Resolved
Copilot AI review requested due to automatic review settings August 27, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Sep 21, 2026
@samuelkarp
samuelkarp added this pull request to the merge queue Sep 21, 2026
Merged via the queue into containerd:main with commit 5152cb5 Sep 21, 2026
97 of 98 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Sep 21, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13855 failed to apply on top of branch "release/2.2":

Applying: core/unpack: don't honor id-mapping labels from image annotations
Using index info to reconstruct a base tree...
M	core/unpack/unpacker.go
M	core/unpack/unpacker_test.go
Falling back to patching base and 3-way merge...
Auto-merging core/unpack/unpacker.go
CONFLICT (content): Merge conflict in core/unpack/unpacker.go
Auto-merging core/unpack/unpacker_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 core/unpack: don't honor id-mapping labels from image annotations

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.2
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13855 failed to apply on top of branch "release/2.0":

Applying: core/unpack: don't honor id-mapping labels from image annotations
Using index info to reconstruct a base tree...
M	core/unpack/unpacker.go
M	core/unpack/unpacker_test.go
Falling back to patching base and 3-way merge...
Auto-merging core/unpack/unpacker.go
CONFLICT (content): Merge conflict in core/unpack/unpacker.go
Auto-merging core/unpack/unpacker_test.go
CONFLICT (content): Merge conflict in core/unpack/unpacker_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 core/unpack: don't honor id-mapping labels from image annotations

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.2
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13855 failed to apply on top of branch "release/1.7":

Applying: core/unpack: don't honor id-mapping labels from image annotations
Using index info to reconstruct a base tree...
A	core/unpack/unpacker.go
A	core/unpack/unpacker_test.go
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): core/unpack/unpacker.go deleted in HEAD and modified in core/unpack: don't honor id-mapping labels from image annotations.  Version core/unpack: don't honor id-mapping labels from image annotations of core/unpack/unpacker.go left in tree.
CONFLICT (modify/delete): core/unpack/unpacker_test.go deleted in HEAD and modified in core/unpack: don't honor id-mapping labels from image annotations.  Version core/unpack: don't honor id-mapping labels from image annotations of core/unpack/unpacker_test.go left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 core/unpack: don't honor id-mapping labels from image annotations

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.2
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: new pull request created: #14200

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.2
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13855 failed to apply on top of branch "release/2.3":

Applying: core/unpack: don't honor id-mapping labels from image annotations
Using index info to reconstruct a base tree...
M	core/unpack/unpacker.go
M	core/unpack/unpacker_test.go
Falling back to patching base and 3-way merge...
Auto-merging core/unpack/unpacker.go
CONFLICT (content): Merge conflict in core/unpack/unpacker.go
Auto-merging core/unpack/unpacker_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 core/unpack: don't honor id-mapping labels from image annotations

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.2
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp samuelkarp added cherry-picked/2.4.x PR commits are cherry picked into release/2.4 branch and removed cherry-pick/2.4.x Change to be cherry picked to release/2.4 labels Sep 22, 2026
zanarellidev added a commit to zanarellidev/containerd that referenced this pull request Sep 22, 2026
…nnotations

CRI callers can provide arbitrary annotations in PodSandboxConfig. Currently,
sandbox_run.go passes these directly to snapshots.FilterInheritedLabels, which
retains all containerd.io/snapshot/ keys including uidmapping and gidmapping.
The overlay and erofs snapshotters act on these labels during snapshot
preparation and chown the snapshot directory to the mapped host uid/gid.

Mirror the defense-in-depth hardening introduced in PR containerd#13855 for image layer
unpack by stripping LabelSnapshotUIDMapping and LabelSnapshotGIDMapping from
the inherited sandbox snapshot labels.

Signed-off-by: Raphael Zanarelli <[email protected]>
zanarellidev added a commit to zanarellidev/containerd that referenced this pull request Sep 22, 2026
…nnotations

CRI callers can provide arbitrary annotations in PodSandboxConfig. Currently,
sandbox_run.go passes these directly to snapshots.FilterInheritedLabels, which
retains all containerd.io/snapshot/ keys including uidmapping and gidmapping.
The overlay and erofs snapshotters act on these labels during snapshot
preparation and chown the snapshot directory to the mapped host uid/gid.

Mirror the defense-in-depth hardening introduced in PR containerd#13855 for image layer
unpack by stripping LabelSnapshotUIDMapping and LabelSnapshotGIDMapping from
the inherited sandbox snapshot labels.

Signed-off-by: Raphael Zanarelli <[email protected]>
zanarellidev added a commit to zanarellidev/containerd that referenced this pull request Sep 25, 2026
…nnotations

CRI callers can provide arbitrary annotations in PodSandboxConfig. Currently,
sandbox_run.go passes these directly to snapshots.FilterInheritedLabels, which
retains all containerd.io/snapshot/ keys including uidmapping and gidmapping.
The overlay and erofs snapshotters act on these labels during snapshot
preparation and chown the snapshot directory to the mapped host uid/gid.

Mirror the defense-in-depth hardening introduced in PR containerd#13855 for image layer
unpack by stripping LabelSnapshotUIDMapping and LabelSnapshotGIDMapping from
the inherited sandbox snapshot labels.

Signed-off-by: Raphael Zanarelli <[email protected]>
Signed-off-by: zanarelli <[email protected]>
@samuelkarp samuelkarp added cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch and removed cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Sep 30, 2026
@samuelkarp samuelkarp added cherry-picked/2.0.x PR commits are cherry picked into the release/2.0 branch cherry-picked/2.2.x PR commits are cherry-picked into release/2.2 branch and removed cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch labels Sep 30, 2026
zanarellidev added a commit to zanarellidev/containerd that referenced this pull request Oct 1, 2026
…nnotations

CRI callers can provide arbitrary annotations in PodSandboxConfig. Currently,
sandbox_run.go passes these directly to snapshots.FilterInheritedLabels, which
retains all containerd.io/snapshot/ keys including uidmapping and gidmapping.
The overlay and erofs snapshotters act on these labels during snapshot
preparation and chown the snapshot directory to the mapped host uid/gid.

Mirror the defense-in-depth hardening introduced in PR containerd#13855 for image layer
unpack by stripping LabelSnapshotUIDMapping and LabelSnapshotGIDMapping from
the inherited sandbox snapshot labels.

Signed-off-by: Raphael Zanarelli <[email protected]>
Signed-off-by: zanarelli <[email protected]>
pandaWall added a commit to pandaWall/containerd that referenced this pull request Oct 10, 2026
layerSnapshotLabels() strips containerd.io/snapshot/uidmapping and
.../gidmapping from image manifest annotations because snapshotters
act on them during Prepare (containerd#13855). Complete the enumeration with
.../max-size, added in containerd#13520: the erofs snapshotter honors it
unclamped when sizing the writable layer of an active snapshot
(writableSize -> X-containerd.mkfs.size -> truncate + mkfs.ext4),
and an image manifest is not a trusted source for that host-side
resource decision.
The sanctioned setters of max-size are CRI clients, via
PodSandboxConfig annotations on the sandbox path (to be extended to
container annotations in containerd#14070); those are untouched.

Today the in-tree erofs differ locates the layer directory through
the mount list without materializing the writable image (MountsToLayer),
so no current code path turns an image-supplied max-size into a real allocation —
this is defense-in-depth completing containerd#13855's enumeration before any consumer of unpack-time layer mounts does.

Signed-off-by: pandaWall <[email protected]>
pandaWall added a commit to pandaWall/containerd that referenced this pull request Oct 10, 2026
layerSnapshotLabels() strips containerd.io/snapshot/uidmapping and
.../gidmapping from image manifest annotations because snapshotters
act on them during Prepare (containerd#13855). Complete the enumeration with
.../max-size, added in containerd#13520: the erofs snapshotter honors it
unclamped when sizing the writable layer of an active snapshot
(writableSize -> X-containerd.mkfs.size -> truncate + mkfs.ext4),
and an image manifest is not a trusted source for that host-side
resource decision.
The sanctioned setters of max-size are CRI clients, via
PodSandboxConfig annotations on the sandbox path (to be extended to
container annotations in containerd#14070); those are untouched.

Today the in-tree erofs differ locates the layer directory through
the mount list without materializing the writable image (MountsToLayer),
so no current code path turns an image-supplied max-size into a real allocation —
this is defense-in-depth completing containerd#13855's enumeration before any consumer of unpack-time layer mounts does.

Signed-off-by: pandaWall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/2.0.x PR commits are cherry picked into the release/2.0 branch cherry-picked/2.2.x PR commits are cherry-picked into release/2.2 branch cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch cherry-picked/2.4.x PR commits are cherry picked into release/2.4 branch size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants