Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 5b8046c

Browse files
authored
Merge pull request #1073 from Random-Liu/cherrypick-#1072-release-1.0
Cherrypick #1072 release 1.0
2 parents d35c674 + b01bbde commit 5b8046c

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

pkg/server/container_create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
192192
if len(volumeMounts) > 0 {
193193
mountMap := make(map[string]string)
194194
for _, v := range volumeMounts {
195-
mountMap[v.HostPath] = v.ContainerPath
195+
mountMap[filepath.Clean(v.HostPath)] = v.ContainerPath
196196
}
197197
opts = append(opts, customopts.WithVolumes(mountMap))
198198
}
@@ -723,7 +723,7 @@ func setOCIBindMountsPrivileged(g *generator) {
723723
spec := g.Spec()
724724
// clear readonly for /sys and cgroup
725725
for i, m := range spec.Mounts {
726-
if spec.Mounts[i].Destination == "/sys" && !spec.Root.Readonly {
726+
if filepath.Clean(spec.Mounts[i].Destination) == "/sys" && !spec.Root.Readonly {
727727
clearReadOnly(&spec.Mounts[i])
728728
}
729729
if m.Type == "cgroup" {
@@ -830,7 +830,7 @@ func defaultRuntimeSpec(id string) (*runtimespec.Spec, error) {
830830
// TODO(random-liu): Mount tmpfs for /run and handle copy-up.
831831
var mounts []runtimespec.Mount
832832
for _, mount := range spec.Mounts {
833-
if mount.Destination == "/run" {
833+
if filepath.Clean(mount.Destination) == "/run" {
834834
continue
835835
}
836836
mounts = append(mounts, mount)

pkg/server/container_create_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ func TestContainerSpecWithExtraMounts(t *testing.T) {
308308
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
309309
c := newTestCRIService()
310310
mountInConfig := &runtime.Mount{
311-
ContainerPath: "test-container-path",
311+
// Test cleanpath
312+
ContainerPath: "test-container-path/",
312313
HostPath: "test-host-path",
313314
Readonly: false,
314315
}
@@ -335,7 +336,7 @@ func TestContainerSpecWithExtraMounts(t *testing.T) {
335336
specCheck(t, testID, testSandboxID, testPid, spec)
336337
var mounts, sysMounts, devMounts []runtimespec.Mount
337338
for _, m := range spec.Mounts {
338-
if m.Destination == "test-container-path" {
339+
if strings.HasPrefix(m.Destination, "test-container-path") {
339340
mounts = append(mounts, m)
340341
} else if m.Destination == "/sys" {
341342
sysMounts = append(sysMounts, m)
@@ -498,6 +499,21 @@ func TestGenerateVolumeMounts(t *testing.T) {
498499
"/test-volume-2",
499500
},
500501
},
502+
"should compare and return cleanpath": {
503+
criMounts: []*runtime.Mount{
504+
{
505+
ContainerPath: "/test-volume-1",
506+
HostPath: "/test-hostpath-1",
507+
},
508+
},
509+
imageVolumes: map[string]struct{}{
510+
"/test-volume-1/": {},
511+
"/test-volume-2/": {},
512+
},
513+
expectedMountDest: []string{
514+
"/test-volume-2/",
515+
},
516+
},
501517
} {
502518
t.Logf("TestCase %q", desc)
503519
config := &imagespec.ImageConfig{

pkg/server/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func checkSelinuxLevel(level string) (bool, error) {
414414
// isInCRIMounts checks whether a destination is in CRI mount list.
415415
func isInCRIMounts(dst string, mounts []*runtime.Mount) bool {
416416
for _, m := range mounts {
417-
if m.ContainerPath == dst {
417+
if filepath.Clean(m.ContainerPath) == filepath.Clean(dst) {
418418
return true
419419
}
420420
}

0 commit comments

Comments
 (0)