Skip to content

Commit

Permalink
Infinispan webhook should prevent incompatible TLS configuration. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson committed Aug 15, 2023
1 parent 5da3067 commit 6fc0597
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
17 changes: 13 additions & 4 deletions api/v1/infinispan_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,19 @@ func (i *Infinispan) validate() error {
allErrs = append(allErrs, err)
}

if i.IsEncryptionEnabled() && i.Spec.Security.EndpointEncryption.CertSecretName == "" {
msg := fmt.Sprintf("field must be provided for 'spec.security.endpointEncryption.certificateSourceType=%s' to be configured", CertificateSourceTypeSecret)
err := field.Required(field.NewPath("spec").Child("security").Child("endpointEncryption").Child("certSecretName"), msg)
allErrs = append(allErrs, err)
if i.IsEncryptionEnabled() {
e := i.Spec.Security.EndpointEncryption
if e.CertSecretName == "" {
msg := fmt.Sprintf("field must be provided for 'spec.security.endpointEncryption.certificateSourceType=%s' to be configured", CertificateSourceTypeSecret)
err := field.Required(field.NewPath("spec").Child("security").Child("endpointEncryption").Child("certSecretName"), msg)
allErrs = append(allErrs, err)
}

if e.CertServiceName != "" && e.Type == CertificateSourceTypeSecret {
msg := fmt.Sprintf(".certServiceName cannot be configured with Encryption .type=%s", CertificateSourceTypeSecret)
err := field.Forbidden(field.NewPath("spec").Child("security").Child("endpointEncryption").Child("certServiceName"), msg)
allErrs = append(allErrs, err)
}
}

if cl := i.Spec.ConfigListener; cl != nil {
Expand Down
22 changes: 22 additions & 0 deletions api/v1/infinispan_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,28 @@ var _ = Describe("Infinispan Webhooks", func() {
statusDetailCause{"FieldValueForbidden", "spec.jmx", "JMX configuration is immutable and cannot be updated after initial Infinispan creation"},
)
})

It("Should prevent incompatible TLS configuration", func() {
ispn := &Infinispan{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: InfinispanSpec{
Replicas: 1,
Security: InfinispanSecurity{
EndpointEncryption: &EndpointEncryption{
CertSecretName: "secret-name",
CertServiceName: "service.com",
Type: CertificateSourceTypeSecret,
},
},
},
}
expectInvalidErrStatus(k8sClient.Create(ctx, ispn),
statusDetailCause{"FieldValueForbidden", "spec.security.endpointEncryption.certServiceName", ".certServiceName cannot be configured with Encryption .type=Secret"},
)
})
})
})

Expand Down

0 comments on commit 6fc0597

Please sign in to comment.