@@ -20,7 +20,6 @@ import (
2020 "context"
2121 "crypto/tls"
2222 "encoding/base64"
23- "errors"
2423 "fmt"
2524 "io"
2625 "net"
@@ -33,6 +32,8 @@ import (
3332 "sync/atomic"
3433 "time"
3534
35+ "github.com/containerd/log"
36+ distribution "github.com/distribution/reference"
3637 imagedigest "github.com/opencontainers/go-digest"
3738 imagespec "github.com/opencontainers/image-spec/specs-go/v1"
3839 runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -47,8 +48,6 @@ import (
4748 "github.com/containerd/containerd/v2/remotes/docker"
4849 "github.com/containerd/containerd/v2/remotes/docker/config"
4950 "github.com/containerd/containerd/v2/tracing"
50- "github.com/containerd/log"
51- distribution "github.com/distribution/reference"
5251)
5352
5453// For image management:
@@ -755,7 +754,7 @@ func (c *CRIImageService) snapshotterFromPodSandboxConfig(ctx context.Context, i
755754 }
756755
757756 // TODO: Find other way to retrieve sandbox runtime, this must belong to the Runtime part of the CRI.
758- ociRuntime , err := c .getSandboxRuntime (s , runtimeHandler )
757+ ociRuntime , err := c .config . GetSandboxRuntime (s , runtimeHandler )
759758 if err != nil {
760759 return "" , fmt .Errorf ("experimental: failed to get sandbox runtime for %s: %w" , runtimeHandler , err )
761760 }
@@ -764,55 +763,3 @@ func (c *CRIImageService) snapshotterFromPodSandboxConfig(ctx context.Context, i
764763 log .G (ctx ).Infof ("experimental: PullImage %q for runtime %s, using snapshotter %s" , imageRef , runtimeHandler , snapshotter )
765764 return snapshotter , nil
766765}
767-
768- // TODO: copy-pasted from the runtime service implementation. This should not be in image service.
769- func (c * CRIImageService ) getSandboxRuntime (config * runtime.PodSandboxConfig , runtimeHandler string ) (criconfig.Runtime , error ) {
770- if untrustedWorkload (config ) {
771- // If the untrusted annotation is provided, runtimeHandler MUST be empty.
772- if runtimeHandler != "" && runtimeHandler != criconfig .RuntimeUntrusted {
773- return criconfig.Runtime {}, errors .New ("untrusted workload with explicit runtime handler is not allowed" )
774- }
775-
776- // If the untrusted workload is requesting access to the host/node, this request will fail.
777- //
778- // Note: If the workload is marked untrusted but requests privileged, this can be granted, as the
779- // runtime may support this. For example, in a virtual-machine isolated runtime, privileged
780- // is a supported option, granting the workload to access the entire guest VM instead of host.
781- // TODO(windows): Deprecate this so that we don't need to handle it for windows.
782- if hostAccessingSandbox (config ) {
783- return criconfig.Runtime {}, errors .New ("untrusted workload with host access is not allowed" )
784- }
785-
786- runtimeHandler = criconfig .RuntimeUntrusted
787- }
788-
789- if runtimeHandler == "" {
790- runtimeHandler = c .config .ContainerdConfig .DefaultRuntimeName
791- }
792-
793- handler , ok := c .config .ContainerdConfig .Runtimes [runtimeHandler ]
794- if ! ok {
795- return criconfig.Runtime {}, fmt .Errorf ("no runtime for %q is configured" , runtimeHandler )
796- }
797- return handler , nil
798- }
799-
800- // untrustedWorkload returns true if the sandbox contains untrusted workload.
801- func untrustedWorkload (config * runtime.PodSandboxConfig ) bool {
802- return config .GetAnnotations ()[annotations .UntrustedWorkload ] == "true"
803- }
804-
805- // hostAccessingSandbox returns true if the sandbox configuration
806- // requires additional host access for the sandbox.
807- func hostAccessingSandbox (config * runtime.PodSandboxConfig ) bool {
808- securityContext := config .GetLinux ().GetSecurityContext ()
809-
810- namespaceOptions := securityContext .GetNamespaceOptions ()
811- if namespaceOptions .GetNetwork () == runtime .NamespaceMode_NODE ||
812- namespaceOptions .GetPid () == runtime .NamespaceMode_NODE ||
813- namespaceOptions .GetIpc () == runtime .NamespaceMode_NODE {
814- return true
815- }
816-
817- return false
818- }
0 commit comments