Skip to content

Commit d413443

Browse files
committed
Add validation test for image volumes with user namespaces
1 parent 9f164d1 commit d413443

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module sigs.k8s.io/cri-tools
22

3-
go 1.25.0
3+
go 1.25
44

55
require (
66
github.com/distribution/reference v0.6.0

pkg/validate/security_context_linux.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,68 @@ var _ = framework.KubeDescribe("Security Context", func() {
10241024

10251025
matchContainerOutputRe(podConfig, containerName, `\s+0\s+1000\s+100000\n`)
10261026
})
1027+
1028+
It("runtime should support image volumes with user namespaces", func() {
1029+
By("pull test image for image volume")
1030+
testImage := framework.TestContext.TestImageList.DefaultTestContainerImage
1031+
framework.PullPublicImage(ic, testImage, nil)
1032+
1033+
By("create pod sandbox with user namespace")
1034+
namespaceOption := &runtimeapi.NamespaceOption{
1035+
UsernsOptions: &runtimeapi.UserNamespace{
1036+
Mode: runtimeapi.NamespaceMode_POD,
1037+
Uids: defaultMapping,
1038+
Gids: defaultMapping,
1039+
},
1040+
}
1041+
1042+
hostLogPath, podLogPath := createLogTempDir(podName)
1043+
defer os.RemoveAll(hostLogPath)
1044+
podID, podConfig = createNamespacePodSandbox(rc, namespaceOption, podName, podLogPath)
1045+
1046+
By("create container with image volume mount")
1047+
containerName := "image-volume-userns-container-" + framework.NewUUID()
1048+
containerConfig := &runtimeapi.ContainerConfig{
1049+
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
1050+
Image: &runtimeapi.ImageSpec{
1051+
Image: testImage,
1052+
UserSpecifiedImage: testImage,
1053+
},
1054+
Command: []string{"sh", "-c", "ls -ln /image-volume && stat -c '%u:%g' /image-volume"},
1055+
LogPath: containerName + ".log",
1056+
Mounts: []*runtimeapi.Mount{
1057+
{
1058+
ContainerPath: "/image-volume",
1059+
Readonly: true,
1060+
Image: &runtimeapi.ImageSpec{
1061+
Image: testImage,
1062+
},
1063+
UidMappings: defaultMapping,
1064+
GidMappings: defaultMapping,
1065+
},
1066+
},
1067+
Linux: &runtimeapi.LinuxContainerConfig{
1068+
SecurityContext: &runtimeapi.LinuxContainerSecurityContext{
1069+
NamespaceOptions: podConfig.GetLinux().GetSecurityContext().GetNamespaceOptions(),
1070+
},
1071+
},
1072+
}
1073+
1074+
containerID := createContainerWithExpectation(rc, ic, containerConfig, podID, podConfig, true)
1075+
1076+
By("start container")
1077+
startContainer(rc, containerID)
1078+
1079+
By("wait for container to complete")
1080+
Eventually(func() runtimeapi.ContainerState {
1081+
return getContainerStatus(rc, containerID).GetState()
1082+
}, time.Minute, time.Second*4).Should(Equal(runtimeapi.ContainerState_CONTAINER_EXITED))
1083+
1084+
By("verify image volume is accessible with correct ownership")
1085+
// The files in the image volume should be accessible inside the container
1086+
// with ownership mapped through idmap mounts
1087+
verifyLogContents(podConfig, containerName+".log", "0:0", stdoutType)
1088+
})
10271089
})
10281090

10291091
When("Host idmap mount support is not needed", func() {

0 commit comments

Comments
 (0)