Search in sources :

Example 16 with OpenSslCertManager

use of io.strimzi.certs.OpenSslCertManager in project strimzi by strimzi.

the class CruiseControlReconcilerTest method reconcileEnabledCruiseControl.

@Test
public void reconcileEnabledCruiseControl(VertxTestContext context) {
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    DeploymentOperator mockDepOps = supplier.deploymentOperations;
    SecretOperator mockSecretOps = supplier.secretOperations;
    ServiceAccountOperator mockSaOps = supplier.serviceAccountOperations;
    ServiceOperator mockServiceOps = supplier.serviceOperations;
    NetworkPolicyOperator mockNetPolicyOps = supplier.networkPolicyOperator;
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    ArgumentCaptor<ServiceAccount> saCaptor = ArgumentCaptor.forClass(ServiceAccount.class);
    when(mockSaOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.serviceAccountName(NAME)), saCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<Secret> secretCaptor = ArgumentCaptor.forClass(Secret.class);
    when(mockSecretOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.secretName(NAME)), secretCaptor.capture())).thenReturn(Future.succeededFuture());
    when(mockSecretOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.apiSecretName(NAME)), secretCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
    when(mockServiceOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.serviceName(NAME)), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<NetworkPolicy> netPolicyCaptor = ArgumentCaptor.forClass(NetworkPolicy.class);
    when(mockNetPolicyOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.networkPolicyName(NAME)), netPolicyCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<ConfigMap> cmCaptor = ArgumentCaptor.forClass(ConfigMap.class);
    when(mockCmOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.logAndMetricsConfigMapName(NAME)), cmCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<Deployment> depCaptor = ArgumentCaptor.forClass(Deployment.class);
    when(mockDepOps.reconcile(any(), eq(NAMESPACE), eq(CruiseControlResources.deploymentName(NAME)), depCaptor.capture())).thenReturn(Future.succeededFuture());
    when(mockDepOps.waitForObserved(any(), eq(NAMESPACE), eq(CruiseControlResources.deploymentName(NAME)), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(mockDepOps.readiness(any(), eq(NAMESPACE), eq(CruiseControlResources.deploymentName(NAME)), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    Kafka kafka = new KafkaBuilder(ResourceUtils.createKafka(NAMESPACE, NAME, 3, "foo", 120, 30)).editSpec().withCruiseControl(cruiseControlSpec).endSpec().build();
    ClusterCa clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(), new PasswordGenerator(10, "a", "a"), NAME, ResourceUtils.createInitialCaCertSecret(NAMESPACE, NAME, AbstractModel.clusterCaCertSecretName(NAME), MockCertManager.clusterCaCert(), MockCertManager.clusterCaCertStore(), "123456"), ResourceUtils.createInitialCaKeySecret(NAMESPACE, NAME, AbstractModel.clusterCaKeySecretName(NAME), MockCertManager.clusterCaKey()));
    CruiseControlReconciler rcnclr = new CruiseControlReconciler(Reconciliation.DUMMY_RECONCILIATION, ResourceUtils.dummyClusterOperatorConfig(), supplier, kafka, VERSIONS, kafka.getSpec().getKafka().getStorage(), clusterCa);
    Checkpoint async = context.checkpoint();
    rcnclr.reconcile(false, null, null, Date::new).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(saCaptor.getAllValues().size(), is(1));
        assertThat(saCaptor.getValue(), is(notNullValue()));
        assertThat(secretCaptor.getAllValues().size(), is(2));
        assertThat(secretCaptor.getAllValues().get(0), is(notNullValue()));
        assertThat(secretCaptor.getAllValues().get(1), is(notNullValue()));
        assertThat(serviceCaptor.getAllValues().size(), is(1));
        assertThat(serviceCaptor.getValue(), is(notNullValue()));
        assertThat(netPolicyCaptor.getAllValues().size(), is(1));
        assertThat(netPolicyCaptor.getValue(), is(notNullValue()));
        assertThat(cmCaptor.getAllValues().size(), is(1));
        assertThat(cmCaptor.getValue(), is(notNullValue()));
        assertThat(depCaptor.getAllValues().size(), is(1));
        assertThat(depCaptor.getValue(), is(notNullValue()));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BrokerCapacityBuilder(io.strimzi.api.kafka.model.balancing.BrokerCapacityBuilder) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) NetworkPolicyOperator(io.strimzi.operator.common.operator.resource.NetworkPolicyOperator) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) ArgumentCaptor(org.mockito.ArgumentCaptor) ServiceAccountOperator(io.strimzi.operator.common.operator.resource.ServiceAccountOperator) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Service(io.fabric8.kubernetes.api.model.Service) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Secret(io.fabric8.kubernetes.api.model.Secret) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) Checkpoint(io.vertx.junit5.Checkpoint) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Kafka(io.strimzi.api.kafka.model.Kafka) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Kafka(io.strimzi.api.kafka.model.Kafka) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) NetworkPolicyOperator(io.strimzi.operator.common.operator.resource.NetworkPolicyOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) Service(io.fabric8.kubernetes.api.model.Service) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Secret(io.fabric8.kubernetes.api.model.Secret) OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) Checkpoint(io.vertx.junit5.Checkpoint) ServiceAccountOperator(io.strimzi.operator.common.operator.resource.ServiceAccountOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) Test(org.junit.jupiter.api.Test)

Example 17 with OpenSslCertManager

use of io.strimzi.certs.OpenSslCertManager in project strimzi by strimzi.

the class ZookeeperClusterTest method generateCertificatesSecret.

private Secret generateCertificatesSecret() {
    ClusterCa clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(), new PasswordGenerator(10, "a", "a"), cluster, null, null);
    clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), emptyMap(), emptyMap(), null, true);
    return zc.generateCertificatesSecret(clusterCa, true);
}
Also used : OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator)

Example 18 with OpenSslCertManager

use of io.strimzi.certs.OpenSslCertManager in project strimzi-kafka-operator by strimzi.

the class ClusterCaTest method testIsExpiringCertificate.

@ParallelTest
public void testIsExpiringCertificate() {
    // simulate certificate creation at following time, with expire at 365 days later (by default) and renewal days at 30 (by default)
    String instantExpected = "2022-03-30T09:00:00Z";
    Clock clock = Clock.fixed(Instant.parse(instantExpected), UTC);
    ClusterCa clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(clock), new PasswordGenerator(10, "a", "a"), cluster, null, null);
    clusterCa.setClock(clock);
    clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), emptyMap(), emptyMap(), null, true);
    // check certificate expiration out of the renewal period, certificate is not expiring
    instantExpected = "2023-02-15T09:00:00Z";
    clock = Clock.fixed(Instant.parse(instantExpected), UTC);
    clusterCa.setClock(clock);
    assertThat(clusterCa.isExpiring(clusterCa.caCertSecret(), Ca.CA_CRT), is(false));
    // check certificate expiration within the renewal period, certificate is expiring
    instantExpected = "2023-03-15T09:00:00Z";
    clock = Clock.fixed(Instant.parse(instantExpected), UTC);
    clusterCa.setClock(clock);
    assertThat(clusterCa.isExpiring(clusterCa.caCertSecret(), Ca.CA_CRT), is(true));
}
Also used : OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Clock(java.time.Clock) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 19 with OpenSslCertManager

use of io.strimzi.certs.OpenSslCertManager in project strimzi-kafka-operator by strimzi.

the class ClusterCaTest method testRemoveOldCertificate.

@ParallelTest
public void testRemoveOldCertificate() {
    // simulate certificate creation at following time, with expire at 365 days later (by default)
    String instantExpected = "2022-03-23T09:00:00Z";
    Clock clock = Clock.fixed(Instant.parse(instantExpected), UTC);
    ClusterCa clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(clock), new PasswordGenerator(10, "a", "a"), cluster, null, null);
    clusterCa.setClock(clock);
    clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), emptyMap(), emptyMap(), null, true);
    assertThat(clusterCa.caCertSecret().getData().size(), is(3));
    // force key replacement so certificate renewal ...
    Secret caKeySecretWithReplaceAnno = new SecretBuilder(clusterCa.caKeySecret()).editMetadata().addToAnnotations(Ca.ANNO_STRIMZI_IO_FORCE_REPLACE, "true").endMetadata().build();
    // ... simulated at the following time, with expire at 365 days later (by default)
    instantExpected = "2022-03-23T11:00:00Z";
    clock = Clock.fixed(Instant.parse(instantExpected), UTC);
    clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(clock), new PasswordGenerator(10, "a", "a"), cluster, clusterCa.caCertSecret(), caKeySecretWithReplaceAnno);
    clusterCa.setClock(clock);
    clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), emptyMap(), emptyMap(), null, true);
    assertThat(clusterCa.caCertSecret().getData().size(), is(4));
    assertThat(clusterCa.caCertSecret().getData().containsKey("ca-2023-03-23T09-00-00Z.crt"), is(true));
    clusterCa.maybeDeleteOldCerts();
    assertThat(clusterCa.caCertSecret().getData().size(), is(3));
    assertThat(clusterCa.caCertSecret().getData().containsKey("ca-2023-03-23T09-00-00Z.crt"), is(false));
}
Also used : OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Clock(java.time.Clock) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 20 with OpenSslCertManager

use of io.strimzi.certs.OpenSslCertManager in project strimzi-kafka-operator by strimzi.

the class ZookeeperClusterTest method generateCertificatesSecret.

private Secret generateCertificatesSecret() {
    ClusterCa clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(), new PasswordGenerator(10, "a", "a"), cluster, null, null);
    clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), emptyMap(), emptyMap(), null, true);
    return zc.generateCertificatesSecret(clusterCa, true);
}
Also used : OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator)

Aggregations

OpenSslCertManager (io.strimzi.certs.OpenSslCertManager)22 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)20 Secret (io.fabric8.kubernetes.api.model.Secret)10 ParallelTest (io.strimzi.test.annotations.ParallelTest)8 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)6 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)6 SecretOperator (io.strimzi.operator.common.operator.resource.SecretOperator)6 Future (io.vertx.core.Future)6 Clock (java.time.Clock)5 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 Service (io.fabric8.kubernetes.api.model.Service)4 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 NetworkPolicy (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy)4 CruiseControlResources (io.strimzi.api.kafka.model.CruiseControlResources)4 CruiseControlSpec (io.strimzi.api.kafka.model.CruiseControlSpec)4 CruiseControlSpecBuilder (io.strimzi.api.kafka.model.CruiseControlSpecBuilder)4 Kafka (io.strimzi.api.kafka.model.Kafka)4 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)4 BrokerCapacityBuilder (io.strimzi.api.kafka.model.balancing.BrokerCapacityBuilder)4