Skip to content

cri: reject CreateContainer when sandbox is not running#13654

Merged
mxpv merged 1 commit into
containerd:mainfrom
crawfordxx:fix-createcontainer-reject-stopped-sandbox
Jun 25, 2026
Merged

cri: reject CreateContainer when sandbox is not running#13654
mxpv merged 1 commit into
containerd:mainfrom
crawfordxx:fix-createcontainer-reject-stopped-sandbox

Conversation

@crawfordxx

Copy link
Copy Markdown
Contributor

What does this PR do?

CreateContainer currently proceeds without checking whether the sandbox is in a running (StateReady) state. If the sandbox has already stopped or is in an unknown state, the call silently creates a container shell that is unusable.

StartContainer already has the correct guard (added in the existing code):

if sandbox.Status.Get().State != sandboxstore.StateReady {
    return nil, fmt.Errorf("sandbox container %q is not running", sandboxID)
}

This PR applies the identical check in CreateContainer, right after the sandbox state is resolved, so callers receive an actionable error instead of a dangling container.

Why is it needed?

The CRI specification requires CreateContainer to fail when the target sandbox is not running. The cri-tools test at kubernetes-sigs/cri-tools#2126 exercises this exact case and currently fails against containerd.

Fixes #13599

Testing

Before this fix, CreateContainer would proceed even if the sandbox
had already stopped or was in an unknown state. This could result in
containers being created in an unusable sandbox, leading to confusing
errors downstream.

StartContainer already guards with the same check:

  if sandbox.Status.Get().State != sandboxstore.StateReady {
      return nil, fmt.Errorf("sandbox container %q is not running", ...)
  }

Apply the identical guard in CreateContainer, immediately after the
sandbox state is known, so that callers receive a clear error instead
of a partial container object.

Fixes #13599

Signed-off-by: crawfordxx <[email protected]>
Copilot AI review requested due to automatic review settings June 23, 2026 04:08
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jun 23, 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

This PR updates the CRI CreateContainer path to enforce the same sandbox-running guard already used by StartContainer, ensuring CreateContainer fails when the target pod sandbox is not in StateReady (running), per CRI expectations.

Changes:

  • Add a StateReady guard in CreateContainer to reject requests targeting non-running sandboxes with a clear error.
  • Align the sandbox store import naming (sandboxstore) and update the internal request struct field type accordingly.

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

Comment on lines +79 to +81
if sandbox.Status.Get().State != sandboxstore.StateReady {
return nil, fmt.Errorf("sandbox container %q is not running", sandboxID)
}
@AkihiroSuda

Copy link
Copy Markdown
Member

/cherry-pick release/2.3
/cherry-pick release/2.2

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: once the present PR merges, I will cherry-pick it on top of release/2.2, release/2.3 in new PRs and assign them to you.

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jun 25, 2026
@mxpv
mxpv added this pull request to the merge queue Jun 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 25, 2026
@mxpv
mxpv added this pull request to the merge queue Jun 25, 2026
Merged via the queue into containerd:main with commit 028999d Jun 25, 2026
85 of 88 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 25, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #13668

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #13669

Details

In response to this:

/cherry-pick release/2.3
/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp samuelkarp added cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch cherry-picked/2.2.x PR commits are cherry-picked into release/2.2 branch and removed cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch labels Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/2.2.x PR commits are cherry-picked into release/2.2 branch cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch size/XS

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

CreateContainer CRI API should be rejected on stopped sandbox

6 participants