Repository navigation
core/unpack: don't honor id-mapping labels from image annotations - #13855
Conversation
There was a problem hiding this comment.
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
layerSnapshotLabelsto filter inherited snapshot labels while explicitly droppingcontainerd.io/snapshot/uidmappingand.../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.
Signed-off-by: Aysha Afrah Ziya <[email protected]>
686c5a2 to
46c1902
Compare
|
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. |
|
any update? |
Signed-off-by: Aysha Afrah Ziya <[email protected]>
|
@samuelkarp: #13855 failed to apply on top of branch "release/2.2": DetailsIn response to this:
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: #13855 failed to apply on top of branch "release/2.0": DetailsIn response to this:
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: #13855 failed to apply on top of branch "release/1.7": DetailsIn response to this:
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: new pull request created: #14200 DetailsIn response to this:
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: #13855 failed to apply on top of branch "release/2.3": DetailsIn response to this:
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. |
…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]>
…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]>
…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]>
…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]>
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]>
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]>
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.