@@ -70,7 +70,7 @@ func TestVolumeCopyUp(t *testing.T) {
7070 assert .Equal (t , "test_content\n " , string (stdout ))
7171
7272 t .Logf ("Check host path of the volume" )
73- hostCmd := fmt .Sprintf ("ls %s/containers/%s/volumes/*/test_file | xargs cat" , * criRoot , cn )
73+ hostCmd := fmt .Sprintf ("find %s/containers/%s/volumes/*/test_file | xargs cat" , * criRoot , cn )
7474 output , err := exec .Command ("sh" , "-c" , hostCmd ).CombinedOutput ()
7575 require .NoError (t , err )
7676 assert .Equal (t , "test_content\n " , string (output ))
@@ -88,3 +88,51 @@ func TestVolumeCopyUp(t *testing.T) {
8888 require .NoError (t , err )
8989 assert .Equal (t , "new_content\n " , string (output ))
9090}
91+
92+ func TestVolumeOwnership (t * testing.T ) {
93+ const (
94+ testImage = "gcr.io/k8s-cri-containerd/volume-ownership:1.0"
95+ execTimeout = time .Minute
96+ )
97+
98+ t .Logf ("Create a sandbox" )
99+ sbConfig := PodSandboxConfig ("sandbox" , "volume-ownership" )
100+ sb , err := runtimeService .RunPodSandbox (sbConfig )
101+ require .NoError (t , err )
102+ defer func () {
103+ assert .NoError (t , runtimeService .StopPodSandbox (sb ))
104+ assert .NoError (t , runtimeService .RemovePodSandbox (sb ))
105+ }()
106+
107+ t .Logf ("Pull test image" )
108+ _ , err = imageService .PullImage (& runtime.ImageSpec {Image : testImage }, nil )
109+ require .NoError (t , err )
110+
111+ t .Logf ("Create a container with volume-ownership test image" )
112+ cnConfig := ContainerConfig (
113+ "container" ,
114+ testImage ,
115+ WithCommand ("tail" , "-f" , "/dev/null" ),
116+ )
117+ cn , err := runtimeService .CreateContainer (sb , cnConfig , sbConfig )
118+ require .NoError (t , err )
119+
120+ t .Logf ("Start the container" )
121+ require .NoError (t , runtimeService .StartContainer (cn ))
122+
123+ // gcr.io/k8s-cri-containerd/volume-ownership:1.0 contains a test_dir
124+ // volume, which is owned by nobody:nogroup.
125+ t .Logf ("Check ownership of test directory inside container" )
126+ stdout , stderr , err := runtimeService .ExecSync (cn , []string {
127+ "stat" , "-c" , "%U:%G" , "/test_dir" ,
128+ }, execTimeout )
129+ require .NoError (t , err )
130+ assert .Empty (t , stderr )
131+ assert .Equal (t , "nobody:nogroup\n " , string (stdout ))
132+
133+ t .Logf ("Check ownership of test directory on the host" )
134+ hostCmd := fmt .Sprintf ("find %s/containers/%s/volumes/* | xargs stat -c %%U:%%G" , * criRoot , cn )
135+ output , err := exec .Command ("sh" , "-c" , hostCmd ).CombinedOutput ()
136+ require .NoError (t , err )
137+ assert .Equal (t , "nobody:nogroup\n " , string (output ))
138+ }
0 commit comments