use of io.strimzi.api.kafka.model.PasswordSecretSource in project strimzi-kafka-operator by strimzi.
the class UtilTest method testAuthTlsHashScramSha512SecretFoundAndPasswordNotFound.
@Test
public void testAuthTlsHashScramSha512SecretFoundAndPasswordNotFound() {
SecretOperator secretOpertator = mock(SecretOperator.class);
Map<String, String> data = new HashMap<>();
data.put("passwordKey", "my-password");
Secret secret = new Secret();
secret.setData(data);
CompletionStage<Secret> cf = CompletableFuture.supplyAsync(() -> secret);
when(secretOpertator.getAsync(anyString(), anyString())).thenReturn(Future.fromCompletionStage(cf));
KafkaClientAuthenticationScramSha512 auth = new KafkaClientAuthenticationScramSha512();
PasswordSecretSource passwordSecretSource = new PasswordSecretSource();
passwordSecretSource.setSecretName("my-secret");
passwordSecretSource.setPassword("password1");
auth.setPasswordSecret(passwordSecretSource);
Future<Integer> result = Util.authTlsHash(secretOpertator, "anyNamespace", auth, List.of());
result.onComplete(handler -> {
assertTrue(handler.failed());
assertEquals("Secret my-secret does not contain key password1", handler.cause().getMessage());
});
}
use of io.strimzi.api.kafka.model.PasswordSecretSource in project strimzi by strimzi.
the class UtilTest method testAuthTlsPlainSecretFoundAndPasswordNotFound.
@Test
public void testAuthTlsPlainSecretFoundAndPasswordNotFound() {
SecretOperator secretOpertator = mock(SecretOperator.class);
Map<String, String> data = new HashMap<>();
data.put("passwordKey", "my-password");
Secret secret = new Secret();
secret.setData(data);
CompletionStage<Secret> cf = CompletableFuture.supplyAsync(() -> secret);
when(secretOpertator.getAsync(anyString(), anyString())).thenReturn(Future.fromCompletionStage(cf));
KafkaClientAuthenticationPlain auth = new KafkaClientAuthenticationPlain();
PasswordSecretSource passwordSecretSource = new PasswordSecretSource();
passwordSecretSource.setSecretName("my-secret");
passwordSecretSource.setPassword("password1");
auth.setPasswordSecret(passwordSecretSource);
Future<Integer> result = Util.authTlsHash(secretOpertator, "anyNamespace", auth, List.of());
result.onComplete(handler -> {
assertTrue(handler.failed());
assertEquals("Secret my-secret does not contain key password1", handler.cause().getMessage());
});
}
use of io.strimzi.api.kafka.model.PasswordSecretSource in project strimzi by strimzi.
the class UtilTest method testAuthTlsPlainSecretAndPasswordFound.
@Test
public void testAuthTlsPlainSecretAndPasswordFound() {
SecretOperator secretOpertator = mock(SecretOperator.class);
Map<String, String> data = new HashMap<>();
data.put("passwordKey", "my-password");
Secret secret = new Secret();
secret.setData(data);
CompletionStage<Secret> cf = CompletableFuture.supplyAsync(() -> secret);
when(secretOpertator.getAsync(anyString(), anyString())).thenReturn(Future.fromCompletionStage(cf));
KafkaClientAuthenticationPlain auth = new KafkaClientAuthenticationPlain();
PasswordSecretSource passwordSecretSource = new PasswordSecretSource();
passwordSecretSource.setSecretName("my-secret");
passwordSecretSource.setPassword("passwordKey");
auth.setPasswordSecret(passwordSecretSource);
Future<Integer> result = Util.authTlsHash(secretOpertator, "anyNamespace", auth, List.of());
result.onComplete(handler -> {
assertTrue(handler.succeeded());
assertEquals("my-password".hashCode(), handler.result());
});
}
use of io.strimzi.api.kafka.model.PasswordSecretSource in project strimzi by strimzi.
the class HttpBridgeScramShaST method setUp.
@BeforeAll
void setUp(ExtensionContext extensionContext) {
LOGGER.info("Deploy Kafka and KafkaBridge before tests");
// Deploy kafka
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(httpBridgeScramShaClusterName, 1, 1).editMetadata().withNamespace(namespace).endMetadata().editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).endKafka().endSpec().build());
String kafkaClientsName = namespace + "-shared-" + Constants.KAFKA_CLIENTS;
// Create Kafka user
KafkaUser scramShaUser = KafkaUserTemplates.scramShaUser(httpBridgeScramShaClusterName, USER_NAME).editMetadata().withNamespace(namespace).endMetadata().build();
resourceManager.createResource(extensionContext, scramShaUser);
resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(namespace, true, kafkaClientsName, scramShaUser).build());
kafkaClientsPodName = kubeClient(namespace).listPodsByPrefixInName(namespace, kafkaClientsName).get(0).getMetadata().getName();
// Initialize PasswordSecret to set this as PasswordSecret in Mirror Maker spec
PasswordSecretSource passwordSecret = new PasswordSecretSource();
passwordSecret.setSecretName(USER_NAME);
passwordSecret.setPassword("password");
// Initialize CertSecretSource with certificate and secret names for consumer
CertSecretSource certSecret = new CertSecretSource();
certSecret.setCertificate("ca.crt");
certSecret.setSecretName(KafkaResources.clusterCaCertificateSecretName(httpBridgeScramShaClusterName));
// Deploy http bridge
resourceManager.createResource(extensionContext, KafkaBridgeTemplates.kafkaBridge(httpBridgeScramShaClusterName, KafkaResources.tlsBootstrapAddress(httpBridgeScramShaClusterName), 1).editMetadata().withNamespace(namespace).endMetadata().editSpec().withNewConsumer().addToConfig(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest").endConsumer().withNewKafkaClientAuthenticationScramSha512().withUsername(USER_NAME).withPasswordSecret(passwordSecret).endKafkaClientAuthenticationScramSha512().withNewTls().withTrustedCertificates(certSecret).endTls().endSpec().build());
kafkaBridgeClientJob = new BridgeClientsBuilder().withProducerName(producerName).withConsumerName(consumerName).withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeScramShaClusterName)).withTopicName(TOPIC_NAME).withMessageCount(MESSAGE_COUNT).withPort(Constants.HTTP_BRIDGE_DEFAULT_PORT).withNamespaceName(namespace).build();
}
use of io.strimzi.api.kafka.model.PasswordSecretSource in project strimzi-kafka-operator 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);
}
Aggregations