DRA: enhance validation for the ResourceClaimParametersReference and ResourceClassParametersReference with the following rules:

1. `apiGroup`: If set, it must be a valid DNS subdomain (e.g. 'example.com').
2. `kind` and `name`: It must be valid path segment name. It may not be '.' or '..' and it may not contain '/' and '%' characters.
This commit is contained in:
carlory
2024-05-30 17:53:16 +08:00
parent bce55b94cd
commit bce0335ea6
4 changed files with 125 additions and 14 deletions

View File

@@ -53,6 +53,8 @@ func TestValidateClaim(t *testing.T) {
}
now := metav1.Now()
badValue := "spaces not allowed"
badAPIGroup := "example.com/v1"
goodAPIGroup := "example.com"
scenarios := map[string]struct {
claim *resource.ResourceClaim
@@ -216,6 +218,29 @@ func TestValidateClaim(t *testing.T) {
return claim
}(),
},
"good-parameters-apigroup": {
claim: func() *resource.ResourceClaim {
claim := testClaim(goodName, goodNS, goodClaimSpec)
claim.Spec.ParametersRef = &resource.ResourceClaimParametersReference{
APIGroup: goodAPIGroup,
Kind: "foo",
Name: "bar",
}
return claim
}(),
},
"bad-parameters-apigroup": {
wantFailures: field.ErrorList{field.Invalid(field.NewPath("spec", "parametersRef", "apiGroup"), badAPIGroup, "a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')")},
claim: func() *resource.ResourceClaim {
claim := testClaim(goodName, goodNS, goodClaimSpec)
claim.Spec.ParametersRef = &resource.ResourceClaimParametersReference{
APIGroup: badAPIGroup,
Kind: "foo",
Name: "bar",
}
return claim
}(),
},
"missing-parameters-kind": {
wantFailures: field.ErrorList{field.Required(field.NewPath("spec", "parametersRef", "kind"), "")},
claim: func() *resource.ResourceClaim {