Skip to content

Commit ff98a7e

Browse files
committed
Address review comments from Paolo
Signed-off-by: Gantigmaa Selenge <[email protected]>
1 parent 91eaf20 commit ff98a7e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ protected Future<Void> authzTrustedCertsSecret() {
874874
Set<String> secretsToCopy = new HashSet<>();
875875
List<Integer> certHashes = new ArrayList<>();
876876

877-
// opa is deprecated?
878877
if (kafka.getAuthorization() instanceof KafkaAuthorizationOpa opaAuthz && opaAuthz.getTlsTrustedCertificates() != null) {
879878
secretsToCopy.addAll(opaAuthz.getTlsTrustedCertificates().stream().map(CertSecretSource::getSecretName).toList());
880879
}

kafka-agent/src/main/java/io/strimzi/kafka/agent/KafkaAgent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ private SslContextFactory.Server getSSLContextFactory() throws GeneralSecurityEx
263263
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
264264
sslContextFactory.setTrustStore(KafkaAgentUtils.jksTrustStore(caCertSecret));
265265

266-
sslContextFactory.setKeyStore(KafkaAgentUtils.jksKeyStore(nodeCertSecret));
267-
sslContextFactory.setKeyStorePassword("changeit");
266+
String password = KafkaAgentUtils.generateRandomPassword();
267+
sslContextFactory.setKeyStore(KafkaAgentUtils.jksKeyStore(nodeCertSecret, password.toCharArray()));
268+
sslContextFactory.setKeyStorePassword(password);
268269
sslContextFactory.setNeedClientAuth(true);
269270
return sslContextFactory;
270271
}

kafka-agent/src/main/java/io/strimzi/kafka/agent/KafkaAgentUtils.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.security.KeyFactory;
1414
import java.security.KeyStore;
1515
import java.security.PrivateKey;
16+
import java.security.SecureRandom;
1617
import java.security.cert.Certificate;
1718
import java.security.cert.CertificateException;
1819
import java.security.cert.CertificateFactory;
@@ -59,7 +60,7 @@ static KeyStore jksTrustStore(Secret secret) throws GeneralSecurityException, IO
5960
* @throws GeneralSecurityException if something goes wrong when creating the truststore
6061
* @throws IOException if there is an I/O or format problem with the data used to load the truststore.
6162
*/
62-
static KeyStore jksKeyStore(Secret secret) throws GeneralSecurityException, IOException {
63+
static KeyStore jksKeyStore(Secret secret, char[] password) throws GeneralSecurityException, IOException {
6364
String secretName = secret.getMetadata().getName();
6465
String strippedPrivateKey = new String(decodeBase64FieldFromSecret(secret, secretName + ".key"), StandardCharsets.US_ASCII)
6566
.replace("-----BEGIN PRIVATE KEY-----", "")
@@ -73,10 +74,16 @@ static KeyStore jksKeyStore(Secret secret) throws GeneralSecurityException, IOEx
7374
X509Certificate certificateChain = x509Certificate(decodeBase64FieldFromSecret(secret, secretName + ".crt"));
7475
KeyStore nodeKeyStore = KeyStore.getInstance("JKS");
7576
nodeKeyStore.load(null);
76-
nodeKeyStore.setKeyEntry(secret.getMetadata().getName(), key, "changeit".toCharArray(), new Certificate[]{certificateChain});
77+
nodeKeyStore.setKeyEntry(secret.getMetadata().getName(), key, password, new Certificate[]{certificateChain});
7778
return nodeKeyStore;
7879
}
7980

81+
static String generateRandomPassword() {
82+
byte[] random = new byte[24];
83+
new SecureRandom().nextBytes(random);
84+
return Base64.getUrlEncoder().withoutPadding().encodeToString(random).substring(0, 32);
85+
}
86+
8087
/**
8188
* Extract all public keys (all .crt records) from a secret.
8289
*/

0 commit comments

Comments
 (0)