Search in sources :

Example 41 with PasswordGenerator

use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.

the class KafkaUpgradeDowngradeMockTest method initialize.

private Future<Void> initialize(VertxTestContext context, Kafka initialKafka) {
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(initialKafka).withStrimziPodSetCrd().withStatefulSetController().withPodController().withServiceController().withDeploymentController().build();
    mockKube.start();
    ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, client, ResourceUtils.zookeeperLeaderFinder(vertx, client), ResourceUtils.adminClientProvider(), ResourceUtils.zookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, 2_000);
    ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
    operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
    LOGGER.info("Reconciling initially -> create");
    return operator.reconcile(new Reconciliation("initial-reconciliation", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}
Also used : ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) MockKube2(io.strimzi.test.mockkube2.MockKube2) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation)

Example 42 with PasswordGenerator

use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.

the class PartialRollingUpdateMockTest method beforeEach.

@BeforeEach
public void beforeEach(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    this.cluster = new KafkaBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).build()).withNewSpec().withNewKafka().withReplicas(5).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build(), new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).build()).withNewPersistentClaimStorage().withSize("123").withStorageClass("foo").withDeleteClaim(true).endPersistentClaimStorage().endKafka().withNewZookeeper().withReplicas(3).withNewPersistentClaimStorage().withSize("123").withStorageClass("foo").withDeleteClaim(true).endPersistentClaimStorage().endZookeeper().endSpec().build();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(cluster).withStrimziPodSetCrd().withDeploymentController().withPodController().withStatefulSetController().withServiceController().build();
    mockKube.start();
    ResourceOperatorSupplier supplier = supplier(client);
    kco = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS, 2_000));
    LOGGER.info("Initial reconciliation");
    CountDownLatch createAsync = new CountDownLatch(1);
    kco.reconcile(new Reconciliation("initialization", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(ar -> {
        context.verify(() -> assertThat(ar.succeeded(), is(true)));
        createAsync.countDown();
    });
    if (!createAsync.await(60, TimeUnit.SECONDS)) {
        context.failNow(new Throwable("Test timeout"));
    }
    LOGGER.info("Initial reconciliation complete");
    context.completeNow();
}
Also used : KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) MockKube2(io.strimzi.test.mockkube2.MockKube2) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 43 with PasswordGenerator

use of io.strimzi.operator.common.PasswordGenerator in project strimzi-kafka-operator by strimzi.

the class KafkaCluster method generateJmxSecret.

/**
 * Generate the Secret containing the username and password to secure the jmx port on the Kafka brokers.
 *
 * @param currentSecret The existing Secret with the current JMX credentials. Null if no secret exists yet.
 *
 * @return The generated Secret
 */
public Secret generateJmxSecret(Secret currentSecret) {
    if (isJmxAuthenticated) {
        PasswordGenerator passwordGenerator = new PasswordGenerator(16);
        Map<String, String> data = new HashMap<>(2);
        if (currentSecret != null && currentSecret.getData() != null) {
            data.put(SECRET_JMX_USERNAME_KEY, currentSecret.getData().computeIfAbsent(SECRET_JMX_USERNAME_KEY, (key) -> Util.encodeToBase64(passwordGenerator.generate())));
            data.put(SECRET_JMX_PASSWORD_KEY, currentSecret.getData().computeIfAbsent(SECRET_JMX_PASSWORD_KEY, (key) -> Util.encodeToBase64(passwordGenerator.generate())));
        } else {
            data.put(SECRET_JMX_USERNAME_KEY, Util.encodeToBase64(passwordGenerator.generate()));
            data.put(SECRET_JMX_PASSWORD_KEY, Util.encodeToBase64(passwordGenerator.generate()));
        }
        return createJmxSecret(KafkaResources.kafkaJmxSecretName(cluster), data);
    } else {
        return null;
    }
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) ExternalTrafficPolicy(io.strimzi.api.kafka.model.template.ExternalTrafficPolicy) KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) KafkaExporterResources(io.strimzi.api.kafka.model.KafkaExporterResources) Storage(io.strimzi.api.kafka.model.storage.Storage) HTTPIngressPath(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath) Rack(io.strimzi.api.kafka.model.Rack) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) Annotations(io.strimzi.operator.common.Annotations) IngressTLS(io.fabric8.kubernetes.api.model.networking.v1.IngressTLS) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) Collections.singletonList(java.util.Collections.singletonList) NetworkPolicyIngressRule(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRule) Route(io.fabric8.openshift.api.model.Route) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) IngressTLSBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder) KafkaClusterTemplate(io.strimzi.api.kafka.model.template.KafkaClusterTemplate) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) JsonObject(io.vertx.core.json.JsonObject) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) KafkaSpec(io.strimzi.api.kafka.model.KafkaSpec) Affinity(io.fabric8.kubernetes.api.model.Affinity) IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) ProbeBuilder(io.strimzi.api.kafka.model.ProbeBuilder) Probe(io.strimzi.api.kafka.model.Probe) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) ListenersUtils.isListenerWithOAuth(io.strimzi.operator.cluster.model.ListenersUtils.isListenerWithOAuth) Set(java.util.Set) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Collections.addAll(java.util.Collections.addAll) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Secret(io.fabric8.kubernetes.api.model.Secret) NetworkPolicyPeerBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeerBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Uuid(org.apache.kafka.common.Uuid) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) Container(io.fabric8.kubernetes.api.model.Container) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) CertAndKey(io.strimzi.certs.CertAndKey) Function(java.util.function.Function) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) KafkaAuthorization(io.strimzi.api.kafka.model.KafkaAuthorization) InlineLogging(io.strimzi.api.kafka.model.InlineLogging) ListenersUtils.isListenerWithCustomAuth(io.strimzi.operator.cluster.model.ListenersUtils.isListenerWithCustomAuth) Collections.singletonMap(java.util.Collections.singletonMap) Service(io.fabric8.kubernetes.api.model.Service) NetworkPolicyBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyBuilder) KafkaSpecChecker(io.strimzi.operator.cluster.operator.resource.KafkaSpecChecker) Volume(io.fabric8.kubernetes.api.model.Volume) NetworkPolicyIngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRuleBuilder) CertAndKeySecretSource(io.strimzi.api.kafka.model.CertAndKeySecretSource) CruiseControlConfigurationParameters(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlConfigurationParameters) KafkaAuthorizationKeycloak(io.strimzi.api.kafka.model.KafkaAuthorizationKeycloak) KafkaListenerAuthenticationCustom(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationCustom) IOException(java.io.IOException) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) KafkaListenerAuthenticationOAuth(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuth) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) Logging(io.strimzi.api.kafka.model.Logging) Reconciliation(io.strimzi.operator.common.Reconciliation) JsonArray(io.vertx.core.json.JsonArray) IngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressRuleBuilder) Util(io.strimzi.operator.common.Util) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) NetworkPolicyPeer(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeer) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) Kafka(io.strimzi.api.kafka.model.Kafka) CRUISE_CONTROL_METRIC_REPORTER(io.strimzi.operator.cluster.model.CruiseControl.CRUISE_CONTROL_METRIC_REPORTER) HTTPIngressPathBuilder(io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder) Collections(java.util.Collections) HashMap(java.util.HashMap) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator)

Example 44 with PasswordGenerator

use of io.strimzi.operator.common.PasswordGenerator in project strimzi-kafka-operator by strimzi.

the class KafkaConnectCluster method generateJmxSecret.

/**
 * Generate the Secret containing the username and password to secure the jmx port on the kafka connect workers
 *
 * @return The generated Secret
 */
public Secret generateJmxSecret() {
    Map<String, String> data = new HashMap<>(2);
    String[] keys = { SECRET_JMX_USERNAME_KEY, SECRET_JMX_PASSWORD_KEY };
    PasswordGenerator passwordGenerator = new PasswordGenerator(16);
    for (String key : keys) {
        data.put(key, Base64.getEncoder().encodeToString(passwordGenerator.generate().getBytes(StandardCharsets.US_ASCII)));
    }
    return createJmxSecret(KafkaConnectCluster.jmxSecretName(cluster), data);
}
Also used : HashMap(java.util.HashMap) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator)

Example 45 with PasswordGenerator

use of io.strimzi.operator.common.PasswordGenerator in project strimzi-kafka-operator by strimzi.

the class ZookeeperCluster method generateJmxSecret.

/**
 * Generate the Secret containing the username and password to secure the jmx port on the zookeeper nodes
 *
 * @param currentSecret The existing Secret with the current JMX credentials. Null if no secret exists yet.
 *
 * @return The generated Secret
 */
public Secret generateJmxSecret(Secret currentSecret) {
    if (isJmxAuthenticated) {
        PasswordGenerator passwordGenerator = new PasswordGenerator(16);
        Map<String, String> data = new HashMap<>(2);
        if (currentSecret != null && currentSecret.getData() != null) {
            data.put(SECRET_JMX_USERNAME_KEY, currentSecret.getData().computeIfAbsent(SECRET_JMX_USERNAME_KEY, (key) -> Util.encodeToBase64(passwordGenerator.generate())));
            data.put(SECRET_JMX_PASSWORD_KEY, currentSecret.getData().computeIfAbsent(SECRET_JMX_PASSWORD_KEY, (key) -> Util.encodeToBase64(passwordGenerator.generate())));
        } else {
            data.put(SECRET_JMX_USERNAME_KEY, Util.encodeToBase64(passwordGenerator.generate()));
            data.put(SECRET_JMX_PASSWORD_KEY, Util.encodeToBase64(passwordGenerator.generate()));
        }
        return createJmxSecret(KafkaResources.zookeeperJmxSecretName(cluster), data);
    } else {
        return null;
    }
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Storage(io.strimzi.api.kafka.model.storage.Storage) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) KafkaJmxAuthenticationPassword(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword) NetworkPolicyIngressRule(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRule) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) ProbeBuilder(io.strimzi.api.kafka.model.ProbeBuilder) Probe(io.strimzi.api.kafka.model.Probe) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Secret(io.fabric8.kubernetes.api.model.Secret) Condition(io.strimzi.api.kafka.model.status.Condition) ZookeeperClusterTemplate(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplate) ZookeeperClusterSpec(io.strimzi.api.kafka.model.ZookeeperClusterSpec) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) CertAndKey(io.strimzi.certs.CertAndKey) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) ArrayList(java.util.ArrayList) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) NetworkPolicyPort(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPort) InlineLogging(io.strimzi.api.kafka.model.InlineLogging) Service(io.fabric8.kubernetes.api.model.Service) NetworkPolicyBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyBuilder) Volume(io.fabric8.kubernetes.api.model.Volume) NetworkPolicyIngressRuleBuilder(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRuleBuilder) IOException(java.io.IOException) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) Logging(io.strimzi.api.kafka.model.Logging) Reconciliation(io.strimzi.operator.common.Reconciliation) Util(io.strimzi.operator.common.Util) NetworkPolicyPeer(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeer) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) Kafka(io.strimzi.api.kafka.model.Kafka) Collections(java.util.Collections) HashMap(java.util.HashMap) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Aggregations

PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)136 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)110 Reconciliation (io.strimzi.operator.common.Reconciliation)104 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)102 Future (io.vertx.core.Future)96 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)94 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)94 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)94 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)94 Mockito.when (org.mockito.Mockito.when)94 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)92 KubernetesVersion (io.strimzi.operator.KubernetesVersion)90 Vertx (io.vertx.core.Vertx)90 CoreMatchers.is (org.hamcrest.CoreMatchers.is)88 AfterAll (org.junit.jupiter.api.AfterAll)88 BeforeAll (org.junit.jupiter.api.BeforeAll)88 Test (org.junit.jupiter.api.Test)86 ArgumentCaptor (org.mockito.ArgumentCaptor)86 MockCertManager (io.strimzi.operator.common.operator.MockCertManager)84 Checkpoint (io.vertx.junit5.Checkpoint)82