Merge pull request #124531 from irsl/master
gitRepo volume: directory must be max 1 level deep
This commit is contained in:
		| @@ -261,6 +261,12 @@ func validateVolume(src *v1.GitRepoVolumeSource) error { | ||||
| 	if err := validateNonFlagArgument(src.Directory, "directory"); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if (src.Revision != "") && (src.Directory != "") { | ||||
| 		cleanedDir := filepath.Clean(src.Directory) | ||||
| 		if strings.Contains(cleanedDir, "/") || (strings.Contains(cleanedDir, "\\")) { | ||||
| 			return fmt.Errorf("%q is not a valid directory, it must not contain a directory separator", src.Directory) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -267,6 +267,20 @@ func TestPlugin(t *testing.T) { | ||||
| 			}, | ||||
| 			isExpectedFailure: true, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "invalid-revision-directory-combo", | ||||
| 			vol: &v1.Volume{ | ||||
| 				Name: "vol1", | ||||
| 				VolumeSource: v1.VolumeSource{ | ||||
| 					GitRepo: &v1.GitRepoVolumeSource{ | ||||
| 						Repository: gitURL, | ||||
| 						Revision:   "main", | ||||
| 						Directory:  "foo/bar", | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			isExpectedFailure: true, | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for _, scenario := range scenarios { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot