Skip to content

Commit 8275a14

Browse files
committed
address Jakub's comments
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
1 parent 663020c commit 8275a14

9 files changed

Lines changed: 36 additions & 33 deletions

File tree

api/src/main/java/io/strimzi/api/kafka/model/user/KafkaUserTlsClientAuthentication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public String getType() {
4747

4848
@Description(
4949
"Number of days for which the user certificate should be valid. " +
50+
"It has to be configured together with `renewalDays`, or none of them should be configured." +
51+
"The number should be bigger than 0 and than `renewalDays`." +
5052
"If not configured, Clients CA configuration is used."
5153
)
5254
@Minimum(1)
@@ -61,6 +63,8 @@ public void setValidityDays(Integer validityDays) {
6163

6264
@Description(
6365
"Number of days before certificate expiration when the user certificate should be renewed. " +
66+
"It has to be configured together with `validityDays`, or none of them should be configured." +
67+
"The number should be bigger than 0 and smaller than `validityDays`." +
6468
"If not configured, Clients CA configuration is used."
6569
)
6670
@Minimum(1)

development-docs/systemtests/io.strimzi.systemtest.operators.user.UserST.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
* [user-operator](labels/user-operator.md)
9898

9999

100-
## testTlsValidityDaysWithForceRenewal
100+
## testTlsValidityDays
101101

102102
**Description:** Verifies functionality of the mTLS `validityDays` and `renewalDays` configured inside each KafkaUser.
103103

@@ -106,12 +106,12 @@
106106
| Step | Action | Result |
107107
| - | - | - |
108108
| 1. | Create `KafkaTopic` to which we will send (and from which we will receive) messages - created in existing Kafka cluster. | `KafkaTopic` is created. |
109-
| 2. | Create `KafkaUser` with TLS authentication; together with default `validityDays` (200 days) and `renewalDays` (20 days) - configured in User operator. | `KafkaUser` is created with defaults. |
109+
| 2. | Create `KafkaUser` with TLS authentication; without configuring the `validityDays` and `renewalDays` - values from User Operator are taken. | `KafkaUser` is created with values from User Operator. |
110110
| 3. | Obtain the `KafkaUser`'s `Secret` and check validity period of the user certificate. | Validity period should be default - 200 days. |
111111
| 4. | Do message transmission to verify, that we are able to connect to Kafka cluster with the TLS `KafkaUser`. | Messages are successfully sent and received. |
112-
| 5. | Change the `validityDays` and `renewalDays` in the `KafkaUser` `.spec.authentication` to 60 and 10. | The `validityDays` and `renewalDays` should be changed in the `KafkaUser`. |
113-
| 6. | Because we changed the `validityDays` and `renewalDays`, we need to force renew the certificate using the `strimzi.io/force-renew=true` annotation | The user certificate was renewed. |
114-
| 7. | Obtain the `KafkaUser`'s `Secret` again and check the validity period of the user certificate. | Validity period should be 60 days. |
112+
| 5. | Change the `validityDays` and `renewalDays` in the `KafkaUser` `.spec.authentication` to 40 and 20. | The `validityDays` and `renewalDays` should be changed in the `KafkaUser`. |
113+
| 6. | Because of the change of `validityDays` and `renewalDays` (and because of the values inside), the certificate will be renewed | The user certificate was renewed. |
114+
| 7. | Obtain the `KafkaUser`'s `Secret` again and check the validity period of the user certificate. | Validity period should be 40 days. |
115115
| 8. | Do message transmission again to verify, that we are able to connect to Kafka cluster with the new user's certificate. | Messages are successfully sent and received using new certificate. |
116116

117117
**Labels:**

development-docs/systemtests/labels/user-operator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ They verify user authentication mechanisms (TLS, SCRAM-SHA-512, external TLS), a
1515
- [testTlsExternalUser](../io.strimzi.systemtest.operators.user.UserST.md)
1616
- [testTlsExternalUserWithQuotas](../io.strimzi.systemtest.operators.user.UserST.md)
1717
- [testTlsUserWithQuotas](../io.strimzi.systemtest.operators.user.UserST.md)
18-
- [testTlsValidityDaysWithForceRenewal](../io.strimzi.systemtest.operators.user.UserST.md)
18+
- [testTlsValidityDays](../io.strimzi.systemtest.operators.user.UserST.md)
1919
- [testUpdateUser](../io.strimzi.systemtest.operators.user.UserST.md)
2020
- [testUserWithNameMoreThan64Chars](../io.strimzi.systemtest.operators.user.UserST.md)
2121
- [testUserWithQuotas](../io.strimzi.systemtest.operators.user.UserST.md)

documentation/modules/appendix_crds.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,10 +2686,10 @@ It must have the value `tls` for the type `KafkaUserTlsClientAuthentication`.
26862686
|Must be `tls`.
26872687
|validityDays
26882688
|integer
2689-
|Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used.
2689+
|Number of days for which the user certificate should be valid. It has to be configured together with `renewalDays`, or none of them should be configured.The number should be bigger than 0 and than `renewalDays`.If not configured, Clients CA configuration is used.
26902690
|renewalDays
26912691
|integer
2692-
|Number of days before certificate expiration when the user certificate should be renewed. If not configured, Clients CA configuration is used.
2692+
|Number of days before certificate expiration when the user certificate should be renewed. It has to be configured together with `validityDays`, or none of them should be configured.The number should be bigger than 0 and smaller than `validityDays`.If not configured, Clients CA configuration is used.
26932693
|====
26942694

26952695
[id='type-KafkaUserTlsExternalClientAuthentication-{context}']

packaging/helm-charts/helm3/strimzi-kafka-operator/crds/044-Crd-kafkauser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ spec:
8484
renewalDays:
8585
type: integer
8686
minimum: 1
87-
description: "Number of days before certificate expiration when the user certificate should be renewed. If not configured, Clients CA configuration is used."
87+
description: "Number of days before certificate expiration when the user certificate should be renewed. It has to be configured together with `validityDays`, or none of them should be configured.The number should be bigger than 0 and smaller than `validityDays`.If not configured, Clients CA configuration is used."
8888
type:
8989
type: string
9090
enum:
@@ -95,7 +95,7 @@ spec:
9595
validityDays:
9696
type: integer
9797
minimum: 1
98-
description: "Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used."
98+
description: "Number of days for which the user certificate should be valid. It has to be configured together with `renewalDays`, or none of them should be configured.The number should be bigger than 0 and than `renewalDays`.If not configured, Clients CA configuration is used."
9999
required:
100100
- type
101101
description: "Authentication mechanism enabled for this Kafka user. The supported authentication mechanisms are `scram-sha-512`, `tls`, and `tls-external`. \n\n* `scram-sha-512` generates a secret with SASL SCRAM-SHA-512 credentials.\n* `tls` generates a secret with user certificate for mutual TLS authentication.\n* `tls-external` does not generate a user certificate. But prepares the user for using mutual TLS authentication using a user certificate generated outside the User Operator.\n ACLs and quotas set for this user are configured in the `CN=<username>` format.\n\nAuthentication is optional. If authentication is not configured, no credentials are generated. ACLs and quotas set for the user are configured in the `<username>` format suitable for SASL authentication."

packaging/install/cluster-operator/044-Crd-kafkauser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ spec:
8383
renewalDays:
8484
type: integer
8585
minimum: 1
86-
description: "Number of days before certificate expiration when the user certificate should be renewed. If not configured, Clients CA configuration is used."
86+
description: "Number of days before certificate expiration when the user certificate should be renewed. It has to be configured together with `validityDays`, or none of them should be configured.The number should be bigger than 0 and smaller than `validityDays`.If not configured, Clients CA configuration is used."
8787
type:
8888
type: string
8989
enum:
@@ -94,7 +94,7 @@ spec:
9494
validityDays:
9595
type: integer
9696
minimum: 1
97-
description: "Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used."
97+
description: "Number of days for which the user certificate should be valid. It has to be configured together with `renewalDays`, or none of them should be configured.The number should be bigger than 0 and than `renewalDays`.If not configured, Clients CA configuration is used."
9898
required:
9999
- type
100100
description: "Authentication mechanism enabled for this Kafka user. The supported authentication mechanisms are `scram-sha-512`, `tls`, and `tls-external`. \n\n* `scram-sha-512` generates a secret with SASL SCRAM-SHA-512 credentials.\n* `tls` generates a secret with user certificate for mutual TLS authentication.\n* `tls-external` does not generate a user certificate. But prepares the user for using mutual TLS authentication using a user certificate generated outside the User Operator.\n ACLs and quotas set for this user are configured in the `CN=<username>` format.\n\nAuthentication is optional. If authentication is not configured, no credentials are generated. ACLs and quotas set for the user are configured in the `<username>` format suitable for SASL authentication."

packaging/install/user-operator/04-Crd-kafkauser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ spec:
8383
renewalDays:
8484
type: integer
8585
minimum: 1
86-
description: "Number of days before certificate expiration when the user certificate should be renewed. If not configured, Clients CA configuration is used."
86+
description: "Number of days before certificate expiration when the user certificate should be renewed. It has to be configured together with `validityDays`, or none of them should be configured.The number should be bigger than 0 and smaller than `validityDays`.If not configured, Clients CA configuration is used."
8787
type:
8888
type: string
8989
enum:
@@ -94,7 +94,7 @@ spec:
9494
validityDays:
9595
type: integer
9696
minimum: 1
97-
description: "Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used."
97+
description: "Number of days for which the user certificate should be valid. It has to be configured together with `renewalDays`, or none of them should be configured.The number should be bigger than 0 and than `renewalDays`.If not configured, Clients CA configuration is used."
9898
required:
9999
- type
100100
description: "Authentication mechanism enabled for this Kafka user. The supported authentication mechanisms are `scram-sha-512`, `tls`, and `tls-external`. \n\n* `scram-sha-512` generates a secret with SASL SCRAM-SHA-512 credentials.\n* `tls` generates a secret with user certificate for mutual TLS authentication.\n* `tls-external` does not generate a user certificate. But prepares the user for using mutual TLS authentication using a user certificate generated outside the User Operator.\n ACLs and quotas set for this user are configured in the `CN=<username>` format.\n\nAuthentication is optional. If authentication is not configured, no credentials are generated. ACLs and quotas set for the user are configured in the `<username>` format suitable for SASL authentication."

systemtest/src/test/java/io/strimzi/systemtest/operators/user/UserST.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class UserST extends AbstractST {
8787

8888
private TestStorage sharedTestStorage;
8989
private String scraperPodName = "";
90-
private final int defaultValidityDays = 200;
91-
private final int defaultRenewalDays = 20;
90+
private final int caValidityDays = 10;
91+
private final int caRenewalDays = 5;
9292

9393
@TestDoc(
9494
description = @Desc("Verifies that Kafka users with names longer than 64 characters are rejected, while users with valid names are accepted."),
@@ -572,24 +572,23 @@ void testTlsExternalUser() {
572572
description = @Desc("Verifies functionality of the mTLS `validityDays` and `renewalDays` configured inside each KafkaUser."),
573573
steps = {
574574
@Step(value = "Create `KafkaTopic` to which we will send (and from which we will receive) messages - created in existing Kafka cluster.", expected = "`KafkaTopic` is created."),
575-
@Step(value = "Create `KafkaUser` with TLS authentication; together with default `validityDays` (200 days) and `renewalDays` (20 days) - configured in User operator.", expected = "`KafkaUser` is created with defaults."),
575+
@Step(value = "Create `KafkaUser` with TLS authentication; without configuring the `validityDays` and `renewalDays` - values from User Operator are taken.", expected = "`KafkaUser` is created with values from User Operator."),
576576
@Step(value = "Obtain the `KafkaUser`'s `Secret` and check validity period of the user certificate.", expected = "Validity period should be default - 200 days."),
577577
@Step(value = "Do message transmission to verify, that we are able to connect to Kafka cluster with the TLS `KafkaUser`.", expected = "Messages are successfully sent and received."),
578-
@Step(value = "Change the `validityDays` and `renewalDays` in the `KafkaUser` `.spec.authentication` to 60 and 10.", expected = "The `validityDays` and `renewalDays` should be changed in the `KafkaUser`."),
579-
@Step(value = "Because we changed the `validityDays` and `renewalDays`, we need to force renew the certificate using the `strimzi.io/force-renew=true` annotation",
580-
expected = "The user certificate was renewed."),
581-
@Step(value = "Obtain the `KafkaUser`'s `Secret` again and check the validity period of the user certificate.", expected = "Validity period should be 60 days."),
578+
@Step(value = "Change the `validityDays` and `renewalDays` in the `KafkaUser` `.spec.authentication` to 40 and 20.", expected = "The `validityDays` and `renewalDays` should be changed in the `KafkaUser`."),
579+
@Step(value = "Because of the change of `validityDays` and `renewalDays` (and because of the values inside), the certificate will be renewed", expected = "The user certificate was renewed."),
580+
@Step(value = "Obtain the `KafkaUser`'s `Secret` again and check the validity period of the user certificate.", expected = "Validity period should be 40 days."),
582581
@Step(value = "Do message transmission again to verify, that we are able to connect to Kafka cluster with the new user's certificate.", expected = "Messages are successfully sent and received using new certificate."),
583582
},
584583
labels = {
585584
@Label(TestDocsLabels.USER_OPERATOR)
586585
}
587586
)
588587
@ParallelTest
589-
void testTlsValidityDaysWithForceRenewal() {
588+
void testTlsValidityDays() {
590589
final TestStorage testStorage = new TestStorage(KubeResourceManager.get().getTestContext());
591-
final int newValidityDays = 60;
592-
final int newRenewalDays = 10;
590+
final int newValidityDays = 40;
591+
final int newRenewalDays = 20;
593592

594593
KubeResourceManager.get().createResourceWithWait(KafkaTopicTemplates.topic(testStorage.getNamespaceName(), testStorage.getTopicName(), sharedTestStorage.getClusterName()).build());
595594

@@ -600,7 +599,7 @@ void testTlsValidityDaysWithForceRenewal() {
600599
String userCertificate = tlsUserSecret.getData().get("user.crt");
601600

602601
// check that notBefore and notAfter contains really the default value of validityDays
603-
assertThat("validity period of the certificate has incorrect value", KafkaUserUtils.getValidityDaysOfCertificate(userCertificate), is(defaultValidityDays));
602+
assertThat("validity period of the certificate has incorrect value", KafkaUserUtils.getValidityDaysOfCertificate(userCertificate), is(caValidityDays));
604603

605604
LOGGER.info("Produce and consume messages before changing the validity - in order to see that everything works as expected.");
606605
final KafkaProducerConsumer kafkaProducerConsumer = new KafkaProducerConsumerBuilder()
@@ -677,8 +676,8 @@ void setup() {
677676
)
678677
.endKafka()
679678
.withNewClientsCa()
680-
.withValidityDays(defaultValidityDays)
681-
.withRenewalDays(defaultRenewalDays)
679+
.withValidityDays(caValidityDays)
680+
.withRenewalDays(caRenewalDays)
682681
.endClientsCa()
683682
.endSpec()
684683
.build(),

user-operator/src/main/java/io/strimzi/operator/user/model/KafkaUserModel.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,24 @@ public Secret generateSecret(boolean generatePkcs12Stores) {
221221
* @param clientsCaCertSecret The clients CA certificate Secret.
222222
* @param clientsCaKeySecret The clients CA key Secret.
223223
* @param userSecret Secret with the user certificate
224-
* @param defaultValidityDays The default number of days (configured in Clients CA) the certificate should be valid for.
225-
* @param defaultRenewalDays The default renewal days (configured in Clients CA).
224+
* @param caValidityDays The default number of days (configured in Clients CA) the certificate should be valid for.
225+
* @param caRenewalDays The default renewal days (configured in Clients CA).
226226
* @param maintenanceWindows List of configured maintenance windows
227227
* @param clock The clock for supplying the reconciler with the time instant of each reconciliation cycle.
228228
* That time is used for checking maintenance windows
229229
* @param generatePkcs12Stores Flag indicating whether PKCS12 keystores should be generated for the user certificates
230230
*/
231231
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
232232
public void maybeGenerateCertificates(Reconciliation reconciliation, CertManager certManager, PasswordGenerator passwordGenerator,
233-
Secret clientsCaCertSecret, Secret clientsCaKeySecret, Secret userSecret, int defaultValidityDays,
234-
int defaultRenewalDays, List<String> maintenanceWindows, Clock clock, boolean generatePkcs12Stores) {
233+
Secret clientsCaCertSecret, Secret clientsCaKeySecret, Secret userSecret, int caValidityDays,
234+
int caRenewalDays, List<String> maintenanceWindows, Clock clock, boolean generatePkcs12Stores) {
235235
// in case that validityDays and renewalDays are configured inside the authentication part of KafkaUser,
236236
// use those instead of default Clients CA configuration
237237
// we are checking it here as we have all needed information about the KafkaUser configuration and also default configuration of Clients CA
238238
KafkaUserTlsClientAuthentication kafkaUserTlsClientAuthentication = (KafkaUserTlsClientAuthentication) authentication;
239239

240-
int validityDays = kafkaUserTlsClientAuthentication.getValidityDays() != null ? kafkaUserTlsClientAuthentication.getValidityDays() : defaultValidityDays;
241-
int renewalDays = kafkaUserTlsClientAuthentication.getRenewalDays() != null ? kafkaUserTlsClientAuthentication.getRenewalDays() : defaultRenewalDays;
240+
int validityDays = kafkaUserTlsClientAuthentication.getValidityDays() != null ? kafkaUserTlsClientAuthentication.getValidityDays() : caValidityDays;
241+
int renewalDays = kafkaUserTlsClientAuthentication.getRenewalDays() != null ? kafkaUserTlsClientAuthentication.getRenewalDays() : caRenewalDays;
242242
validateCACertificates(clientsCaCertSecret, clientsCaKeySecret);
243243

244244
ClientsCa clientsCa = new ClientsCa(

0 commit comments

Comments
 (0)