Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove keystore/truststore pwd from kafka agent command #10480

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docker-images/kafka-based/kafka/scripts/kafka_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ fi

KEY_STORE=/tmp/kafka/cluster.keystore.p12
TRUST_STORE=/tmp/kafka/cluster.truststore.p12
KAFKA_OPTS="${KAFKA_OPTS} -javaagent:$(ls "$KAFKA_HOME"/libs/kafka-agent*.jar)=$KAFKA_READY:$ZK_CONNECTED:$KEY_STORE:$CERTS_STORE_PASSWORD:$TRUST_STORE:$CERTS_STORE_PASSWORD"

rm -f /tmp/kafka-agent.properties
tee /tmp/kafka-agent.properties <<EOF
sslKeyStorePath=${KEY_STORE}
sslKeyStorePass=${CERTS_STORE_PASSWORD}
sslTrustStorePath=${TRUST_STORE}
sslTrustStorePass=${CERTS_STORE_PASSWORD}
EOF

KAFKA_OPTS="${KAFKA_OPTS} -javaagent:$(ls "$KAFKA_HOME"/libs/kafka-agent*.jar)=$KAFKA_READY:$ZK_CONNECTED:/tmp/kafka-agent.properties"
export KAFKA_OPTS

# Configure Garbage Collection logging
Expand Down
25 changes: 20 additions & 5 deletions kafka-agent/src/main/java/io/strimzi/kafka/agent/KafkaAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import javax.servlet.http.HttpServletResponse;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
* A very simple Java agent which polls the value of the {@code kafka.server:type=KafkaServer,name=BrokerState}
Expand Down Expand Up @@ -452,7 +454,7 @@ private boolean isKRaftMode() {
*/
public static void premain(String agentArgs) {
String[] args = agentArgs.split(":");
if (args.length < 6) {
if (args.length < 3) {
LOGGER.error("Not enough arguments to parse {}", agentArgs);
System.exit(1);
} else {
Expand All @@ -471,10 +473,23 @@ public static void premain(String agentArgs) {
}
}

String sslKeyStorePath = args[2];
String sslKeyStorePass = args[3];
String sslTrustStorePath = args[4];
String sslTrustStorePass = args[5];
final Properties agentProperties = new Properties();
final Map<String, String> agentConfigs = new HashMap<>();

try (FileInputStream fis = new FileInputStream(args[2])) {
agentProperties.load(fis);
for (String key : agentProperties.stringPropertyNames()) {
agentConfigs.put(key, agentProperties.getProperty(key));
}
} catch (IOException e) {
LOGGER.error("Could not read and parse properties file {}", args[2]);
System.exit(1);
}

final String sslKeyStorePath = agentConfigs.get("sslKeyStorePath");
final String sslKeyStorePass = agentConfigs.get("sslKeyStorePass");
final String sslTrustStorePath = agentConfigs.get("sslTrustStorePath");
final String sslTrustStorePass = agentConfigs.get("sslTrustStorePass");
if (sslKeyStorePath.isEmpty() || sslTrustStorePath.isEmpty()) {
LOGGER.error("SSLKeyStorePath or SSLTrustStorePath is empty: sslKeyStorePath={} sslTrustStore={} ", sslKeyStorePath, sslTrustStorePath);
System.exit(1);
Expand Down
Loading