Skip to content

Commit 25e49d5

Browse files
committed
shim: infer SandboxPlatform from OCI spec when not explicitly set
When runtime options are non-empty (e.g., SandboxIsolation is set) but SandboxPlatform is empty, infer the platform from the OCI spec rather than failing validation. This matches the existing behavior when options are entirely empty. containerd's default config (config_windows.go) sets SandboxIsolation=1 for the runhcs-wcow-hypervisor runtime handler but omits SandboxPlatform, making options non-empty with an empty platform string. This causes platforms.Parse("") to fail with 'invalid runtime sandbox platform'. The OCI spec already contains sufficient information to determine the platform: spec.Linux != nil indicates LCOW, while spec.Windows != nil with spec.Linux == nil indicates WCOW. Fixes the interaction between containerd's default runtime config and hcsshim's strict validation added in PR #2473.
1 parent cd32b44 commit 25e49d5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cmd/containerd-shim-runhcs-v1/service_internal.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"os"
1010
"path/filepath"
11+
"runtime"
1112

1213
task "github.com/containerd/containerd/api/runtime/task/v2"
1314
containerd_v1_types "github.com/containerd/containerd/api/types/task"
@@ -130,8 +131,25 @@ func (s *service) createInternal(ctx context.Context, req *task.CreateTaskReques
130131
}
131132

132133
if !emptyShimOpts {
134+
sandboxPlatform := shimOpts.GetSandboxPlatform()
135+
if sandboxPlatform == "" {
136+
// Infer platform from the OCI spec when not explicitly configured.
137+
// containerd's default config sets SandboxIsolation without SandboxPlatform,
138+
// making options non-empty but leaving the platform unset. Rather than
139+
// failing, fall back to spec-based inference which is already used when
140+
// options are entirely empty.
141+
if oci.IsLCOW(&spec) {
142+
sandboxPlatform = "linux/" + runtime.GOARCH
143+
} else if oci.IsWCOW(&spec) {
144+
sandboxPlatform = "windows/" + runtime.GOARCH
145+
} else {
146+
return nil, fmt.Errorf("cannot infer runtime sandbox platform from OCI spec: no Linux or Windows config present")
147+
}
148+
shimOpts.SandboxPlatform = sandboxPlatform
149+
}
150+
133151
// validate runtime platform
134-
plat, err := platforms.Parse(shimOpts.GetSandboxPlatform())
152+
plat, err := platforms.Parse(sandboxPlatform)
135153
if err != nil {
136154
return nil, fmt.Errorf("invalid runtime sandbox platform: %w", err)
137155
}

0 commit comments

Comments
 (0)