Skip to content

Make device mapping work even if PrivilegedWithoutHostDevices is false #5053

@qiutongs

Description

@qiutongs

In today's containerd cri, in the case of privileged container, cri adds all host devices and ignore the device mapping when PrivilegedWithoutHostDevices is false(default value). Otherwise, cri only adds configured device mapping.

if !ociRuntime.PrivilegedWithoutHostDevices {
specOpts = append(specOpts, oci.WithHostDevices, oci.WithAllDevicesAllowed)
} else {
// add requested devices by the config as host devices are not automatically added
specOpts = append(specOpts, customopts.WithDevices(c.os, config), customopts.WithCapabilities(securityContext))
}

But the device mapping should be honored even in privileged mode.

Steps to reproduce the issue:
I didn't find an easy way to produce because ctr --device flag doesn't support device mapping. See #5046

  1. Start a k8s cluster
  2. Create a PersistentVolume with volumeMode as Block
  3. Create a PersistentVolumeClaim with volumeMode as Block. (You should see the PersistentVolumeClaim is bound with PersistentVolume)
  4. Create a Pod with volume corresponding to the PersistentVolumeClaim and specify a devicePath
apiVersion: v1
kind: Pod 
spec:
  containers:
    securityContext:
      privileged: true
    volumeDevices:
      devicePath: /my-disk
      name: example-local-claim
  volumes:
    name: example-local-claim
    persistentVolumeClaim:
      claimName: example-local-claim
  1. exec into the pod

Describe the results you received:

  • /dev/ has all the host devices
  • /my-disk doesn't exist

Describe the results you expected:

  • /dev/ has all the host devices
  • /my-disk exist

Output of containerd --version:

containerd github.com/containerd/containerd v1.5.0-beta.1-2-gddcc431c1.m ddcc431c11b80aacf495dbcf920fe46f7d748345.m

Any other relevant information:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions