Commit Graph

257 Commits

Author SHA1 Message Date
Samuel Karp
6414e00413 cri: validate CRIU availability and version early
Perform an early validation check on both container checkpoint and
restore paths to fail-fast if the CRIU binary is missing or is older
than the minimum required version (3.16.0).

To support runtime-configured environments, the validation respects the
custom PATH from the shim manager environment if configured, skipping
any relative paths to avoid incorrect daemon-relative resolution. If not
configured, it falls back to a standard system PATH lookup. The check
result is cached using sync.Once to prevent redundant process spawning.

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
(cherry picked from commit 186397511b)
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-07-20 22:17:52 +00:00
William Myers
f3b4b35c94 sandbox: forward Create fields, fix event topics
The gRPC sandbox controller service only forwarded the `options` field
when calling the local controller. The `netns_path`, `rootfs`, and
`annotations` fields were silently dropped, causing clients using the
gRPC proxy path to receive incomplete sandbox configurations.

Event topics were missing the leading `/` prefix ("sandboxes/create"
instead of "/sandboxes/create"), causing the event exchange to reject
the publish and return an error to the caller.

Add unit tests for the controller service that exercise all RPC
methods.

Signed-off-by: William Myers <willmyrs@amazon.com>
(cherry picked from commit 557c54b116)
Signed-off-by: Phil Estes <estesp@gmail.com>
2026-04-23 16:10:32 +02:00
yashsingh74
1ea353741e fix: Used nolint to ignore the static checks
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
(cherry picked from commit 03a44a2d7c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-11 10:16:37 +01:00
yashsingh74
cebb3583e1 fix: ST1005: error strings should not end with punctuation or newlines
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
(cherry picked from commit b3eec6d8e9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-11 10:13:07 +01:00
yashsingh74
9b0b270cdf fix: QF1002: could use tagged switch on host (staticcheck)
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
(cherry picked from commit 56516173d0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-11 10:12:49 +01:00
Akihiro Suda
232786c906 Fix directory permissions
- Create /var/lib/containerd with 0o700 (was: 0o711).
- Create config.TempDir with 0o700 (was: 0o711).
- Create /run/containerd/io.containerd.grpc.v1.cri with 0o700 (was: 0o755).
- Create /run/containerd/io.containerd.sandbox.controller.v1.shim with 0o700 (was: 0o711).
- Leave /run/containerd and /run/containerd/io.containerd.runtime.v2.task created with 0o711,
  as required by userns-remapped containers.
  /run/containerd/io.containerd.runtime.v2.task/<NS>/<ID> is created with:
  - 0o700 for non-userns-remapped containers
  - 0o710 for userns-remapped containers with the remapped root group as the owner group.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit 51b0cf11dc5af7ed1919beba259e644138b28d96)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-10-29 14:30:40 +09:00
Gao Xiang
8d194c19fe erofs-snapshotter: make IMMUTABLE_FL optional
Enabling the IMMUTABLE_FL file attribute causes dirty data to be
flushed synchronously at least on EXT4, which can greatly impact
container launch performance.  In contrast, the overlayfs snapshotter
does not use syncfs by default.

Most users may not need IMMUTABLE_FL, let's make IMMUTABLE_FL optional
to align with the behavior of the overlayfs snapshotter and recover the
original performance.

1. tensorflow

Test commands:
$ nerdctl image pull --snapshotter=X --unpack="false" tensorflow/tensorflow:2.19.0
$ time nerdctl container --snapshotter=X run -d tensorflow/tensorflow:2.19.0 /bin/sh

Results:
 overlayfs                 | 0m18.748s
 erofs (no IMMUTABLE_FL)   | 0m10.090s
 erofs (with IMMUTABLE_FL) | 0m21.074s

2. ubuntu 22.04

Test commands:
$ nerdctl image pull --snapshotter=X --unpack="false" ubuntu:22.04
$ time nerdctl container --snapshotter=X run -d ubuntu:22.04 /bin/sh

Results:
 overlayfs                 | 0m1.147s
 erofs (no IMMUTABLE_FL)   | 0m0.795s
 erofs (with IMMUTABLE_FL) | 0m1.094s

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-07-12 13:03:00 +08:00
Gao Xiang
583133e710 erofs-differ: fix filesystem UUID for tar-converted layers
Derive filesystem UUIDs (`lsblk -o +UUID`) from the OCI layer digests
(although diffIDs are better in principle, but they're unavailable by
differs in advance) rather than generating a random one.  This allows
EROFS to uniquely identify each layer using the content-addressable
filesystem UUID.

It can also be used for reproducible builds. To achieve this, configure
`mkfs_options` with `-T0 --mkfs-time` (However, `--mkfs-time` requires
erofs-utils 1.8+; Otherwise, all inode timestamps will be reset w/o it):

``` toml
  [plugins."io.containerd.differ.v1.erofs"]
    mkfs_options = ["-T0 --mkfs-time"]
```

Fixes: c73c8e5d52 ("Introduce EROFS differ")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-07-03 08:41:10 +00:00
Kirtana Ashok
e6cecd0d7f Merge pull request #11936 from k8s-infra-cherrypick-robot/cherry-pick-11915-to-release/2.1
[release/2.1] Fix transfer differ selection
2025-06-06 11:32:09 -07:00
Derek McGowan
4bcea74dec Update differ selection in transfer service to prefer default
Currently the erofs differ will be chosen and cause pulls to fail with
not implemented errors.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-06-04 05:41:24 +00:00
Derek McGowan
0c3cd8a995 Add debug log when transfer returns not implemented
Currently the error details are not included in the output error and
there is no log. One of the reasons a the transferer was skipped could
be do to a specific component which is not implemented (such as trying
to use erofs differ) or unsupported image (pulling schema1). This
information is useful to find a bad configuration.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-06-04 05:41:24 +00:00
Gao Xiang
480126f507 erofs-snapshotter: fix to work with wrapped errors
Commit fb6dd2cf15 ("client:improve mount error message") changed
the return value into a wraped error message, which causes the
ENOTBLK check doesn't work.

Reported-by: Aadhar Agarwal <aadagarwal@microsoft.com>
Fixes: https://github.com/containerd/containerd/pull/11861
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-06-04 02:51:53 +00:00
Henry Wang
d82921ff59 Enable DuplicationSuppressor in transfer service
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-06-03 18:06:34 +00:00
Gao Xiang
2168cb92c9 erofs-differ: fix EROFS native image support
A dumb bug was just found after I worked out a usable native
converter [1], instead of relying on some prebuilt image..

[1] https://github.com/erofs/erofs-container-toolkit
Signed-off-by: Gao Xiang <xiang@kernel.org>
2025-05-14 05:30:46 +00:00
Phil Estes
c213879967 Merge pull request #11770 from azr/log-fetch-parameters
fix multipart layer fetch in client: pass config down
2025-05-05 12:51:17 +00:00
Adrien Delorme
e2d6a71605 cri: put limiter out of config
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-05-04 20:33:35 +02:00
Mike Brown
5f3f84f567 removes use of klog from containerd repo
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2025-05-02 13:34:46 +00:00
Adrien Delorme
ca356e46ee cri: add a ConcurrentDownloadLimiter
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-30 10:20:26 +02:00
Adrien Delorme
413702b7e4 fix comment
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-30 10:20:26 +02:00
Fu Wei
ef7bdf18a1 Merge pull request #10177 from azr/azr/parallel-layer-fetch
Multipart layer fetch
2025-04-24 20:35:00 +00:00
Phil Estes
25d1d30e6c Merge pull request #11744 from dmcgowan/unpack-rootfs-types
Add support for unpacking custom media types
2025-04-24 14:11:00 +00:00
Adrien Delorme
72c8c7708c only keep one setting: concurrent_layer_fetch_buffer
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-24 11:41:33 +02:00
Adrien Delorme
88116b1911 remove max_dl_operations setting
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-24 11:39:42 +02:00
Adrien Delorme
f9af08820b perf(pull): multipart layer fetch
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
Co-Authored-By: Corentin REGAL <143578+co42@users.noreply.github.com>
2025-04-24 11:39:42 +02:00
Derek McGowan
cdd7ec40db Support configuring custom media types for unpack
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-23 21:19:07 -07:00
Maksym Pavlenko
d983c186f5 Merge pull request #11733 from erofs/erofs-layers
erofs-differ: support EROFS native image layers
2025-04-23 23:33:23 +00:00
Derek McGowan
116b98704b Merge pull request #8515 from fangn2/cri-image-transfer
Update CRI to use transfer service for image pull by default
2025-04-23 22:58:12 +00:00
Maksym Pavlenko
1f70f07480 Merge pull request #11729 from dmcgowan/erofsutils-internal
Move erofsutils to internal
2025-04-23 19:26:25 +00:00
Tony Fang
b694be29a0 Update CRI image service to pull using transfer service
- adds a transfer service progress reporter to handle timeouts. Also other test fixes
- fallback to local image pull when configuration conflict

Signed-off-by: Tony Fang <nhfang@amazon.com>

Co-authored-by: Swagat Bora <sbora@amazon.com>
2025-04-23 18:18:27 +00:00
Gao Xiang
2f9734fa59 erofs-differ: support EROFS native image layers
If the layer media type is expected as an EROFS native layer (ending
with `.erofs`), copy the content as the layer blob.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-04-24 00:26:37 +08:00
Maksym Pavlenko
e511a384ee Add warning message when using async mode
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-22 09:27:45 -07:00
Maksym Pavlenko
89a8cd2fb8 Introduce no_sync option
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-22 09:27:45 -07:00
Maksym Pavlenko
57c1cfa5ff Update godoc for Bolt options
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-22 09:27:45 -07:00
Maksym Pavlenko
c94a92f422 Expose boltdb configuration for metadata plugin
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-22 09:27:42 -07:00
Derek McGowan
98eded24b8 Move erofsutils to internal
Avoid introducing utils package outside of internal. This package
should not be imported by other modules.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-22 09:03:49 -07:00
Sebastiaan van Stijn
568880ec3e erofsutils: MountsToLayer slight optimizations
follow-up to 09f34d18b7

- Use strings.Cut instead of trimming prefixes and strings.Split
  to reduce allocations
- Use a switch for mount-type for slightly better readability
  than if / else if / else.
- Fix GoDoc to start with the function name.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-19 17:04:23 +02:00
Fu Wei
4a51d8c8f7 Merge pull request #11603 from erofs/erofs-snapshotter
erofs-differ: implement fast differ with DiffDirChanges()
2025-04-19 13:28:46 +00:00
Gao Xiang
09f34d18b7 erofs-differ: implement fast differ with DiffDirChanges()
Unlike the walking differ, which implements a generic method to
accommodate all kinds of snapshotters, the EROFS differ is just
implemented for EROFS and EROFS snapshotter so it can utilize the
recent DiffDirChanges() [1] to avoid traversing the entire rootfs
directory in order to improve `nerdctl commit` performance.

Additionally, I think `baseDir` is unnecessary too (in principle,
only `upperdir` is useful for OCI format convention).  However,
addressing this requires more work, so left as is for now.

It's also useful to implement a customized Compare() method for
EROFS differ so that we can dump the native EROFS-formatted blob
to the content store later.

[1] https://github.com/containerd/continuity/pull/145
Signed-off-by: Gao Xiang <xiang@kernel.org>
2025-04-19 11:30:48 +08:00
Akihiro Suda
d9c889568e Remove the support for Schema 1 images
Schema 1 (`application/vnd.docker.distribution.manifest.v1+prettyjws`) has been
officially deprecated since containerd v1.7 (PR 6884), and disabled since v2.0 (PR 9765).

Users who have been seeing warnings like `conversion from schema 1 images is deprecated`
now have to rebuild the image with Schema 2 or OCI.

Schema 2 was introduced in Docker 1.10 (Feb 2016), so most users should have been already
using Schema 2 or OCI.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-04-11 09:03:26 +09:00
Tonis Tiigi
f87b2c1cd8 avoid import to testing pkg outside of tests
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-04-07 23:58:28 -07:00
Henry Wang
a083b669c9 Set default differ for the default unpack config of transfer service
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-04-01 22:39:49 +00:00
Samuel Karp
7bce8dfca5 Merge pull request #11581 from fuweid/fix-image-deletion-sync
*: CRIImageService should delete image synchronously
2025-03-24 21:44:44 +00:00
Wei Fu
e7b4165ab2 *: CRIImageService should delete image synchronously
Use memory service instead of metadata store.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-03-21 22:30:45 -04:00
Jin Dong
42effa3b91 Mark NetworkPluginBinDir as DEPRECATED
To make it as DEPRECATED, this PR does the following:

1. Changes config default to use `NetworkPluginBinDirs`;
2. Mark `NetworkPluginBinDir` as deprecated (in config version 3);
3. Add config migration from 2 to 3, which migrates `bin_dir`
  in version 2 to `bin_dirs` in version 3.

Signed-off-by: Jin Dong <djdongjin95@gmail.com>

[wip] add deprecation warning

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
2025-03-21 16:59:32 +00:00
Adrian Reber
9e6beafd53 Support container restore through CRI/Kubernetes
This implements container restore as described in:

https://kubernetes.io/blog/2022/12/05/forensic-container-checkpointing-alpha/#restore-checkpointed-container-standalone

For detailed step by step instruction also see contrib/checkpoint/checkpoint-restore-cri-test.sh

The code changes are based on changes I have done in Podman around 2018
and CRI-O around 2020.

The history behind restoring container via CRI/Kubernetes probably
requires some explanation. The initial proposal to bring
checkpoint/restore to Kubernetes was looking at pod checkpoint and
restoring and the corresponding CRI changes.

https://github.com/kubernetes-sigs/cri-tools/pull/662
https://github.com/kubernetes/kubernetes/pull/97194

After discussing this topic for about two years another approach was
implemented as described in KEP-2008:

https://github.com/kubernetes/enhancements/issues/2008

"Forensic Container Checkpointing" allowed us to separate checkpointing
from restoring. For the "Forensic Container Checkpointing" it is enough
to create a checkpoint of the container. Restoring is not necessary as
the analysis of the checkpoint archive can happen without restoring the
container.

While thinking about a way to restore a container it was by coincidence
that we started to look into restoring containers in Kubernetes via
Create and Start. The way it was done in CRI-O is to figure out during
Create if the container image is a checkpoint image and if that is true
we are using another code path. The same was implemented now with this
change in containerd.

With this change it is possible to restore the container from a
checkpoint tar archive that is created during checkpointing via CRI.

To restore a container via Kubernetes we convert the tar archive to an
OCI image as described in the kubernetes.io blog post from above. Using
this OCI image it is possible to restore a container in Kubernetes.

At this point I think it should be doable to restore containers in
CRI-O and containerd no matter if they have been created by containerd or
CRI-O. The biggest difference is the container metadata and that can
be adapted during restore.

Open items:

 * It is not clear to me why restoring a container in containerd goes
   through task/Create(). But as the restore code already exists this
   change extended the existing code path to restore a container in
   task/Create() to also restore a container through the CRI via
   Create and Start.
 * Automatic image pulling. containerd does not pull images
   automatically if created via the CRI. There is an option in
   crictl to pull images before starting, but that uses the CRI
   image pull interface. It is still a separate pull and create
   operation. Restoring containers from an OCI image is a bit
   different. The checkpoint OCI image does not include the base
   image, but just a reference to the image (NAME@DIGEST).
   Using crictl with pulling will enable the pulling of the
   checkpoint image, but not of the base image the checkpoint is
   based on. So during preparation of the checkpoint containerd
   will automatically pull the base image, but I was not able how
   to pull an image blockingly in containerd. So there is a for
   loop waiting for the container image to appear in the internal
   store. I think this probably can be implemented better.

Anyway, this is a first step towards container restored in Kubernetes
when using containerd.

Signed-off-by: Adrian Reber <areber@redhat.com>
2025-03-11 12:55:13 +01:00
Maksym Pavlenko
e1e88115dd Merge pull request #11450 from austinvazquez/dependabot/go_modules/go.etcd.io/bbolt-1.4.0
build(deps): bump go.etcd.io/bbolt from 1.3.11 to 1.4.0
2025-03-06 00:43:50 +00:00
Phil Estes
f35b7dae5f Merge pull request #11330 from ningmingxiao/blkdiscard
device mapper:fix sometimes blkdiscard doesn't have --version flags
2025-03-05 21:49:43 +00:00
Gao Xiang
3a5de731c5 erofs-snapshotter: clear IMMUTABLE_FL only for committed snapshots
Otherwise, the following error avoids snapshot GC:
level=warning msg="snapshot garbage collection failed" error="failed
to clear IMMUTABLE_FL: failed to open: open /var/lib/containerd/io.
containerd.snapshotter.v1.erofs/snapshots/2/layer.erofs: no such file
or directory

Fixes: b477cf8e97 ("erofs-snapshotter: protect layer blobs with FS_IMMUTABLE_FL")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-03-05 10:04:07 +08:00
Gao Xiang
971915797a erofs-snapshotter: force the use of loop devices for single-layer images
Currently, containerd cannot dynamically select between EROFS block
or file-based mounting approaches based on the specific runtime (or
the Linux kernel version of the runtime) due to its static mount
structure.

For example, the EROFS snapshotter fails on Linux 5.4 (Ubuntu 20.04)
with `bin/nerdctl run --net=host --snapshotter=erofs busybox:latest`:

FATA[0005] failed to mount {Type:erofs Source:/var/lib/containerd/
io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs Target:
Options:[ro]} on "/tmp/initialC1374142795": block device required

Temporarily fix this by appending `-oloop` for single-layer images.
The upcoming mount manager will make it better [1].

[1] https://github.com/containerd/containerd/issues/11303
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-03-04 17:07:01 +08:00
Gao Xiang
b477cf8e97 erofs-snapshotter: protect layer blobs with FS_IMMUTABLE_FL
As documented in ioctl_iflags(2):
```
 FS_IMMUTABLE_FL
  The file is immutable: no changes are permitted to the file contents
  or metadata (permissions, timestamps, ownership, link count, and so
  on).  (This restriction applies even to the superuser.)
```

For example, any user cannot delete/move layer blobs when
FS_IMMUTABLE_FL is set:
``` sh
 # cd /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/4
 # mv layer{,1}.erofs
 mv: cannot move 'layer.erofs' to 'layer1.erofs': Operation not permitted
 # rm layer.erofs
 rm: cannot remove 'layer.erofs': Operation not permitted
```

Note that it's a best-effort approach for data loss prevention.  IOWs,
just warn out if FS_IMMUTABLE_FL cannot be set anyway (e.g., due to lack
of support in the underlying filesystem.)

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-03-03 20:11:48 +08:00