From 8d86bd1c644fec011e2cb48414d66a7dbc3f7f1d Mon Sep 17 00:00:00 2001 From: Di Xu Date: Wed, 12 Jul 2017 23:37:51 +0800 Subject: [PATCH] mountpath should be absolute --- pkg/api/validation/validation.go | 3 +++ pkg/api/validation/validation_test.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 32cea35b67d..f6bd510bfdd 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -1760,6 +1760,9 @@ func ValidateVolumeMounts(mounts []api.VolumeMount, volumes sets.String, fldPath if mountpoints.Has(mnt.MountPath) { allErrs = append(allErrs, field.Invalid(idxPath.Child("mountPath"), mnt.MountPath, "must be unique")) } + if !path.IsAbs(mnt.MountPath) { + allErrs = append(allErrs, field.Invalid(idxPath.Child("mountPath"), mnt.MountPath, "must be an absolute path")) + } mountpoints.Insert(mnt.MountPath) if len(mnt.SubPath) > 0 { allErrs = append(allErrs, validateLocalDescendingPath(mnt.SubPath, fldPath.Child("subPath"))...) diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index 141520043eb..6f0940d03e1 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -3045,7 +3045,6 @@ func TestValidateVolumeMounts(t *testing.T) { {Name: "abc-123", MountPath: "/bab", SubPath: "baz"}, {Name: "abc-123", MountPath: "/bac", SubPath: ".baz"}, {Name: "abc-123", MountPath: "/bad", SubPath: "..baz"}, - {Name: "abc", MountPath: "c:/foo/bar"}, } if errs := ValidateVolumeMounts(successCase, volumes, field.NewPath("field")); len(errs) != 0 { t.Errorf("expected success: %v", errs) @@ -3055,6 +3054,7 @@ func TestValidateVolumeMounts(t *testing.T) { "empty name": {{Name: "", MountPath: "/foo"}}, "name not found": {{Name: "", MountPath: "/foo"}}, "empty mountpath": {{Name: "abc", MountPath: ""}}, + "relative mountpath": {{Name: "abc", MountPath: "bar"}}, "mountpath collision": {{Name: "foo", MountPath: "/path/a"}, {Name: "bar", MountPath: "/path/a"}}, "absolute subpath": {{Name: "abc", MountPath: "/bar", SubPath: "/baz"}}, "subpath in ..": {{Name: "abc", MountPath: "/bar", SubPath: "../baz"}},