Commit Graph
54 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
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
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
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
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
Maksym Pavlenko 3e0ebf0f6d Deprecate shim.Command
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-29 10:51:55 -07:00
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
Maksym Pavlenko 16b7ce2549 Address code review suggestions
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym PavlenkoandSamuel Karp 45b7de2837 Limit amount of bytes read from stdin
Co-authored-by: Samuel Karp <me@samuelkarp.com>
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 3c0e8a55b6 Update comments wording about when to deprecate and remove the old path
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 9bf65dcf02 Use enums instead of strings for capabilities and log level
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 9dc864fd0f Switch to proto instead of json
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 73edc80451 Format code after cherry pick
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Derek McGowan 243cab594e Deprecate old pkg/shim interfaces
Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 3fbdb132bf Fix module path
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko d957b1bf53 Use log level instead of debug flag
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 31d0bbbad7 Include containerd version when launching shim
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko f71c2e4211 Reformat and clean proto files
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko b7ef291edc Provide bootstrap params when launching shims
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 9e9a095feb Read spec annotations from file
Revert changes related to reading annotations in runc v2 shim,
because this requires a special path for runc shim. This complicates
migration to the new bootstrap API.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko fa02acee20 Generate shim CLI flags under Command
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko fc8062f379 Rename CommandConfig field to better reflect their purpose
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 3831fc8063 Fix reading from stdin
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 5ea993b48d Pass runc options as a separate extension
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko 7f39b2d933 Update shim to support new bootstrap api
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Akihiro Suda 8b1faadb06 Merge pull request #12960 from vvoland/shim-path-perm
pkg/shim: Fix NewSocket directory permissions
2026-03-18 00:35:47 +00:00
Sebastiaan van Stijn 828c2119e5 pkg: modernize: any
go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest
    modernize -any -fix ./...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-15 18:24:15 +01:00
Paweł Gronowski 8f44dc45ea pkg/shim: Remove Darwin-specific socket permissions
The executable bit is needed only for the parent directory, not the
socket itself.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2026-03-13 10:20:02 +01:00
Paweł Gronowski 910631704e pkg/shim: Fix NewSocket directory permissions
NewSocket was using the same permission mode (0600) for both the socket
file and its parent directory.

Directories require the execute bit to be traversable, so creating a
directory with 0600 prevents any files from being created inside it.

Use 0700 for directory creation while keeping 0600 for socket files.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2026-03-13 10:20:01 +01:00
Paweł Gronowski 31c6307262 pkg/shim: Add unit tests
Currently the tests fail on Linux:

```
--- FAIL: TestNewSocket (0.00s)
    --- FAIL: TestNewSocket/socket_in_nested_directory (0.00s)
        util_unix_test.go:42: NewSocket failed: mkdir failed for /tmp/shim-test-1791693890/a/b/test.sock: mkdir /tmp/shim-test-1791693890/a/b: permission denied
FAIL
FAIL	github.com/containerd/containerd/v2/pkg/shim	0.004s
FAIL
```

This is fixed by the next commit.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2026-03-13 10:20:01 +01:00
Sebastiaan van Stijn e5ae0a8828 cmd/shim: containerd-shim-runc-v2: add long-form '--version' flag
All other binaries have both a `-v` and `--version` flag. Add a long-form
'--version' flag for this binary, useful to perform a quick check if the
binary is "functional".

Before this:

    containerd-shim-runc-v2 --help
    # ...
      -socket string
            socket path to serve
      -v	show the shim version and exit

After this:

    containerd-shim-runc-v2 --help
    # ...
      -socket string
            socket path to serve
      -v
      -version
            show the shim version and exit

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-07 13:10:13 +01:00
yashsingh74 403f86ecc2 fix: QF1012: Use of fmt.Fprintln(...)
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2025-06-18 14:16:41 +05:30
Brian Goff b85909cd4c shim: Move pprof server to plugin
Makes the pprof server a plugin and also gates by the `shim_tracing`
build tag (like otel is).
With this change, `net/http` is no longer a dependency in the shim.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-10-03 00:12:50 +00:00
Brian Goff b2681dfbdb shim: Move ttrpc interceptors to plugins
This makes it so we don't need to import otelttrpc unless the shim is
compiled with the `shim_tracing` build tag.
This way otel is no longer compiled into the binary at all unless
`shim_tracing` is set.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-10-03 00:12:47 +00:00
Brian Goff 17d4a1357e Propagate trace contexts to shims
This adds trace context propagation over the grpc/ttrpc calls to a shim.

It also adds the otlp plugin to the runc shim so that it will send
traces to the configured tracer (which is inherited from containerd's
config).
It doesn't look like this is adding any real overhead to the runc shim's
memory usage, however it does add 2MB to the binary size.
As such this is gated by a build tag `shim_tracing`

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-09-30 21:44:16 +00:00
Akhil Mohan 300fd770a0 use typeurl funcs for marshalling anypb.Any
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
2024-07-10 22:26:27 +05:30
Henry Wang 243b803a19 Add pprof to runc-shim
Signed-off-by: Henry Wang <henwang@amazon.com>
2024-06-20 23:12:31 +00:00
Sebastiaan van Stijn 75fd7a5a7f pkg/shim: remove logrus imports
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 12:35:36 +02:00
Derek McGowan ca59fb0b41 Cleanup shim manager configuration
Keep platforms configuration on task manager and add environment config
for shims.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-05-22 11:06:53 -07:00
Henry Wang d9dc2811ae fix: delete sockets on shim exit
Signed-off-by: Henry Wang <henwang@amazon.com>
2024-05-08 21:53:39 +00:00