Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation webhook for KafkaUser #968

Closed
wants to merge 5 commits into from
Closed

Add validation webhook for KafkaUser #968

wants to merge 5 commits into from

Conversation

panyuenlau
Copy link
Member

@panyuenlau panyuenlau commented May 11, 2023

Description

Add validation webhook implementation for KafkaUser resource creation and update, see the test cases for example misconfigurations and corresponding rejection messages

Type of Change

  • New Feature

Checklist

  • I have read the contributing guidelines
  • I have verified this change is not present in other open pull requests
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@panyuenlau panyuenlau marked this pull request as ready for review May 11, 2023 19:57
@panyuenlau panyuenlau requested a review from a team as a code owner May 11, 2023 19:57
Comment on lines +101 to +105
if util.ObjectManagedByClusterRegistry(kafkaCluster) {
// referencing remote Kafka clusters is not allowed
logMsg = fmt.Sprintf("KafkaCluster CR '%s' in the namespace '%s' is a remote resource", clusterName, clusterNamespace)
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("clusterRef"), kafkaUser.Spec.ClusterRef, logMsg))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Won't this cause issues with clreg replicated KafkaUsers from remote K8s clusters and Kafka clusters?
I didn't see any guard against validating KafkaUsers replicated by clreg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm yea you are right, we probably shouldn't have this restriction here

@panyuenlau
Copy link
Member Author

panyuenlau commented Jun 2, 2023

If we add the KafkaUser validation webhook ATM, validation error will be seen on the dangling SSL resources (more specifically, the KafkaUser that the operator creates but doesn't clean up) due to #989 when users upgrade the operator from an older version.

@panyuenlau panyuenlau marked this pull request as draft June 12, 2023 14:27
Comment on lines +108 to +114
// avoid panic if the user wants to create a kafka user but the cluster is in plaintext mode
if kafkaCluster.Spec.ListenersConfig.SSLSecrets == nil && kafkaUser.Spec.PKIBackendSpec == nil {
logMsg = fmt.Sprintf("KafkaCluster CR '%s' in namespace '%s' is in plaintext mode, "+
"therefore 'spec.pkiBackendSpec' must be provided to create certificate", clusterName, clusterNamespace)
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("pkiBackendSpec"), kafkaUser.Spec.PKIBackendSpec, logMsg))
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself: This check is not validate against a Kafka cluster within a Istio mesh since the broker certs are issued by Istio, not Koperator

@bartam1
Copy link
Contributor

bartam1 commented Jul 21, 2023

Please add this validation also into this PR: #1019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants