use of io.strimzi.api.kafka.model.KafkaBridgeSpec in project strimzi by strimzi.
the class HttpBridgeKafkaExternalListenersST method testScramShaAuthWithWeirdUsername.
@ParallelTest
void testScramShaAuthWithWeirdUsername(ExtensionContext extensionContext) {
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
// Create weird named user with . and more than 64 chars -> SCRAM-SHA
final String weirdUserName = "jjglmahyijoambryleyxjjglmahy.ijoambryleyxjjglmahyijoambryleyxasd.asdasidioiqweioqiweooioqieioqieoqieooi";
// Initialize PasswordSecret to set this as PasswordSecret in Mirror Maker spec
final PasswordSecretSource passwordSecret = new PasswordSecretSource();
passwordSecret.setSecretName(weirdUserName);
passwordSecret.setPassword("password");
// Initialize CertSecretSource with certificate and secret names for consumer
CertSecretSource certSecret = new CertSecretSource();
certSecret.setCertificate("ca.crt");
certSecret.setSecretName(KafkaResources.clusterCaCertificateSecretName(clusterName));
KafkaBridgeSpec bridgeSpec = new KafkaBridgeSpecBuilder().withNewKafkaClientAuthenticationScramSha512().withUsername(weirdUserName).withPasswordSecret(passwordSecret).endKafkaClientAuthenticationScramSha512().withNewTls().withTrustedCertificates(certSecret).endTls().build();
testWeirdUsername(extensionContext, weirdUserName, new KafkaListenerAuthenticationScramSha512(), bridgeSpec, SecurityProtocol.SASL_SSL);
}
use of io.strimzi.api.kafka.model.KafkaBridgeSpec in project strimzi by strimzi.
the class KafkaBridgeCluster method fromCrd.
public static KafkaBridgeCluster fromCrd(Reconciliation reconciliation, KafkaBridge kafkaBridge, KafkaVersion.Lookup versions) {
KafkaBridgeCluster kafkaBridgeCluster = new KafkaBridgeCluster(reconciliation, kafkaBridge);
KafkaBridgeSpec spec = kafkaBridge.getSpec();
kafkaBridgeCluster.tracing = spec.getTracing();
kafkaBridgeCluster.setResources(spec.getResources());
kafkaBridgeCluster.setLogging(spec.getLogging());
kafkaBridgeCluster.setGcLoggingEnabled(spec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : spec.getJvmOptions().isGcLoggingEnabled());
if (spec.getJvmOptions() != null) {
kafkaBridgeCluster.setJavaSystemProperties(spec.getJvmOptions().getJavaSystemProperties());
}
kafkaBridgeCluster.setJvmOptions(spec.getJvmOptions());
String image = spec.getImage();
if (image == null) {
image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_BRIDGE_IMAGE, "quay.io/strimzi/kafka-bridge:latest");
}
kafkaBridgeCluster.setImage(image);
kafkaBridgeCluster.setReplicas(spec.getReplicas());
kafkaBridgeCluster.setBootstrapServers(spec.getBootstrapServers());
kafkaBridgeCluster.setKafkaAdminClientConfiguration(spec.getAdminClient());
kafkaBridgeCluster.setKafkaConsumerConfiguration(spec.getConsumer());
kafkaBridgeCluster.setKafkaProducerConfiguration(spec.getProducer());
if (kafkaBridge.getSpec().getLivenessProbe() != null) {
kafkaBridgeCluster.setLivenessProbe(kafkaBridge.getSpec().getLivenessProbe());
}
if (kafkaBridge.getSpec().getReadinessProbe() != null) {
kafkaBridgeCluster.setReadinessProbe(kafkaBridge.getSpec().getReadinessProbe());
}
kafkaBridgeCluster.setMetricsEnabled(spec.getEnableMetrics());
kafkaBridgeCluster.setTls(spec.getTls() != null ? spec.getTls() : null);
String warnMsg = AuthenticationUtils.validateClientAuthentication(spec.getAuthentication(), spec.getTls() != null);
if (!warnMsg.isEmpty()) {
LOGGER.warnCr(reconciliation, warnMsg);
}
kafkaBridgeCluster.setAuthentication(spec.getAuthentication());
if (spec.getTemplate() != null) {
KafkaBridgeTemplate template = spec.getTemplate();
ModelUtils.parseDeploymentTemplate(kafkaBridgeCluster, template.getDeployment());
ModelUtils.parsePodTemplate(kafkaBridgeCluster, template.getPod());
ModelUtils.parseInternalServiceTemplate(kafkaBridgeCluster, template.getApiService());
if (template.getApiService() != null && template.getApiService().getMetadata() != null) {
kafkaBridgeCluster.templateServiceLabels = template.getApiService().getMetadata().getLabels();
kafkaBridgeCluster.templateServiceAnnotations = template.getApiService().getMetadata().getAnnotations();
}
if (template.getBridgeContainer() != null && template.getBridgeContainer().getEnv() != null) {
kafkaBridgeCluster.templateContainerEnvVars = template.getBridgeContainer().getEnv();
}
if (template.getBridgeContainer() != null && template.getBridgeContainer().getSecurityContext() != null) {
kafkaBridgeCluster.templateContainerSecurityContext = template.getBridgeContainer().getSecurityContext();
}
if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
kafkaBridgeCluster.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
kafkaBridgeCluster.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
}
ModelUtils.parsePodDisruptionBudgetTemplate(kafkaBridgeCluster, template.getPodDisruptionBudget());
}
kafkaBridgeCluster.templatePodLabels = Util.mergeLabelsOrAnnotations(kafkaBridgeCluster.templatePodLabels, DEFAULT_POD_LABELS);
if (spec.getHttp() != null) {
kafkaBridgeCluster.setHttpEnabled(true);
kafkaBridgeCluster.setKafkaBridgeHttpConfig(spec.getHttp());
} else {
LOGGER.warnCr(reconciliation, "No protocol specified.");
throw new InvalidResourceException("No protocol for communication with Bridge specified. Use HTTP.");
}
kafkaBridgeCluster.setOwnerReference(kafkaBridge);
return kafkaBridgeCluster;
}
use of io.strimzi.api.kafka.model.KafkaBridgeSpec in project strimzi-kafka-operator by strimzi.
the class KafkaBridgeCluster method fromCrd.
public static KafkaBridgeCluster fromCrd(Reconciliation reconciliation, KafkaBridge kafkaBridge, KafkaVersion.Lookup versions) {
KafkaBridgeCluster kafkaBridgeCluster = new KafkaBridgeCluster(reconciliation, kafkaBridge);
KafkaBridgeSpec spec = kafkaBridge.getSpec();
kafkaBridgeCluster.tracing = spec.getTracing();
kafkaBridgeCluster.setResources(spec.getResources());
kafkaBridgeCluster.setLogging(spec.getLogging());
kafkaBridgeCluster.setGcLoggingEnabled(spec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : spec.getJvmOptions().isGcLoggingEnabled());
if (spec.getJvmOptions() != null) {
kafkaBridgeCluster.setJavaSystemProperties(spec.getJvmOptions().getJavaSystemProperties());
}
kafkaBridgeCluster.setJvmOptions(spec.getJvmOptions());
String image = spec.getImage();
if (image == null) {
image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_BRIDGE_IMAGE, "quay.io/strimzi/kafka-bridge:latest");
}
kafkaBridgeCluster.setImage(image);
kafkaBridgeCluster.setReplicas(spec.getReplicas());
kafkaBridgeCluster.setBootstrapServers(spec.getBootstrapServers());
kafkaBridgeCluster.setKafkaAdminClientConfiguration(spec.getAdminClient());
kafkaBridgeCluster.setKafkaConsumerConfiguration(spec.getConsumer());
kafkaBridgeCluster.setKafkaProducerConfiguration(spec.getProducer());
if (kafkaBridge.getSpec().getLivenessProbe() != null) {
kafkaBridgeCluster.setLivenessProbe(kafkaBridge.getSpec().getLivenessProbe());
}
if (kafkaBridge.getSpec().getReadinessProbe() != null) {
kafkaBridgeCluster.setReadinessProbe(kafkaBridge.getSpec().getReadinessProbe());
}
kafkaBridgeCluster.setMetricsEnabled(spec.getEnableMetrics());
kafkaBridgeCluster.setTls(spec.getTls() != null ? spec.getTls() : null);
String warnMsg = AuthenticationUtils.validateClientAuthentication(spec.getAuthentication(), spec.getTls() != null);
if (!warnMsg.isEmpty()) {
LOGGER.warnCr(reconciliation, warnMsg);
}
kafkaBridgeCluster.setAuthentication(spec.getAuthentication());
if (spec.getTemplate() != null) {
KafkaBridgeTemplate template = spec.getTemplate();
ModelUtils.parseDeploymentTemplate(kafkaBridgeCluster, template.getDeployment());
ModelUtils.parsePodTemplate(kafkaBridgeCluster, template.getPod());
ModelUtils.parseInternalServiceTemplate(kafkaBridgeCluster, template.getApiService());
if (template.getApiService() != null && template.getApiService().getMetadata() != null) {
kafkaBridgeCluster.templateServiceLabels = template.getApiService().getMetadata().getLabels();
kafkaBridgeCluster.templateServiceAnnotations = template.getApiService().getMetadata().getAnnotations();
}
if (template.getBridgeContainer() != null && template.getBridgeContainer().getEnv() != null) {
kafkaBridgeCluster.templateContainerEnvVars = template.getBridgeContainer().getEnv();
}
if (template.getBridgeContainer() != null && template.getBridgeContainer().getSecurityContext() != null) {
kafkaBridgeCluster.templateContainerSecurityContext = template.getBridgeContainer().getSecurityContext();
}
if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
kafkaBridgeCluster.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
kafkaBridgeCluster.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
}
ModelUtils.parsePodDisruptionBudgetTemplate(kafkaBridgeCluster, template.getPodDisruptionBudget());
}
kafkaBridgeCluster.templatePodLabels = Util.mergeLabelsOrAnnotations(kafkaBridgeCluster.templatePodLabels, DEFAULT_POD_LABELS);
if (spec.getHttp() != null) {
kafkaBridgeCluster.setHttpEnabled(true);
kafkaBridgeCluster.setKafkaBridgeHttpConfig(spec.getHttp());
} else {
LOGGER.warnCr(reconciliation, "No protocol specified.");
throw new InvalidResourceException("No protocol for communication with Bridge specified. Use HTTP.");
}
kafkaBridgeCluster.setOwnerReference(kafkaBridge);
return kafkaBridgeCluster;
}
use of io.strimzi.api.kafka.model.KafkaBridgeSpec in project strimzi-kafka-operator by strimzi.
the class HttpBridgeKafkaExternalListenersST method testTlsAuthWithWeirdUsername.
@ParallelTest
void testTlsAuthWithWeirdUsername(ExtensionContext extensionContext) {
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
// Create weird named user with . and maximum of 64 chars -> TLS
final String weirdUserName = "jjglmahyijoambryleyxjjglmahy.ijoambryleyxjjglmahyijoambryleyxasd";
// Initialize CertSecretSource with certificate and secret names for consumer
CertSecretSource certSecret = new CertSecretSource();
certSecret.setCertificate("ca.crt");
certSecret.setSecretName(KafkaResources.clusterCaCertificateSecretName(clusterName));
KafkaBridgeSpec bridgeSpec = new KafkaBridgeSpecBuilder().withNewKafkaClientAuthenticationTls().withNewCertificateAndKey().withSecretName(weirdUserName).withCertificate("user.crt").withKey("user.key").endCertificateAndKey().endKafkaClientAuthenticationTls().withNewTls().withTrustedCertificates(certSecret).endTls().build();
testWeirdUsername(extensionContext, weirdUserName, new KafkaListenerAuthenticationTls(), bridgeSpec, SecurityProtocol.SSL);
}
use of io.strimzi.api.kafka.model.KafkaBridgeSpec in project strimzi by strimzi.
the class HttpBridgeKafkaExternalListenersST method testWeirdUsername.
@SuppressWarnings({ "checkstyle:MethodLength" })
private void testWeirdUsername(ExtensionContext extensionContext, String weirdUserName, KafkaListenerAuthentication auth, KafkaBridgeSpec spec, SecurityProtocol securityProtocol) {
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 1).editMetadata().withNamespace(namespace).endMetadata().editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).withAuth(auth).build(), new GenericKafkaListenerBuilder().withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withAuth(auth).build()).endKafka().endSpec().build());
BridgeClients kafkaBridgeClientJob = new BridgeClientsBuilder().withProducerName(clusterName + "-" + producerName).withConsumerName(clusterName + "-" + consumerName).withBootstrapAddress(KafkaBridgeResources.serviceName(clusterName)).withTopicName(topicName).withMessageCount(MESSAGE_COUNT).withPort(Constants.HTTP_BRIDGE_DEFAULT_PORT).withNamespaceName(namespace).build();
// Create topic
resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(clusterName, topicName).editMetadata().withNamespace(namespace).endMetadata().build());
// Create user
if (auth.getType().equals(Constants.TLS_LISTENER_DEFAULT_NAME)) {
resourceManager.createResource(extensionContext, KafkaUserTemplates.tlsUser(clusterName, weirdUserName).editMetadata().withNamespace(namespace).endMetadata().build());
} else {
resourceManager.createResource(extensionContext, KafkaUserTemplates.scramShaUser(clusterName, weirdUserName).editMetadata().withNamespace(namespace).endMetadata().build());
}
final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(namespace, true, kafkaClientsName).build());
// Deploy http bridge
resourceManager.createResource(extensionContext, KafkaBridgeTemplates.kafkaBridge(clusterName, KafkaResources.tlsBootstrapAddress(clusterName), 1).editMetadata().withNamespace(namespace).endMetadata().withNewSpecLike(spec).withBootstrapServers(KafkaResources.tlsBootstrapAddress(clusterName)).withNewHttp(Constants.HTTP_BRIDGE_DEFAULT_PORT).withNewConsumer().addToConfig(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest").endConsumer().endSpec().build());
final Service service = KafkaBridgeUtils.createBridgeNodePortService(clusterName, namespace, BRIDGE_EXTERNAL_SERVICE);
ServiceResource.createServiceResource(extensionContext, service, namespace);
resourceManager.createResource(extensionContext, kafkaBridgeClientJob.consumerStrimziBridge());
final String kafkaProducerExternalName = "kafka-producer-external" + new Random().nextInt(Integer.MAX_VALUE);
final List<ListenerStatus> listenerStatusList = KafkaResource.kafkaClient().inNamespace(namespace).withName(clusterName).get().getStatus().getListeners();
final String externalBootstrapServers = listenerStatusList.stream().filter(listener -> listener.getType().equals(Constants.EXTERNAL_LISTENER_DEFAULT_NAME)).findFirst().orElseThrow(RuntimeException::new).getBootstrapServers();
final KafkaClients externalKafkaProducer = new KafkaClientsBuilder().withProducerName(kafkaProducerExternalName).withBootstrapAddress(externalBootstrapServers).withNamespaceName(namespace).withTopicName(topicName).withMessageCount(100).build();
if (auth.getType().equals(Constants.TLS_LISTENER_DEFAULT_NAME)) {
// tls producer
resourceManager.createResource(extensionContext, externalKafkaProducer.producerTlsStrimzi(clusterName, weirdUserName));
} else {
// scram-sha producer
resourceManager.createResource(extensionContext, externalKafkaProducer.producerScramShaStrimzi(clusterName, weirdUserName));
}
ClientUtils.waitForClientSuccess(kafkaProducerExternalName, namespace, MESSAGE_COUNT);
// delete kafka producer job
JobUtils.deleteJobWithWait(namespace, kafkaProducerExternalName);
ClientUtils.waitForClientSuccess(clusterName + "-" + consumerName, namespace, MESSAGE_COUNT);
}
Aggregations