Repository navigation
pkg/shim: Report bootstrap API mismatch on startup - #13910
Conversation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pkg/shim/compat.go:35
- The error text says the shim "was built against the new API", which can be confusing/misleading for users (it’s really a caller/protocol mismatch). Consider rephrasing to focus on the deprecated shim start protocol and the actionable remediation (restart the containerd daemon after upgrade).
var errDeprecatedBootstrapAPI = errors.New("shim was started through the deprecated API but was built against the new API; if you upgraded containerd, you may need to restart the daemon")
ec12654 to
9868b6d
Compare
9868b6d to
3d8d08b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
pkg/shim/compat.go:44
- parseBootstrapParams discards the proto.Unmarshal error and always returns errDeprecatedBootstrapAPI, which can make malformed/partial bootstrap input look like a legacy-caller mismatch. Including the unmarshal failure as context would make startup failures easier to diagnose while still allowing errors.Is(err, errDeprecatedBootstrapAPI) checks.
return nil, errDeprecatedBootstrapAPI
}
return params, nil
pkg/shim/compat.go:41
- readBootstrapParamsFromDeprecatedFields is now unused (no references in pkg/shim), but remains in this file along with legacy-only imports. If this PR is explicitly removing input-side support for the deprecated startup API, consider deleting the dead helper and trimming compat.go so it only contains the new-protocol validation logic.
This issue also appears on line 42 of the same file.
params := &bootapi.BootstrapParams{}
if len(input) == 0 || proto.Unmarshal(input, params) != nil {
return nil, errDeprecatedBootstrapAPI
}
if params.InstanceID != cliID || params.Namespace != cliNamespace {
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pkg/shim/compat.go:35
- parseBootstrapParams currently collapses all parsing/identity failures into errDeprecatedBootstrapAPI by discarding the proto.Unmarshal error. This can make debugging harder (e.g., corrupted/truncated stdin vs. truly deprecated startup) and provides no detail when stdin decodes but the identity doesn't match the CLI values. Consider wrapping errDeprecatedBootstrapAPI with additional context while preserving errors.Is semantics via %w.
var errDeprecatedBootstrapAPI = errors.New("shim was started through the deprecated API but was built against the new API; if you upgraded containerd, you may need to restart the daemon")
// parseBootstrapParams parses input from a caller using the bootstrap API.
// Legacy runtime options can unmarshal as BootstrapParams, so verify the
// identity against the command-line values.
3d8d08b to
510511f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pkg/shim/shim.go:279
- Using io.ReadAll(io.LimitReader(..., 10<<20)) caps memory, but it can also silently truncate inputs larger than the limit (ReadAll returns nil error). That would later surface as a misleading parse/deprecated-API error. Consider reading limit+1 and returning a clear "stdin too large" error when the payload exceeds the cap.
// Read stdin into memory so the bootstrap payload can be validated.
// Protect against unbounded memory consumption with a limit (e.g., 10MB).
input, err := io.ReadAll(io.LimitReader(os.Stdin, 10<<20))
if err != nil {
return fmt.Errorf("failed to read stdin: %w", err)
}
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 <[email protected]>
510511f to
85385a4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pkg/shim/compat.go:47
- When the bootstrap payload unmarshals successfully but the identity doesn’t match the CLI values, the returned error doesn’t include any of the mismatched values. Including the stdin vs CLI instance_id/namespace makes this failure mode actionable (and matches the test’s intent of having “details” for this case), while still wrapping errDeprecatedBootstrapAPI for errors.Is checks.
if params.InstanceID != cliID || params.Namespace != cliNamespace {
return nil, fmt.Errorf("bootstrap parameters do not match command-line arguments: %w", errDeprecatedBootstrapAPI)
}
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:
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.