Skip to content

Commit 16e3c12

Browse files
committed
update API docs and add ST for this change
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
1 parent fcebdcf commit 16e3c12

13 files changed

Lines changed: 155 additions & 21 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public String getType() {
4242
})
4343
@Description(
4444
"Number of days for which the user certificate should be valid. " +
45-
"If not configured, default User Operator value is used."
45+
"If not configured, default User Operator value is used. " +
46+
"If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, " +
47+
"the certificate is immediately renewed, without waiting for maintenance window. "
4648
)
4749
@JsonInclude(value = JsonInclude.Include.NON_NULL)
4850
public Integer getValidityDays() {
@@ -61,7 +63,7 @@ public void setValidityDays(Integer validityDays) {
6163
})
6264
@Description(
6365
"Configures how many days before the certificate expiration should be the user certificate renewed. " +
64-
"If not configured, default User Operator value is used."
66+
"If not configured, default User Operator value is used."
6567
)
6668
@JsonInclude(value = JsonInclude.Include.NON_NULL)
6769
public Integer getRenewalDays() {

api/src/test/resources/crds/v1/044-Crd-kafkauser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ spec:
9595
description: Authentication type.
9696
validityDays:
9797
type: integer
98-
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used."
98+
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used. If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, the certificate is immediately renewed, without waiting for maintenance window. "
9999
x-kubernetes-validations:
100100
- rule: self > 0
101101
message: '''validityDays'' has to be higher than 0.'

api/src/test/resources/crds/v1beta2/044-Crd-kafkauser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ spec:
9595
description: Authentication type.
9696
validityDays:
9797
type: integer
98-
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used."
98+
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used. If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, the certificate is immediately renewed, without waiting for maintenance window. "
9999
x-kubernetes-validations:
100100
- rule: self > 0
101101
message: '''validityDays'' has to be higher than 0.'

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

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

9999

100+
## testTlsValidityDays
101+
102+
**Description:** Verifies functionality of the mTLS `validityDays` and `renewalDays` configured inside each KafkaUser.
103+
104+
**Steps:**
105+
106+
| Step | Action | Result |
107+
| - | - | - |
108+
| 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. |
110+
| 3. | Obtain the `KafkaUser`'s `Secret` and check validity period of the user certificate. | Validity period should be default - 200 days. |
111+
| 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 the current certificate would exceed the new validity period, `KafkaUser`'s `Secret` and user certificate should be renewed - we are waiting for the certificate change. | The user certificate was changed. |
114+
| 7. | Obtain the `KafkaUser`'s `Secret` again and check the validity period of the user certificate. | Validity period should be 60 days. |
115+
| 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. |
116+
117+
**Labels:**
118+
119+
* [user-operator](labels/user-operator.md)
120+
121+
100122
## testUpdateUser
101123

102124
**Description:** Verifies updating a Kafka user from TLS to SCRAM-SHA-512 authentication and validates user secret contents.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +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+
- [testTlsValidityDays](../io.strimzi.systemtest.operators.user.UserST.md)
1819
- [testUpdateUser](../io.strimzi.systemtest.operators.user.UserST.md)
1920
- [testUserWithNameMoreThan64Chars](../io.strimzi.systemtest.operators.user.UserST.md)
2021
- [testUserWithQuotas](../io.strimzi.systemtest.operators.user.UserST.md)

documentation/modules/appendix_crds.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ It must have the value `tls` for the type `KafkaUserTlsClientAuthentication`.
26772677
|Must be `tls`.
26782678
|validityDays
26792679
|integer
2680-
|Number of days for which the user certificate should be valid. If not configured, default User Operator value is used.
2680+
|Number of days for which the user certificate should be valid. If not configured, default User Operator value is used. If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, the certificate is immediately renewed, without waiting for maintenance window.
26812681
|renewalDays
26822682
|integer
26832683
|Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, default User Operator value is used.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ spec:
9696
description: Authentication type.
9797
validityDays:
9898
type: integer
99-
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used."
99+
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used. If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, the certificate is immediately renewed, without waiting for maintenance window. "
100100
x-kubernetes-validations:
101101
- rule: self > 0
102102
message: '''validityDays'' has to be higher than 0.'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ spec:
9595
description: Authentication type.
9696
validityDays:
9797
type: integer
98-
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used."
98+
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used. If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, the certificate is immediately renewed, without waiting for maintenance window. "
9999
x-kubernetes-validations:
100100
- rule: self > 0
101101
message: '''validityDays'' has to be higher than 0.'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ spec:
9595
description: Authentication type.
9696
validityDays:
9797
type: integer
98-
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used."
98+
description: "Number of days for which the user certificate should be valid. If not configured, default User Operator value is used. If new validity policy would make the current certificate expired or current certificate's validity period would exceed new policy, the certificate is immediately renewed, without waiting for maintenance window. "
9999
x-kubernetes-validations:
100100
- rule: self > 0
101101
message: '''validityDays'' has to be higher than 0.'

systemtest/src/main/java/io/strimzi/systemtest/utils/kafkaUtils/KafkaUserUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.strimzi.api.kafka.model.user.KafkaUser;
1616
import io.strimzi.api.kafka.model.user.KafkaUserScramSha512ClientAuthenticationBuilder;
1717
import io.strimzi.api.kafka.model.user.KafkaUserSpec;
18+
import io.strimzi.operator.common.Util;
1819
import io.strimzi.systemtest.TestConstants;
1920
import io.strimzi.systemtest.resources.ResourceConditions;
2021
import io.strimzi.systemtest.resources.ResourceOperation;
@@ -23,8 +24,13 @@
2324
import org.apache.logging.log4j.LogManager;
2425
import org.apache.logging.log4j.Logger;
2526

27+
import java.io.ByteArrayInputStream;
2628
import java.io.File;
2729
import java.io.IOException;
30+
import java.security.cert.CertificateException;
31+
import java.security.cert.CertificateFactory;
32+
import java.security.cert.X509Certificate;
33+
import java.time.temporal.ChronoUnit;
2834
import java.util.List;
2935
import java.util.Random;
3036
import java.util.function.Consumer;
@@ -255,4 +261,17 @@ public static void waitForUserWithPrefixDeletion(String namespaceName, String us
255261
}
256262
});
257263
}
264+
265+
public static int getValidityDaysOfCertificate(String certificate) {
266+
try {
267+
byte[] certBytes = Util.decodeFromBase64(certificate).getBytes();
268+
CertificateFactory cf = CertificateFactory.getInstance("X.509");
269+
X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certBytes));
270+
271+
return (int) ChronoUnit.DAYS.between(cert.getNotBefore().toInstant(), cert.getNotAfter().toInstant());
272+
} catch (CertificateException e) {
273+
LOGGER.error("Failed to parse certificate due to: {}", e.getMessage());
274+
throw new RuntimeException(e);
275+
}
276+
}
258277
}

0 commit comments

Comments
 (0)