Skip to content

Commit 74d9f79

Browse files
committed
Jakub's comments
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
1 parent 8fd3d8c commit 74d9f79

13 files changed

Lines changed: 126 additions & 274 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
@JsonPropertyOrder({"type", "validityDays", "renewalDays"})
2222
@EqualsAndHashCode(callSuper = true)
2323
@ToString(callSuper = true)
24+
@CelValidation(rules = {
25+
@CelValidation.CelValidationRule(
26+
rule = "has(self.renewalDays) == has(self.validityDays)",
27+
message = "Both 'validityDays' and 'renewalDays' must be set together, or both must be unset."
28+
),
29+
@CelValidation.CelValidationRule(
30+
rule = "!has(self.renewalDays) || !has(self.validityDays) || self.renewalDays < self.validityDays",
31+
message = "'renewalDays' must be less than 'validityDays'."
32+
)
33+
})
2434
public class KafkaUserTlsClientAuthentication extends KafkaUserAuthentication {
2535
public static final String TYPE_TLS = "tls";
2636

@@ -42,9 +52,7 @@ public String getType() {
4252
})
4353
@Description(
4454
"Number of days for which the user certificate should be valid. " +
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. "
55+
"If not configured, Clients CA configuration is used."
4856
)
4957
@JsonInclude(value = JsonInclude.Include.NON_NULL)
5058
public Integer getValidityDays() {
@@ -63,7 +71,7 @@ public void setValidityDays(Integer validityDays) {
6371
})
6472
@Description(
6573
"Configures how many days before the certificate expiration should be the user certificate renewed. " +
66-
"If not configured, default User Operator value is used."
74+
"If not configured, Clients CA configuration is used."
6775
)
6876
@JsonInclude(value = JsonInclude.Include.NON_NULL)
6977
public Integer getRenewalDays() {

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

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

9999

100-
## testTlsValidityDays
100+
## testTlsValidityDaysWithForceRenewal
101101

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

@@ -110,7 +110,7 @@
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. |
112112
| 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. |
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. |
114114
| 7. | Obtain the `KafkaUser`'s `Secret` again and check the validity period of the user certificate. | Validity period should be 60 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

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-
- [testTlsValidityDays](../io.strimzi.systemtest.operators.user.UserST.md)
18+
- [testTlsValidityDaysWithForceRenewal](../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
@@ -2680,10 +2680,10 @@ It must have the value `tls` for the type `KafkaUserTlsClientAuthentication`.
26802680
|Must be `tls`.
26812681
|validityDays
26822682
|integer
2683-
|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.
2683+
|Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used.
26842684
|renewalDays
26852685
|integer
2686-
|Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, default User Operator value is used.
2686+
|Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, Clients CA configuration is used.
26872687
|====
26882688

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

operator-common/src/main/java/io/strimzi/operator/common/model/Ca.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -536,41 +536,6 @@ public boolean isExpiring(Secret secret, String certKey) {
536536
return certNeedsRenewal(currentCert);
537537
}
538538

539-
/**
540-
* Checks if the validityDays configuration is different from previous state.
541-
* If yes, the method checks if the new configuration of validityDays would make the certificate expired
542-
* or if the current Certificate's validity period exceeds the new policy.
543-
*
544-
* @param secret Secret with the certificate
545-
* @param certKey Key under which is the certificate stored
546-
*
547-
* @return True if the certificate should be renewed due to new validity period. False otherwise.
548-
*/
549-
public boolean requiresImmediateRenewalDueToValidityChange(Secret secret, String certKey) {
550-
X509Certificate currentCert = cert(secret, certKey);
551-
552-
Instant notBefore = currentCert.getNotBefore().toInstant();
553-
Instant notAfter = currentCert.getNotAfter().toInstant();
554-
int currentValidityDays = (int) ChronoUnit.DAYS.between(notBefore, notAfter);
555-
556-
if (currentValidityDays != validityDays) {
557-
Instant wouldExpireUnderNewPolicy = notBefore.plus(validityDays, ChronoUnit.DAYS);
558-
559-
if (!this.clock.instant().isBefore(wouldExpireUnderNewPolicy)) {
560-
LOGGER.infoCr(reconciliation, "Certificate of Secret {}/{} would be expired under new validity policy, it will be renewed",
561-
secret.getMetadata().getNamespace(), secret.getMetadata().getName());
562-
return true;
563-
}
564-
if (currentValidityDays > validityDays) {
565-
LOGGER.infoCr(reconciliation, "Certificate's current validity period of Secret {}/{} exceeds new policy, it will be renewed",
566-
secret.getMetadata().getNamespace(), secret.getMetadata().getName());
567-
return true;
568-
}
569-
}
570-
571-
return false;
572-
}
573-
574539
/**
575540
* Returns whether the certificate is expiring or not
576541
*

operator-common/src/test/java/io/strimzi/operator/common/operator/MockCertManager.java

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
package io.strimzi.operator.common.operator;
66

77
import io.strimzi.certs.CertManager;
8-
import io.strimzi.certs.OpenSslCertManager;
98
import io.strimzi.certs.Subject;
10-
import io.strimzi.operator.common.Util;
119

1210
import java.io.ByteArrayOutputStream;
1311
import java.io.File;
@@ -78,9 +76,59 @@ public class MockCertManager implements CertManager {
7876
D0z+vgrfionoRhyWUDh7POlWwdUOWiBDBOFrkgeKNphSC0glYFN+2IW7
7977
-----END CERTIFICATE-----
8078
""";
81-
82-
private static final String CLIENTS_KEY;
83-
private static final String CLIENTS_CERT;
79+
private static final String CLIENTS_KEY = """
80+
-----BEGIN PRIVATE KEY-----
81+
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCWws5FEJOpfZ/s
82+
FJWYbYdJVxmZB+5PjCwA2TUZxF/3P4w/5g2KZaXNy89AfBC5vRDRgyDyj/RwcDg8
83+
0kDGKobcGhTx5YkWoNvR/2WuTN6KC8DM78bfEREDHDxiXfAXrMIi7Ux2FvUX13l7
84+
6Sp9kiG3ETLjFom3n/qhg1ITJqPJSJi3tey0o2Pd5Arv0MIhQyep++URtZfND5fg
85+
F5x7hgnSf9Q1P1dJnVadu+ohUmmG7g+zX4rTqjN2jmHcf9V4lLK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F5PtBcKpZLTwr1cwxLHGB/TXWiXQslcTwlo
102+
lkclB+A7BwzJ4tXzy29I8HTmVoOWLRFnYvAFZ26d3CZdqciFv8a8zF1QnZX1uN6F
103+
DsPGrNbpS6OLmH5QoJ4wzICd3a321noVNiaVIUQNAoGAYu4RrGcBKRuy75lfKARD
104+
gNxxVlvuI33ieK/3A9nUWc3LXl5D/yiSePCUs4giOwi2gFrGjcmIqLXZE5XUYGEu
105+
zXWWQCGbMqyX15/A2/eTuj658F292nkSyU/5U2999WjCm79sfnGJB1zavfv2fzGK
106+
g4trXCUkjAVG3Toaq05saGM=
107+
-----END PRIVATE KEY-----
108+
""";
109+
private static final String CLIENTS_CERT = """
110+
-----BEGIN CERTIFICATE-----
111+
MIIDhjCCAm6gAwIBAgIJAOKzFJgrn+rZMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV
112+
BAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg
113+
Q29tcGFueSBMdGQxEzARBgNVBAMMCmNsaWVudHMtY2EwIBcNMTgwODIzMTYyMTI1
114+
WhgPMjExODA3MzAxNjIxMjVaMFcxCzAJBgNVBAYTAlhYMRUwEwYDVQQHDAxEZWZh
115+
dWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQgQ29tcGFueSBMdGQxEzARBgNVBAMM
116+
CmNsaWVudHMtY2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCWws5F
117+
EJOpfZ/sFJWYbYdJVxmZB+5PjCwA2TUZxF/3P4w/5g2KZaXNy89AfBC5vRDRgyDy
118+
j/RwcDg80kDGKobcGhTx5YkWoNvR/2WuTN6KC8DM78bfEREDHDxiXfAXrMIi7Ux2
119+
FvUX13l76Sp9kiG3ETLjFom3n/qhg1ITJqPJSJi3tey0o2Pd5Arv0MIhQyep++UR
120+
tZfND5fgF5x7hgnSf9Q1P1dJnVadu+ohUmmG7g+zX4rTqjN2jmHcf9V4lLKdPGWw
121+
LQEGnP9yDqlm8x12M/BcIJasRgcciVsKYFuXe09NEYBvUjW8L6gaQ6U9wcYZ2MlK
122+
W/8LMGkSFfO4quAJAgMBAAGjUzBRMB0GA1UdDgQWBBQUwNmfsNj+PM240pVPxYx9
123+
Q9eQhDAfBgNVHSMEGDAWgBQUwNmfsNj+PM240pVPxYx9Q9eQhDAPBgNVHRMBAf8E
124+
BTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAnhbNKwMmnayHsT6kKgyyDV6RUUYs6
125+
nYf3nx+GIQWSw4c5TOHDcTWdKpOxVnLNXYKQoSkb1RBoSMLBdQwidZ5K2DB5eXaG
126+
rcfEbKNBc5ZCFgFEAyy35pitJOmU/KzCdKyvx+TR5hIgGoKajYX5JZxj+1rTPGKO
127+
ePT9iFp1ZbzHjgw6vFeJ+D2ov6HfW6C/KuK9Y6xUpvRQLVjMJYCyzxkxQAxZvu/0
128+
0HVYYH6UJ7kuWywFMWoBdZ8US/vuUSBYyCGNL9p6ol+h9rsz3cIWBVBjx8C3qKki
129+
QtlIdmFljGSaGGY6aJjUvUdgoPp1yQPa5oS+afr5g9gaEp4lxP6mc+Li
130+
-----END CERTIFICATE-----
131+
""";
84132

85133
private static final String ALTERNATE_CLIENTS_CERT = """
86134
-----BEGIN CERTIFICATE-----
@@ -221,24 +269,6 @@ public class MockCertManager implements CertManager {
221269
CLUSTER_CERT_STORE = loadResource(is);
222270
is = MockCertManager.class.getClassLoader().getResourceAsStream("CLIENTS_CERT.str");
223271
CLIENTS_CERT_STORE = loadResource(is);
224-
// generate clients certificate and key, to satisfy the validity days check mainly in KafkaUser tests
225-
OpenSslCertManager openSslCertManager = new OpenSslCertManager();
226-
try {
227-
File keyFile = Files.createTempFile("tls", "key").toFile();
228-
File csrFile = Files.createTempFile("tls", "csr").toFile();
229-
File certFile = Files.createTempFile("tls", "cert").toFile();
230-
231-
Subject.Builder subject = new Subject.Builder();
232-
subject.withCommonName("strimzi-client");
233-
234-
openSslCertManager.generateCsr(keyFile, csrFile, subject.build());
235-
openSslCertManager.generateCert(csrFile, Util.decodeBytesFromBase64(clusterCaKey()), Util.decodeBytesFromBase64(clusterCaCert()), certFile, subject.build(), 365);
236-
237-
CLIENTS_CERT = Base64.getEncoder().encodeToString(Files.readAllBytes(certFile.toPath()));
238-
CLIENTS_KEY = Base64.getEncoder().encodeToString(Files.readAllBytes(keyFile.toPath()));
239-
} catch (Exception e) {
240-
throw new RuntimeException("Failed to create tmp files");
241-
}
242272
}
243273

244274
public static String clusterCaCert() {
@@ -250,21 +280,29 @@ public static String clusterCaKey() {
250280
}
251281

252282
public static String clientsCaCert() {
253-
return CLIENTS_CERT;
283+
return Base64.getEncoder().encodeToString(CLIENTS_CERT.getBytes(Charset.defaultCharset()));
254284
}
255285

256286
public static String alternateClientsCaCert() {
257287
return Base64.getEncoder().encodeToString(ALTERNATE_CLIENTS_CERT.getBytes(Charset.defaultCharset()));
258288
}
259289

260290
public static String clientsCaKey() {
261-
return CLIENTS_KEY;
291+
return Base64.getEncoder().encodeToString(CLIENTS_KEY.getBytes(Charset.defaultCharset()));
262292
}
263293

264294
public static String clusterCaCertStore() {
265295
return Base64.getEncoder().encodeToString(CLUSTER_CERT_STORE);
266296
}
267297

298+
public static String clientsCaCertStore() {
299+
return Base64.getEncoder().encodeToString(CLIENTS_CERT_STORE);
300+
}
301+
302+
public static String certStorePassword() {
303+
return Base64.getEncoder().encodeToString(CERT_STORE_PASSWORD.getBytes(Charset.defaultCharset()));
304+
}
305+
268306
private void write(File keyFile, String str) throws IOException {
269307
try (FileWriter writer = new FileWriter(keyFile)) {
270308
writer.write(str);

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
@@ -83,7 +83,7 @@ spec:
8383
description: "Specify the password for the user. If not set, a new password is generated by the User Operator."
8484
renewalDays:
8585
type: integer
86-
description: "Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, default User Operator value is used."
86+
description: "Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, Clients CA configuration is used."
8787
x-kubernetes-validations:
8888
- rule: self > 0
8989
message: '''renewalDays'' has to be higher than 0.'
@@ -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. 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. "
99+
description: "Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used."
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ spec:
8282
description: "Specify the password for the user. If not set, a new password is generated by the User Operator."
8383
renewalDays:
8484
type: integer
85-
description: "Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, default User Operator value is used."
85+
description: "Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, Clients CA configuration is used."
8686
x-kubernetes-validations:
8787
- rule: self > 0
8888
message: '''renewalDays'' has to be higher than 0.'
@@ -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. 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. "
98+
description: "Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used."
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ spec:
8282
description: "Specify the password for the user. If not set, a new password is generated by the User Operator."
8383
renewalDays:
8484
type: integer
85-
description: "Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, default User Operator value is used."
85+
description: "Configures how many days before the certificate expiration should be the user certificate renewed. If not configured, Clients CA configuration is used."
8686
x-kubernetes-validations:
8787
- rule: self > 0
8888
message: '''renewalDays'' has to be higher than 0.'
@@ -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. 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. "
98+
description: "Number of days for which the user certificate should be valid. If not configured, Clients CA configuration is used."
9999
x-kubernetes-validations:
100100
- rule: self > 0
101101
message: '''validityDays'' has to be higher than 0.'

0 commit comments

Comments
 (0)