Skip to content

pkg/shim: Return JSON bootstrap results to legacy callers - #13764

Closed
vvoland wants to merge 1 commit into
containerd:mainfrom
vvoland:shim-compat
Closed

vvoland wants to merge 1 commit into
containerd:mainfrom
vvoland:shim-compat

Conversation

@vvoland

@vvoland vvoland commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

A containerd 2.2 daemon cannot start a containerd 2.3 containerd-shim-runc-v2.

The 2.3 shim accepts the deprecated CLI, environment, and stdin startup interface, but returns a protobuf-encoded BootstrapResult. Containerd 2.2 expects a JSON BootstrapParams response or a plain socket address. It therefore interprets the protobuf payload as the socket address and fails with an error similar to:

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

Detect legacy callers by comparing the identity decoded from stdin with the identity supplied through the compatibility CLI fields. This comparison is necessary because containerd 2.2 sends runtime options as a protobuf Any.
The Any fields can decode as non-empty BootstrapParams.instance_id and .namespace fields, so successful protobuf unmarshalling alone cannot distinguish the protocols.

For legacy callers, return the JSON BootstrapParams response they expect.
For new bootstrap callers, continue returning the protobuf BootstrapResult.

The legacy JSON response preserves the expected field names, always includes the version, and excludes unsupported capabilities and metadata.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores backward compatibility between containerd 2.2 daemons and containerd 2.3+ containerd-shim-runc-v2 by returning the legacy JSON bootstrap response for legacy callers while preserving the protobuf BootstrapResult response for new callers.

Changes:

  • Add bootstrap-protocol detection that distinguishes legacy callers from new bootstrap callers even when legacy runtime options can protobuf-unmarshal into BootstrapParams.
  • For legacy callers, emit a JSON BootstrapParams response instead of protobuf.
  • Add unit coverage for the new parseBootstrapParams protocol-detection logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/shim/shim.go Detect legacy bootstrap callers and switch stdout response encoding to JSON for compatibility.
pkg/shim/compat.go Introduce parseBootstrapParams to distinguish legacy runtime-options payloads from new bootstrap params.
pkg/shim/shim_test.go Add tests covering new-vs-legacy bootstrap payload detection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/shim/shim.go Resolved
Copilot AI review requested due to automatic review settings July 13, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread pkg/shim/shim.go Resolved
Copilot AI review requested due to automatic review settings July 13, 2026 17:09
@kubernetes-prow kubernetes-prow Bot added size/L and removed size/M labels Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread pkg/shim/shim.go Resolved
Copilot AI review requested due to automatic review settings July 13, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread pkg/shim/shim.go Resolved
Comment thread pkg/shim/shim.go Resolved
Comment thread pkg/shim/shim.go Outdated
// distinguishes it from the new protocol.
params, usesBootstrapProtocol := parseBootstrapParams(input, id, namespaceFlag)
if !usesBootstrapProtocol {
// TODO: Return error once the new API is stable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but looks like this TODO is outdated?

@thaJeztah thaJeztah added the cherry-pick/2.3.x Change to be cherry picked to release/2.3 label Jul 14, 2026
A containerd 2.2 daemon cannot start a containerd 2.3
`containerd-shim-runc-v2`.

The 2.3 shim accepts the deprecated CLI, environment, and stdin startup
interface, but returns a protobuf-encoded `BootstrapResult`.
Containerd 2.2 expects a JSON `BootstrapParams` response or a plain
socket address. It therefore interprets the protobuf payload as the
socket address and fails with an error similar to:

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

Detect legacy callers by comparing the identity decoded from stdin with
the identity supplied through the compatibility CLI fields. This
comparison is necessary because containerd 2.2 sends runtime options as
a protobuf `Any`.
The `Any` fields can decode as non-empty `BootstrapParams.instance_id`
and `.namespace` fields, so successful protobuf unmarshalling alone
cannot distinguish the protocols.

For legacy callers, return the JSON `BootstrapParams` response they
expect.
For new bootstrap callers, continue returning the protobuf
`BootstrapResult`.

The legacy JSON response preserves the expected field names, always
includes the version, and excludes unsupported capabilities and
metadata.

Signed-off-by: Paweł Gronowski <[email protected]>
Copilot AI review requested due to automatic review settings July 14, 2026 14:57
@vvoland
vvoland marked this pull request as ready for review July 14, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dmcgowan
dmcgowan requested a review from mxpv July 14, 2026 17:00

@mxpv mxpv left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containerd daemon already handles this logic in 2.3 and main:

func parseStartResponse(response []byte) (*bootapi.BootstrapResult, error) {
	var result bootapi.BootstrapResult

	if err := proto.Unmarshal(response, &result); err == nil {
		return &result, nil
	}

	// Fallback to legacy parsing for backward compatibility with 
    // legacy shims that return the address as a plain string or JSON.

	var params client.BootstrapParams //nolint:staticcheck // Used for backward compatibility with legacy shims
	if err := json.Unmarshal(response, &params); err != nil || params.Version < 2 {
		// Use TTRPC for legacy shims
		params.Address = string(response)
		params.Protocol = "ttrpc"
		params.Version = 2
	}

...

	return &bootapi.BootstrapResult{
		Version:  int32(params.Version),
		Address:  params.Address,
		Protocol: params.Protocol,
	}, nil
}

Instead of adding another path on shim side, I'd suggest to backport this function to 2.2 -

if err := json.Unmarshal(response, &params); err != nil || params.Version < 2 {

@github-project-automation github-project-automation Bot moved this from Needs Triage to Needs Update in Pull Request Review Jul 14, 2026
@mxpv

mxpv commented Jul 14, 2026

Copy link
Copy Markdown
Member

Or the other way around: main and 2.3 already have fallback, so it makes sense to open this PR straight against 2.2

@thaJeztah

Copy link
Copy Markdown
Member

I haven't dug in as deep as @vvoland but it's a bit odd though if the shim handles the old API on one side, but then produces the wrong result on ten other side?

@mxpv

mxpv commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

New shims produce protobuf (2.3 and main).
Old shims produce JSON (2.2 and below).
We added a compatibility layer on containerd side to recognize both, so it should support both newer and older shims. The case here is opposite - older daemon with newer shims.

@mxpv

mxpv commented Jul 14, 2026

Copy link
Copy Markdown
Member

Thinking of this more: @vvoland this use case is a bit unusual. How did you end up having older containerd 2.2 daemon and newer shims 2.3 ? Is this a downgrade?

@mxpv mxpv added cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch and removed cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Jul 14, 2026
@vvoland

vvoland commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

parseStartResponse solves the reverse case.

The particular case which we hit this is when we embedded the containerd 2.2 in Moby but the containerd binaries (runc-shim specifically) was on 2.3.

However, this also affects cases where you upgrade your containerd packages but don't restart the daemon. We've hit this in the past with the v1 -> v2 transition, like: #10984

The fix must be on the shim side so that the upgrade to latest containerd can happen from any containerd older than 2.3, not just latest 2.2 release.

@mxpv

mxpv commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

containerd 2.3+ is be able to parse both json and protobuf responses.
The reverse case exists because we did not backport the code to older versions.

The patch you're proposing requires rebuilding older shims, which defeats the purpose of clean upgrades.

While backporting and upgrading the daemon would be much easier (one fallback path, only daemon needs upgrade). You upgrade the daemon and it should be able to work with any shims.

@vvoland

vvoland commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm happy to also backport parseStartResponse to 2.2 but it's still not mutually exclusive with this PR.

For a user willing to migrate to 2.3 from 2.2 the most sensible and common path is going from whatever 2.2.X to the latest 2.3.X.

The 2.2 backport helps once the patched 2.2 daemon is running but does not cover a direct upgrade from an arbitrary 2.0–2.2 installation where the package replaces containerd-shim-runc-v2 while the existing daemon remains running. The user would first need to migrate to latest 2.2 with this patch before being able to upgrade to 2.3.X.


The patch you're proposing requires rebuilding older shims, which defeats the purpose of clean upgrades.

Not really - the point here is being able to update cleanly to a first containerd 2.3 version that includes this patch from any containerd 2.0-2.2 daemon. This will work because the runc shim is packaged alongside the containerd daemon.

This patch also matches the compatibility note from #12786:

pkg/shim is backward compatible. It uses the new bootstrap protocol by default and fallbacks to CLI/env/stdin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

containerd 2.2 cannot parse the bootstrap response from a 2.3 runc shim

4 participants