Sets KeySize openapi schema max/min validation

Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
This commit is contained in:
JoshVanL 2020-02-12 10:17:48 +00:00
parent f9c23dcb8f
commit d784453ada
No known key found for this signature in database
GPG Key ID: E7A7196576A219DA
4 changed files with 8 additions and 21 deletions

View File

@ -133,6 +133,10 @@ type CertificateSpec struct {
// If provided, value must be between 2048 and 8192 inclusive when KeyAlgorithm is
// empty or is set to "rsa", and value must be one of (256, 384, 521) when
// KeyAlgorithm is set to "ecdsa".
// +kubebuilder:validation:ExclusiveMaximum=false
// +kubebuilder:validation:Maximum=8192
// +kubebuilder:validation:ExclusiveMinimum=false
// +kubebuilder:validation:Minimum=0
// +optional
KeySize int `json:"keySize,omitempty"`

View File

@ -129,6 +129,10 @@ type CertificateSpec struct {
// If provided, value must be between 2048 and 8192 inclusive when KeyAlgorithm is
// empty or is set to "rsa", and value must be one of (256, 384, 521) when
// KeyAlgorithm is set to "ecdsa".
// +kubebuilder:validation:ExclusiveMaximum=false
// +kubebuilder:validation:Maximum=8192
// +kubebuilder:validation:ExclusiveMinimum=false
// +kubebuilder:validation:Minimum=0
// +optional
KeySize int `json:"keySize,omitempty"`

View File

@ -52,9 +52,6 @@ func ValidateCertificateSpec(crt *cmapi.CertificateSpec, fldPath *field.Path) fi
if len(crt.IPAddresses) > 0 {
el = append(el, validateIPAddresses(crt, fldPath)...)
}
if crt.KeySize < 0 {
el = append(el, field.Invalid(fldPath.Child("keySize"), crt.KeySize, "cannot be less than zero"))
}
switch crt.KeyAlgorithm {
case cmapi.KeyAlgorithm(""):
case cmapi.RSAKeyAlgorithm:
@ -75,11 +72,6 @@ func ValidateCertificateSpec(crt *cmapi.CertificateSpec, fldPath *field.Path) fi
if len(crt.Usages) > 0 {
el = append(el, validateUsages(crt, fldPath)...)
}
switch crt.KeyEncoding {
case cmapi.KeyEncoding(""), cmapi.PKCS1, cmapi.PKCS8:
default:
el = append(el, field.Invalid(fldPath.Child("keyEncoding"), crt.KeyEncoding, "must be either empty or one of pkcs1 or pkcs8"))
}
return el
}

View File

@ -244,19 +244,6 @@ func TestValidateCertificate(t *testing.T) {
},
},
},
"certificate with keysize less than zero": {
cfg: &cmapi.Certificate{
Spec: cmapi.CertificateSpec{
CommonName: "testcn",
SecretName: "abc",
IssuerRef: validIssuerRef,
KeySize: -99,
},
},
errs: []*field.Error{
field.Invalid(fldPath.Child("keySize"), -99, "cannot be less than zero"),
},
},
"certificate with rsa keyAlgorithm specified and invalid keysize 1024": {
cfg: &cmapi.Certificate{
Spec: cmapi.CertificateSpec{