Skip to content

shim: infer SandboxPlatform from OCI spec when not explicitly set#2620

Open
rzlink wants to merge 1 commit intomicrosoft:mainfrom
rzlink:fix-sandbox-platform-inference
Open

shim: infer SandboxPlatform from OCI spec when not explicitly set#2620
rzlink wants to merge 1 commit intomicrosoft:mainfrom
rzlink:fix-sandbox-platform-inference

Conversation

@rzlink
Copy link

@rzlink rzlink commented Mar 4, 2026

Summary

Fixes #2619

When containerd's default runhcs-wcow-hypervisor runtime config sets SandboxIsolation=1 without SandboxPlatform, the shim options are non-empty but SandboxPlatform is "". The platform validation added in PR #2473 unconditionally calls platforms.Parse("") which fails, breaking all Hyper-V isolated containers on stock containerd v2.2.1+.

Changes

In createInternal(), when runtime options are non-empty but SandboxPlatform is empty, infer the platform from the OCI spec before validation:

  • oci.IsLCOW(&spec)"linux/" + runtime.GOARCH
  • oci.IsWCOW(&spec)"windows/" + runtime.GOARCH

This mirrors the existing behavior when options are entirely empty — the shim already correctly handles platform inference in that code path.

Root Cause

containerd's config_windows.go defaults:

"runhcs-wcow-hypervisor": {
    Options: map[string]interface{}{
        "SandboxIsolation": 1,         // set
        // SandboxPlatform is NOT set  // missing!
    },
},

This makes emptyShimOpts = false (options are non-empty due to SandboxIsolation), but SandboxPlatform is "", causing the validation to fail.

Testing

  • Tested on Windows Server 2022 CAPZ clusters with containerd v2.2.1
  • Before fix: invalid runtime sandbox platform: "" error on every Hyper-V pod
  • After fix: Hyper-V pods create and run successfully
  • Kubernetes e2e [Feature:WindowsHyperVContainers] tests pass with the patched shim

@rzlink rzlink requested a review from a team as a code owner March 4, 2026 21:32
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 microsoft#2473.

Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
@rzlink rzlink force-pushed the fix-sandbox-platform-inference branch from 25e49d5 to c53a9dc Compare March 4, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shim: SandboxPlatform validation fails when containerd sets SandboxIsolation without SandboxPlatform

1 participant