Repository navigation
Patches - #13626
Patches#13626
Conversation
openUserFile now stats the opened file, refuses anything that is not a regular file, and wraps the returned fs.File so reads are capped at maxUserFileBytes (10 MiB). All callers of openUserFile read either etc/passwd or etc/group; both are regular files on real systems, well under the cap. The cap and the regular-file check together bound parser memory use when reading user-database files of unexpected shape or size. Adds tests for the cap and for the non-regular file rejection. The cap test covers three boundary points: a small pad (trailing entry parsed), a pad placing the entry's last byte exactly on the cap (still parsed), and a pad past the cap (read returns an "exceeds" error). Assisted-by: Antigravity Signed-off-by: Chris Henzie <[email protected]>
Google-Bug-Id: 508657842 Signed-off-by: Samuel Karp <[email protected]>
Filter out any annotations on the checkpointed container matching `cdi.k8s.io/` or exactly `cdi.k8s.io` during restore to prevent unauthorized device restoration. When an annotation is denied, a warning log is generated. Tested by: * Unit tests for exact matching, prefix boundaries, and metadata merging * Complete CRI integration and checkpoint restore suite Assisted-by: Antigravity Signed-off-by: Samuel Karp <[email protected]>
Image config labels are copied onto the container by both the CRI plugin (BuildLabels) and the client's WithImageConfigLabels option used by `ctr run`. Labels in the containerd.io/* namespace are interpreted by containerd itself and labels in the io.cri-containerd* namespace are interpreted by the CRI plugin. An image config is not a trusted source for labels in either namespace. Skip labels in both reserved namespaces when copying labels from an image config to a container, and warn about each label skipped: an image that tries to set them may be attempting to alter containerd behavior. Oversized image labels are already skipped this way by the CRI plugin. Labels set explicitly by clients, for example via `ctr run --label` or in the CRI request, are unaffected. Verified with the CRI plugin and with `ctr run` against an image whose config carries labels like these: the labels are no longer present on the created container and a warning is logged for each. Assisted-by: Claude Code Signed-off-by: Ben Cressey <[email protected]> Signed-off-by: Samuel Karp <[email protected]>
The CRI checkpoint restore path unpacked checkpoint archive/OCI image content directly into the container's persistent state directory and read files such as container.log back from it with a symlink-following copy. Checkpoint content is externally provided, so make restore more defensive about what it unpacks and how it reads those files back. Behavior changes: - Only unpack regular files and directories from the checkpoint archive. - Unpack checkpoint content into a dedicated <state>/ctrd-restore subdirectory created fresh rather than into the state dir itself, so checkpoint content cannot collide with containerd's own files (e.g. the "status" blob). Restore and cleanup operate on that subdir; cleanup is now a single RemoveAll of it. Signed-off-by: Brian Goff <[email protected]>
|
Adding label DetailsInstructions 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. |
There was a problem hiding this comment.
Pull request overview
This PR applies a set of security hardening patches across containerd’s OCI spec helpers, label handling, and CRI checkpoint/restore flows, aligned with the CVE advisories referenced in the PR description.
Changes:
- Harden user/group database file reads in
pkg/ociby rejecting non-regular files and enforcing a maximum read size, with new tests. - Introduce a reserved label namespace check in
pkg/labels, and use it to prevent copying reserved image-config labels into containers (CRI and client paths), with tests. - Harden CRI checkpoint import/restore by confining extracted content to a dedicated subdirectory, filtering unsafe archive entries, and avoiding symlink-following reads for restored/copied files, with new tests and script updates.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/oci/spec_opts.go | Wraps /etc/passwd//etc/group opens to reject non-regular sources and cap reads. |
| pkg/oci/spec_opts_user_bounds_test.go | Adds tests for read caps and non-regular-file rejection. |
| pkg/labels/validate.go | Adds IsReserved helper for reserved label namespaces. |
| pkg/labels/validate_test.go | Adds unit coverage for IsReserved. |
| pkg/labels/labels.go | Defines reserved label namespace prefixes. |
| internal/cri/util/util.go | Skips reserved image-config labels when building container labels. |
| internal/cri/util/util_test.go | Updates label-building tests for reserved label filtering. |
| internal/cri/server/container_start.go | Restores checkpoints from confined restore dir and simplifies cleanup to remove the confined dir. |
| internal/cri/server/container_checkpoint_linux.go | Hardens checkpoint import/restore: tar entry filtering, confined restore dir, no-symlink copy, directory safety validation, annotation filtering. |
| internal/cri/server/container_checkpoint_linux_test.go | Adds tests for copyNoFollow, tar entry filtering, dir safety validation, and annotation filtering. |
| internal/cri/labels/labels.go | Reuses the shared CRI reserved prefix constant from pkg/labels. |
| contrib/checkpoint/checkpoint-restore-cri-test.sh | Updates the CRI checkpoint/restore test script to exercise CDI annotation filtering and improve cleanup robustness. |
| client/container_opts.go | Filters reserved image-config labels during WithImageConfigLabels, with warnings. |
| client/container_opts_test.go | Adds unit test ensuring reserved image-config labels are not copied. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
These have already been reviewed and tested in the private fork.
Security Updates