use of io.strimzi.operator.common.PasswordGenerator in project strimzi 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));
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class ClusterCaTest method testRemoveExpiredCertificate.
@ParallelTest
public void testRemoveExpiredCertificate() {
// 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));
// running a CA reconcile simulated at following time (365 days later) expecting expired certificate being removed
instantExpected = "2023-03-23T10:00:00Z";
clock = Clock.fixed(Instant.parse(instantExpected), UTC);
clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(), new PasswordGenerator(10, "a", "a"), cluster, clusterCa.caCertSecret(), clusterCa.caKeySecret());
clusterCa.setClock(clock);
clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), emptyMap(), emptyMap(), null, true);
assertThat(clusterCa.caCertSecret().getData().size(), is(3));
assertThat(clusterCa.caCertSecret().getData().containsKey("ca-2023-03-23T09-00-00Z.crt"), is(false));
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class CruiseControl method generateCruiseControlApiCredentials.
/**
* Creates Cruise Control API auth usernames, passwords, and credentials file
*
* @return Map containing Cruise Control API auth credentials
*/
public static Map<String, String> generateCruiseControlApiCredentials() {
PasswordGenerator passwordGenerator = new PasswordGenerator(16);
String apiAdminPassword = passwordGenerator.generate();
String apiUserPassword = passwordGenerator.generate();
/*
* Create Cruise Control API auth credentials file following Jetty's
* HashLoginService's file format: username: password [,rolename ...]
*/
String authCredentialsFile = API_ADMIN_NAME + ": " + apiAdminPassword + "," + API_ADMIN_ROLE + "\n" + API_USER_NAME + ": " + apiUserPassword + "," + API_USER_ROLE + "\n";
Map<String, String> data = new HashMap<>(3);
data.put(API_ADMIN_PASSWORD_KEY, Util.encodeToBase64(apiAdminPassword));
data.put(API_USER_PASSWORD_KEY, Util.encodeToBase64(apiUserPassword));
data.put(API_AUTH_FILE_KEY, Util.encodeToBase64(authCredentialsFile));
return data;
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockTest method init.
/*
* init is equivalent to a @BeforeEach method
* since this is a parameterized set, the tests params are only available at test start
* This must be called before each test
*/
private void init(Params params) {
setFields(params);
cluster = new KafkaBuilder().withNewMetadata().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(singletonMap("foo", "bar")).endMetadata().withNewSpec().withNewKafka().withReplicas(kafkaReplicas).withStorage(kafkaStorage).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()).withResources(resources).endKafka().withNewZookeeper().withReplicas(zkReplicas).withStorage(zkStorage).endZookeeper().withNewEntityOperator().withNewTopicOperator().endTopicOperator().withNewUserOperator().endUserOperator().endEntityOperator().endSpec().build();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(cluster).withStrimziPodSetCrd().withDeploymentController().withPodController().withStatefulSetController().withServiceController().build();
mockKube.start();
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, kubernetesVersion);
ResourceOperatorSupplier supplier = supplierWithMocks();
ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class KafkaAssemblyOperatorNonParametrizedTest method testDeleteClusterRoleBindings.
@Test
public void testDeleteClusterRoleBindings(VertxTestContext context) {
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
ClusterRoleBindingOperator mockCrbOps = supplier.clusterRoleBindingOperator;
ArgumentCaptor<ClusterRoleBinding> desiredCrb = ArgumentCaptor.forClass(ClusterRoleBinding.class);
when(mockCrbOps.reconcile(any(), eq(KafkaResources.initContainerClusterRoleBindingName(NAME, NAMESPACE)), desiredCrb.capture())).thenReturn(Future.succeededFuture());
KafkaAssemblyOperator op = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), certManager, passwordGenerator, supplier, ResourceUtils.dummyClusterOperatorConfig(1L));
Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
Checkpoint async = context.checkpoint();
op.delete(reconciliation).onComplete(context.succeeding(c -> context.verify(() -> {
assertThat(desiredCrb.getValue(), is(nullValue()));
Mockito.verify(mockCrbOps, times(1)).reconcile(any(), any(), any());
async.flag();
})));
}
Aggregations