mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	mountpath should be absolute
This commit is contained in:
		@@ -1760,6 +1760,9 @@ func ValidateVolumeMounts(mounts []api.VolumeMount, volumes sets.String, fldPath
 | 
				
			|||||||
		if mountpoints.Has(mnt.MountPath) {
 | 
							if mountpoints.Has(mnt.MountPath) {
 | 
				
			||||||
			allErrs = append(allErrs, field.Invalid(idxPath.Child("mountPath"), mnt.MountPath, "must be unique"))
 | 
								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)
 | 
							mountpoints.Insert(mnt.MountPath)
 | 
				
			||||||
		if len(mnt.SubPath) > 0 {
 | 
							if len(mnt.SubPath) > 0 {
 | 
				
			||||||
			allErrs = append(allErrs, validateLocalDescendingPath(mnt.SubPath, fldPath.Child("subPath"))...)
 | 
								allErrs = append(allErrs, validateLocalDescendingPath(mnt.SubPath, fldPath.Child("subPath"))...)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3045,7 +3045,6 @@ func TestValidateVolumeMounts(t *testing.T) {
 | 
				
			|||||||
		{Name: "abc-123", MountPath: "/bab", SubPath: "baz"},
 | 
							{Name: "abc-123", MountPath: "/bab", SubPath: "baz"},
 | 
				
			||||||
		{Name: "abc-123", MountPath: "/bac", SubPath: ".baz"},
 | 
							{Name: "abc-123", MountPath: "/bac", SubPath: ".baz"},
 | 
				
			||||||
		{Name: "abc-123", MountPath: "/bad", 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 {
 | 
						if errs := ValidateVolumeMounts(successCase, volumes, field.NewPath("field")); len(errs) != 0 {
 | 
				
			||||||
		t.Errorf("expected success: %v", errs)
 | 
							t.Errorf("expected success: %v", errs)
 | 
				
			||||||
@@ -3055,6 +3054,7 @@ func TestValidateVolumeMounts(t *testing.T) {
 | 
				
			|||||||
		"empty name":          {{Name: "", MountPath: "/foo"}},
 | 
							"empty name":          {{Name: "", MountPath: "/foo"}},
 | 
				
			||||||
		"name not found":      {{Name: "", MountPath: "/foo"}},
 | 
							"name not found":      {{Name: "", MountPath: "/foo"}},
 | 
				
			||||||
		"empty mountpath":     {{Name: "abc", MountPath: ""}},
 | 
							"empty mountpath":     {{Name: "abc", MountPath: ""}},
 | 
				
			||||||
 | 
							"relative mountpath":  {{Name: "abc", MountPath: "bar"}},
 | 
				
			||||||
		"mountpath collision": {{Name: "foo", MountPath: "/path/a"}, {Name: "bar", MountPath: "/path/a"}},
 | 
							"mountpath collision": {{Name: "foo", MountPath: "/path/a"}, {Name: "bar", MountPath: "/path/a"}},
 | 
				
			||||||
		"absolute subpath":    {{Name: "abc", MountPath: "/bar", SubPath: "/baz"}},
 | 
							"absolute subpath":    {{Name: "abc", MountPath: "/bar", SubPath: "/baz"}},
 | 
				
			||||||
		"subpath in ..":       {{Name: "abc", MountPath: "/bar", SubPath: "../baz"}},
 | 
							"subpath in ..":       {{Name: "abc", MountPath: "/bar", SubPath: "../baz"}},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user