Skip to content

Commit 4aed9d6

Browse files
committed
Address ppatierno review comments
* Remove unnecessary 'public' in docs * Add missing null checking * Throw IllegalArgumentException for unknown CertificateManagerType Signed-off-by: Kate Stanley <11195226+katheris@users.noreply.github.com>
1 parent eb9980a commit 4aed9d6

6 files changed

Lines changed: 32 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# CHANGELOG
22

3-
## 1.2.0
3+
## 1.3.0
44

55
* Add support for cert-manager. Users can set `spec.clusterCa.type` and/or `spec.clientsCa.type` to `cert-manager.io` to delegate end-entity certificate issuance to a cert-manager `Issuer` or `ClusterIssuer`. This feature is behind the `CertManagerCaType` feature gate, which is disabled by default.
6+
7+
## 1.2.0
8+
69
* Add support for Apache Kafka 4.3.1
710
* Support templated (per-pod) additional volumes for Kafka, Kafka Connect and Kafka MirrorMaker 2 operands
811
* Stop auto-mounting Service Account tokens into Pods and mount them through a volume instead

api/src/main/java/io/strimzi/api/kafka/model/common/CertificateManagerType.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,18 @@ public enum CertificateManagerType {
1616

1717
@JsonCreator
1818
public static CertificateManagerType forValue(String value) {
19-
switch (value) {
20-
case "strimzi.io":
21-
return STRIMZI_IO;
22-
case "cert-manager.io":
23-
return CERT_MANAGER_IO;
24-
default:
25-
return null;
26-
}
19+
return switch (value) {
20+
case "strimzi.io" -> STRIMZI_IO;
21+
case "cert-manager.io" -> CERT_MANAGER_IO;
22+
default -> throw new IllegalArgumentException(String.format("Unknown certificate manager type: %s. Must be %s or %s.", value, STRIMZI_IO.toValue(), CERT_MANAGER_IO.toValue()));
23+
};
2724
}
2825

2926
@JsonValue
3027
public String toValue() {
31-
switch (this) {
32-
case STRIMZI_IO:
33-
return "strimzi.io";
34-
case CERT_MANAGER_IO:
35-
return "cert-manager.io";
36-
default:
37-
return null;
38-
}
28+
return switch (this) {
29+
case STRIMZI_IO -> "strimzi.io";
30+
case CERT_MANAGER_IO -> "cert-manager.io";
31+
};
3932
}
4033
}

cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/assembly/CertManagerCaProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private CompletionStage<String> getCaCertForCertManager() {
111111
.thenApply(secret -> {
112112
if (secret == null) {
113113
throw new InvalidResourceException("CA public certificate Secret " + caCertSecretName + " missing.");
114-
} else if (secret.getData().get(caCertSecretKey) == null) {
114+
} else if (secret.getData() == null || secret.getData().get(caCertSecretKey) == null) {
115115
throw new InvalidResourceException("CA public certificate Secret " + caCertSecretName + " missing key " + caCertSecretKey);
116116
}
117117
CertificateUtils.validateUserCaCertChain(reconciliation, caRole, Map.of(caCertSecretKey, secret.getData().get(caCertSecretKey)));

documentation/modules/security/proc-using-cert-manager.adoc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[role="_abstract"]
1111
Configure Strimzi to delegate TLS certificate issuing to https://cert-manager.io/[cert-manager] instead of managing it internally.
12-
When enabled, Strimzi creates cert-manager `Certificate` resources for each component and reads the CA public certificate from a user-provided `Secret` to establish TLS trust.
12+
When enabled, Strimzi creates cert-manager `Certificate` resources for each component and reads the CA certificate from a user-provided `Secret` to establish TLS trust.
1313
cert-manager is responsible for issuing and renewing all end-entity certificates.
1414

1515
This feature requires the `CertManagerCaType` feature gate to be enabled.
@@ -29,7 +29,7 @@ NOTE: Strimzi does not install cert-manager and is not responsible for creating
2929
[source,shell,subs="+quotes"]
3030
kubectl apply -f packaging/install/cert-manager/
3131

32-
. Create a `Secret` containing the CA public certificate that Strimzi should trust.
32+
. Create a `Secret` containing the CA certificate that Strimzi should trust.
3333
+
3434
[source,shell,subs="+quotes"]
3535
----
@@ -40,13 +40,16 @@ kubectl create secret generic _<ca_cert_secret_name>_ \
4040
+
4141
Replace _<ca_cert_secret_name>_ with a name of your choice, _<path_to_ca_cert_pem>_ with the path to the CA certificate PEM file, and _<namespace>_ with the namespace of the Kafka cluster.
4242

43+
NOTE: The `ca.crt` file in the Secret must contain either a single CA certificate or CA certificate chain that can be used to trust certificates issued by cert-manager.
44+
For this reason the cert-manager `SelfSigned` issuer is not supported.
45+
4346
. Create or update the `Kafka` resource, setting `type: cert-manager.io` on `clusterCa`, `clientsCa`, or both.
4447
Set `generateCertificateAuthority: false` and provide the `certManager.issuerRef` and `certManager.caCert` configuration.
4548
+
4649
.Example `Kafka` resource using cert-manager for both Cluster CA and Clients CA
4750
[source,yaml,subs="attributes+"]
4851
----
49-
apiVersion: kafka.strimzi.io/v1beta2
52+
apiVersion: kafka.strimzi.io/v1
5053
kind: Kafka
5154
metadata:
5255
name: my-cluster
@@ -82,7 +85,7 @@ spec:
8285
<3> Name of the cert-manager `Issuer` or `ClusterIssuer` to use.
8386
<4> Kind of the issuer. Must be `Issuer` or `ClusterIssuer`.
8487
<5> API group of the issuer. Defaults to `cert-manager.io`.
85-
<6> Name of the `Secret` containing the CA public certificate.
88+
<6> Name of the `Secret` containing the CA certificate.
8689
<7> Key within the `Secret` that holds the CA certificate PEM data.
8790

8891
. Apply the `Kafka` resource.
@@ -101,7 +104,7 @@ During reconciliation, Strimzi copies the certificates from these Secrets into t
101104

102105
.CA certificate rotation
103106

104-
When the CA public certificate in the user-provided `Secret` changes, Strimzi detects the change on the next reconciliation.
107+
When the CA certificate in the user-provided `Secret` changes, Strimzi detects the change on the next reconciliation.
105108

106109
* If the new certificate was signed by the same private key (cert renewal), Strimzi rolls the Kafka pods once to update the truststore.
107110
* If the new certificate was signed by a new private key (key replacement), Strimzi performs a phased rolling restart.

operator-common/src/main/java/io/strimzi/operator/common/ca/CertManagerCa.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import io.strimzi.operator.common.operator.resource.kubernetes.CertManagerCertificateOperator;
1919
import io.strimzi.operator.common.operator.resource.kubernetes.SecretOperator;
2020

21-
import java.math.BigInteger;
2221
import java.security.cert.CertificateException;
2322
import java.security.cert.X509Certificate;
2423
import java.time.Duration;
@@ -111,13 +110,13 @@ public void maybeUpdateCa(String newCaCertAsBase64, String existingCaCertHash, X
111110
updatedCertData.put(CA_CRT, newCaCertAsBase64);
112111
}
113112
case RENEW_CERT -> {
114-
updatedCertData = new HashMap<>();
113+
updatedCertData = new HashMap<>(caCertData);
115114
updatedCertData.put(CA_CRT, newCaCertAsBase64);
116115
++caCertGeneration;
117116
}
118117
case REPLACE_KEY -> {
119118
String notAfterDate = DATE_TIME_FORMATTER.format(currentCaCertX509().getNotAfter().toInstant().atZone(ZoneId.of("Z")));
120-
updatedCertData = new HashMap<>();
119+
updatedCertData = new HashMap<>(caCertData);
121120
updatedCertData.put(Ca.SecretEntry.CRT.asKey("ca-" + notAfterDate), caCertData.get(CA_CRT));
122121
updatedCertData.put(CA_CRT, newCaCertAsBase64);
123122
++caCertGeneration;
@@ -137,7 +136,7 @@ private RenewalType shouldUpdateCa(String newCaCertAsBase64, String existingCaCe
137136
String newCaCertHash;
138137
try {
139138
x509CaCert = CertificateUtils.x509Certificate(Util.decodeBytesFromBase64(newCaCertAsBase64));
140-
newCaCertHash = String.format("%040x", new BigInteger(1, Util.sha1Digest(x509CaCert.getEncoded())));
139+
newCaCertHash = CertificateUtils.getCertificateThumbprint(x509CaCert);
141140
} catch (CertificateException e) {
142141
throw new RuntimeException(e);
143142
}
@@ -265,7 +264,7 @@ private Certificate buildCertificateResource(String entityName, Subject subject,
265264
.withNewPrivateKey()
266265
.withAlgorithm("RSA")
267266
.withEncoding("PKCS8")
268-
.withSize(2048)
267+
.withSize(4096)
269268
.endPrivateKey()
270269
.withDuration(convertToFabric8Duration(validityDays))
271270
.withRenewBefore(convertToFabric8Duration(renewalDays))

operator-common/src/main/java/io/strimzi/operator/common/operator/resource/kubernetes/CertManagerCertificateOperator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ public CompletionStage<Void> waitForReady(Reconciliation reconciliation, String
5151

5252
private boolean isReady(String namespace, String name) {
5353
Certificate certificate = operation().inNamespace(namespace).withName(name).get();
54-
CertificateStatus status = certificate.getStatus();
54+
if (certificate == null) {
55+
return false;
56+
}
57+
5558
boolean certificateReady = false;
59+
CertificateStatus status = certificate.getStatus();
5660
if (status != null) {
57-
List<CertificateCondition> conditions = certificate.getStatus().getConditions();
61+
List<CertificateCondition> conditions = status.getConditions();
5862
Optional<CertificateCondition> readyCondition = conditions.stream().filter(condition -> condition.getType().equals("Ready"))
5963
.findFirst();
6064
if (readyCondition.isPresent() && readyCondition.get().getStatus().equals("True")) {

0 commit comments

Comments
 (0)