Commit Graph
2036 Commits
Author SHA1 Message Date
Maksym Pavlenko 051118d229 Merge pull request #14036 from mxpv/shim-telemetry
Pass tracing context from shim to runc and hooks
2026-08-27 18:35:45 +00:00
Maksym Pavlenko 5c25750dd5 shim: propagate trace context to runc and OCI hooks
runc and the OCI hooks it spawns are separate processes, so the trace
context can not reach them over ttrpc. Inject it into their environment
instead, riding on the request context via go-runc's WithExtraEnv, which
does not race with concurrent requests the way setting it on the shim
process would.

The otelttrpc interceptor extracts that context, so chain it first
explicitly instead of leaving it to plugin initialization order. Also
flush the spans the tracing plugin buffered before the shim exits.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-08-25 11:21:41 -07:00
Maksym Pavlenko e26a0fed28 Merge pull request #13991 from mxpv/move-shim-command
Remove shim.Command form pkg
2026-08-25 16:28:51 +00:00
Sebastiaan van Stijn 442969ef0e pkg/tracing: handle error and typed-nil Stringer attributes
Log fields which contain an error currently fall through to JSON
marshaling, which may produce an unhelpful value such as "{}" instead
of the error message.

Handle error values explicitly and use fmt.Sprint when formatting error
and fmt.Stringer values. Besides preserving their textual
representation, fmt handles typed-nil implementations without
propagating a panic from their Error or String method.

Also simplify the final fmt.Sprintf("%v", v) fallback to fmt.Sprint(v).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-22 20:50:57 +02:00
Maksym Pavlenko 0cdf551004 Merge pull request #13910 from vvoland/shim-compat-warn
pkg/shim: Report bootstrap API mismatch on startup
2026-08-20 21:10:21 +00:00
Mike Brown 7f1c5db266 Merge pull request #13818 from fuweid/introduce-resolve-in-root-function
pkg/oci: resolve rootfs symlinks for user lookup
2026-08-20 17:24:37 +00:00
Maksym Pavlenko 55c39f2516 Move shim.Command to runtime
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-08-19 13:20:33 -07:00
Maksym Pavlenko 014e20a87f shim: apply PublisherOpts
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-08-19 10:24:36 -07:00
Wei Fu a8fc3a0172 pkg/oci: resolve rootfs symlinks for user lookup
Some rootfs may use symlinks for /etc/passwd and /etc/group. For example,
NixOS uses absolute symlinks to files in /nix/store. os.Root is not used
because it rejects absolute symlinks.

The previous code only handled a symlink on the final path. Add a helper to
resolve symlinks in every path component with fs.ReadLinkFS. Absolute symlinks
are resolved from the rootfs, and the final path is still opened with fs.FS.

When tracing a path through symbolic links, the maximum number of links that
can be followed is [40][1].

[1]: <https://man7.org/linux/man-pages/man7/path_resolution.7.html>

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-08-19 12:10:46 -04:00
Paweł Gronowski 85385a4c33 pkg/shim: Report bootstrap API mismatch on startup
A pre-2.3 containerd daemon can start a newly installed shim through the
deprecated CLI, environment, and stdin API.
The shim currently accepts that request but returns a protobuf bootstrap
result, which the old daemon cannot parse.
It treats the protobuf bytes as a socket address and fails later with a
cryptic error:

```
failed to create TTRPC connection: unsupported protocol: \b\x03\x12Yunix
```

This patch makes the shim reject the deprecated startup request before
starting and tell the user that the containerd daemon may need to be
restarted.
The 2.2 daemon includes the shim's stderr in its start error, so this
message reaches the user directly.

This explicitly removes input-side support for the deprecated startup
API, but it does not break a working standard containerd pairing.
Pre-2.3 daemons already cannot consume the response from the new shim.
After a package upgrade, a restarted daemon uses the new bootstrap API.

Custom callers that send the deprecated request format while supporting
the new protobuf response will now also be rejected.

Signed-off-by: Paweł Gronowski <git@grono.dev>
2026-08-17 15:00:41 +02:00
Harsh Rawat 3bb3d8b7c6 address copilot comments
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
2026-08-12 16:48:40 +05:30
Harsh Rawat 983dcf4987 [pkg/shim] Implement Windows-specific unimplemented methods
The shim package could not be used by Windows shims due to missing implementation. This commit adds the Windows implementation for the shim package.

Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
2026-08-12 16:27:07 +05:30
Krisztian Litkey bf0111a9cc nri,deprecation: emit warnings for old NRI plugins.
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
2026-08-07 10:39:30 -05:00
Samuel Karp 56bc534e7e Merge pull request #13871 from samuelkarp/remove_deprecated_checkpoint_restore
cri: remove restore in CreateContainer
2026-07-31 15:50:29 +00:00
Fu Wei 2600710ddb Merge pull request #13735 from AkihiroSuda/whiteout-test
integration: build the whiteout-test image locally
2026-07-31 15:15:31 +00:00
Samuel Karp 91be73ba62 cri: remove restore in CreateContainer
Remove support for restoring checkpoint data during CreateContainer,
which was previously deprecated in v2.3.

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-07-29 09:32:24 -07:00
Samuel Karp fda8a90116 Merge pull request #13838 from samuelkarp/deprecate-cri-checkpoint
cri: deprecate restore in CreateContainer
2026-07-28 17:36:14 +00:00
Samuel Karp a3f99ba690 cri: deprecate restore in CreateContainer
Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-07-27 22:11:29 -07:00
Nikolaus Schuetz 41f6f0e877 pkg/epoch: reject negative SOURCE_DATE_EPOCH values
ParseSourceDateEpoch used strconv.ParseInt, which accepts a leading sign, so a
negative SOURCE_DATE_EPOCH was silently accepted and produced a pre-1970
timestamp with a nil error. That contradicts the function's own doc ("returns
an error if ... not well-formatted") and the reproducible-builds spec, where
SOURCE_DATE_EPOCH is a non-negative number of seconds since the Unix epoch.
Reject negative values and add a regression test.

Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
2026-07-22 14:46:05 -07:00
Aysha Afrah Ziya 0205398ac2 pkg/archive: reject out-of-range device numbers in layer headers
Signed-off-by: Aysha Afrah Ziya <aysha26@digiscrypt.com>
2026-07-14 20:10:05 +05:30
Akihiro Suda f418688f2c integration: build the whiteout-test image locally
Build the image for TestIssue13030 locally using pkg/archive,
instead of pulling the prebuilt ghcr.io/containerd/whiteout-test image.

The image is built by appending layers generated with archive.WriteDiff
on top of the busybox base image, served with the new
testutil.ServeImage helper on a localhost HTTP registry, and pulled
through the regular client.Pull path with WithPullUnpack. This removes
the need to publish the multi-arch whiteout-test image, so the
Dockerfile and Makefile added in PR 13704 are removed along with the
image list entry.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2026-07-08 23:39:42 +09:00
Sebastiaan van Stijn 296f917d5d pkg/kernelversion: update links to upstream source
The package was moved to a separate module; update the links to
make it easier to discover the current version of upstream.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-02 17:11:44 +02:00
Sebastiaan van Stijn c45f911980 pkg/kernelversion: simplify code with sync.OnceValues
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-02 17:11:44 +02:00
Sebastiaan van Stijn 5e3e05aec7 pkg/kernelversion: fix minor linting issues
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-02 17:11:44 +02:00
Sebastiaan van Stijn 762b89ceeb pkg/kernelversion: use unix.ByteSliceToString for utsname fields
similar to [moby@8a5c131]

[moby@8a5c131]: https://github.com/moby/moby/commit/8a5c13155e3d94fcbc8e7642738df0fefceeb96b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-02 17:11:42 +02:00
Akihiro Suda a6f337bba8 Merge pull request #13560 from jgehrcke/klauspost-gzip-decomp
pkg/archive/compression: use klauspost/compress/gzip for decode
2026-06-30 13:51:32 +00:00
Maksym Pavlenko 10004d5967 Merge pull request #13675 from thaJeztah/rm_sequential
pkg/archive: remove redundant github.com/moby/sys/sequential dependency
2026-06-26 15:58:07 +00:00
Sebastiaan van Stijn 35f753cc44 pkg/archive: remove redundant github.com/moby/sys/sequential dependency
Go 1.26 adds support for passing Windows file flags via os.OpenFile,
eliminating the need to call windows.CreateFile directly.

github.com/moby/sys/sequential v0.7.0 uses this functionality when
compiled with go1.26, but provides fallbacks for older Go versions.

Given that containerd has go1.26 as a minimum requirement, we can
remove github.com/moby/sys/sequential as an intermediate, and implement
the code locally.

ref:

- https://github.com/moby/sys/commit/9d2fc630f5932bed2dc29585a5ef6b025f5d58bf
- https://go-review.googlesource.com/c/go/+/699415
- https://go-review.googlesource.com/c/go/+/724621

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-06-26 10:14:53 +02:00
Sebastiaan van Stijn 7a7aebfcbf pkg/oci: update TestOpenUserFileCapsReads to use newlined data
This test verifies the maximum file-size constraints that were added in
[containerd7b05ec4]. However, github.com/moby/sys@v0.4.1 adds similar
constraints, including a constraint on line-length (1M): [moby/sys@2c56c3d]
that may hit before the file-size limit is reached if the data does not
contain newlines.

This patch updates the test to use data that includes newlines to make
sure it's testing the file-size constraints, not line-limit constraints.

[containerd7b05ec4]: https://github.com/containerd/containerd/commit/7b05ec421d0a07b33964c74145b6bf5dff58f476
[moby/sys@2c56c3d]: https://github.com/moby/sys/commit/2c56c3d5d089bfa66d01b6c0bb69428e9d5d18c5

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-06-26 09:57:28 +02:00
Derek McGowan 53f4271fd9 Merge pull request #13661 from akerouanton/default-unix-spec
oci: use path.Join to fill CgroupsPath
2026-06-25 14:18:19 +00:00
Albin Kerouanton 51e3a8f4ab oci: use path.Join to fill CgroupsPath
`populateDefaultUnixSpec` uses `filepath.Join` to generate the default
`CgroupsPath`. On Windows, this produces invalid paths as path elems are
joined with backslash. Switch to `path.Join` instead.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2026-06-24 10:20:54 +02:00
Samuel Karp 5558f3aa0e Merge pull request #13626 from samuelkarp/june-18-combined-main
Patches
2026-06-18 16:02:14 -07:00
Chris Henzie 5a91c99584 Merge commit from fork 2026-06-15 21:25:17 -07:00
Dr. Jan-Philip Gehrcke d8f13bf4cc pkg/archive/compression: use klauspost/compress/gzip for decode
Replace the stdlib compress/gzip decoder with klauspost's inflate.
Also see
https://github.com/containerd/containerd/issues/13559

Signed-off-by: Dr. Jan-Philip Gehrcke <jgehrcke@nvidia.com>
2026-06-15 14:34:15 -05:00
Esteban Ginez be3fcf33e8 fix(shim/windows): retry on winio.ErrTimeout in awaitPipeReady
awaitPipeReady retried only when DialPipe returned os.IsNotExist or
context.DeadlineExceeded, but winio.DialPipe converts the per-attempt
deadline into winio.ErrTimeout before returning. A pipe in state 1
(ListenPipe called, Accept not yet called) causes DialPipe to block for
the full per-attempt timeout and return winio.ErrTimeout, which the old
check treated as a fatal error instead of retrying.

Also guard windows.ERROR_PIPE_BUSY explicitly to match the error checks
in containerd/nerdbox#218.

Adds a regression test that forces the state-1 to state-2 transition
race by delaying Accept past the 1-second per-attempt timeout.

Signed-off-by: Esteban Ginez <esteban.ginez@docker.com>
2026-06-10 14:49:50 -07:00
Ben Cressey 0ec1af4cae Do not propagate reserved labels from image configs
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 <ben@cressey.org>
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-06-10 13:18:24 -07:00
Sebastiaan van Stijn 633a5be1c9 pkg/oci: WithUser: remove redundant isErrRange utility
`strconv.NumError` implements `Unwrap` (see https://go.dev/cl/194563),
so there's no need to manually assert the type and unwrap.

Updates 9439355c2b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-05-26 10:14:17 +02:00
LEI WANG 9439355c2b oci: return explicit error for out-of-range USER values
Detect strconv.ErrRange and validate uid/gid bounds to avoid falling back to username/group lookups.

Signed-off-by: LEI WANG <ssst0n3@gmail.com>
2026-05-19 11:36:54 -07:00
Samuel Karp ae843af785 Merge pull request #13360 from mxpv/task
Fix sandbox task API endpoints for non-runc runtimes
2026-05-19 00:15:24 +00:00
Maksym Pavlenko b88ab5af4f Wire task address and version fields
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-05-18 13:37:19 -07:00
Chris Henzie 7b05ec421d Bound user-database file reads in openUserFile
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 <chrishenzie@gmail.com>
2026-05-16 01:04:01 +00:00
Kir Kolyshkin 899dee1f59 pkg: remove unused nolint annotations
Commit f9c80be1b removed varcheck linter, but some nolint:varcheck
annotations are still there, resulting in golangci-lint warning:

> WARN [runner/nolint_filter] Found unknown linters in //nolint directives: varcheck

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-05-12 11:02:51 -07:00
Maksym Pavlenko 3e0ebf0f6d Deprecate shim.Command
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-29 10:51:55 -07:00
Sanil2108 f62bce25df pkg/rootfs: remove unused InitRootFS and related helpers
InitRootFS was added in #1477 for potential future use but has no
callers either inside or outside this repository. Remove it along
with the associated Mounter interface, initializerFunc type,
createInitLayer helper, and the platform-specific init files that
only existed to support it.

Fixes #13238

Signed-off-by: Sanil2108 <sanilkhurana7@gmail.com>
2026-04-21 08:59:39 +05:30
Derek McGowan e07a1aa491 Add configuration for socket directory to the shim manager
Allow the socket directory to be directly configured by the shim manager
with reasonable defaults when not set. The default for root users will
still be the same directory under the default state directory. For
non-root users a temp directory will be used as default if the state
directory is not owned by the user.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-15 00:21:29 -07:00
Derek McGowan d806373feb Make shim socket directory use configured state
Send the socket directory from containerd to the shim. The shim still
decides where the socket goes but can use the environment variable
passed from containerd to ensure the socket is placed in the configured
directory with proper permission.

This is needed for some rootless cases which do not have permission to
the default state directory as currently set. The directory being
hardcoded by the shim means it is currently not possible to change the
location the shim will listen at.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-15 00:21:18 -07:00
Derek McGowan 74b465dcc6 Merge pull request #13208 from dmcgowan/update-bootstrap-log-levels
Update bootstrap API log level definition
2026-04-10 17:01:20 -07:00
Derek McGowan 2c102c6cbe Update bootstrap API log level definition
Avoid using logrus concepts in the API, use slog style log levels with
integer values and 0 meaning the default "info" level.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-10 15:23:34 -07:00
Esteban Ginez 01e5fa616f fix: address review feedback on awaitPipeReady
- Use time.NewTimer + Stop() instead of time.After to avoid timer leaks
- Treat context.DeadlineExceeded as retryable (pipe busy, not just missing)
- Wrap last dial error instead of os.ErrNotExist for better diagnostics
- Update makeConnection godoc to reflect current BootstrapResult type

Signed-off-by: Esteban Ginez <esteban.ginez@docker.com>
2026-04-09 15:15:32 -07:00
Esteban Ginez 1e98ebaf0e fix(windows): verify pipe readiness before returning shim address
The shim "start" helper returns the named pipe address before the
daemon process has created the pipe via winio.ListenPipe(). On busy
Windows systems, containerd may try to connect before the pipe exists.

Add awaitPipeReady() — the start helper now polls the pipe address
(up to 5s, 10ms intervals) before writing the bootstrap result to
stdout. This follows hcsshim's readiness pattern where the shim
verifies its endpoint is ready before signaling the parent.

As a safety net, also parameterize makeConnection() with a dialer so
binary.Start() uses AnonDialer (retry) for new shims while loadShim()
keeps AnonReconnectDialer (fail-fast) for reconnects per #3659.

On Unix, awaitPipeReady() is a no-op: domain sockets appear atomically.

Signed-off-by: Esteban Ginez <esteban.ginez@docker.com>
2026-04-09 15:07:06 -07:00