@@ -32,6 +32,7 @@ import (
32
32
"github.com/containerd/containerd"
33
33
"github.com/containerd/containerd/api/events"
34
34
"github.com/containerd/containerd/cio"
35
+ "github.com/containerd/containerd/containers"
35
36
"github.com/containerd/containerd/namespaces"
36
37
"github.com/containerd/containerd/oci"
37
38
"github.com/containerd/containerd/pkg/ttrpcutil"
@@ -657,6 +658,24 @@ func TestLongUnixSocketPath_Isolated(t *testing.T) {
657
658
}
658
659
}
659
660
661
+ func allowDeviceAccess (_ context.Context , _ oci.Client , _ * containers.Container , s * oci.Spec ) error {
662
+ // By default, all devices accesses are forbidden.
663
+ s .Linux .Resources .Devices = append (
664
+ s .Linux .Resources .Devices ,
665
+ specs.LinuxDeviceCgroup {Allow : true , Access : "r" },
666
+ )
667
+
668
+ // Exposes the host kernel's /dev as /dev.
669
+ // By default, runc creates own /dev with a minimal set of pseudo devices such as /dev/null.
670
+ s .Mounts = append (s .Mounts , specs.Mount {
671
+ Type : "bind" ,
672
+ Options : []string {"bind" },
673
+ Destination : "/dev" ,
674
+ Source : "/dev" ,
675
+ })
676
+ return nil
677
+ }
678
+
660
679
func TestStubBlockDevices_Isolated (t * testing.T ) {
661
680
prepareIntegTest (t )
662
681
@@ -706,15 +725,6 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
706
725
oci .WithProcessArgs ("/bin/sh" , "/var/firecracker-containerd-test/scripts/lsblk.sh" ),
707
726
708
727
oci .WithMounts ([]specs.Mount {
709
- // Exposes the host kernel's /dev as /dev.
710
- // By default, runc creates own /dev with a minimal set of pseudo devices such as /dev/null.
711
- {
712
- Type : "bind" ,
713
- Options : []string {"bind" },
714
- Destination : "/dev" ,
715
- Source : "/dev" ,
716
- },
717
-
718
728
// Exposes test scripts from the host kernel
719
729
{
720
730
Type : "bind" ,
@@ -723,8 +733,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
723
733
Source : "/var/firecracker-containerd-test/scripts" ,
724
734
},
725
735
}),
726
- // Make the host kernel's /dev readable
727
- oci .WithParentCgroupDevices ,
736
+ allowDeviceAccess ,
728
737
),
729
738
)
730
739
require .NoError (t , err , "failed to create container %s" , containerName )
0 commit comments