- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 01:19 PM
We found the solution!, thanks to a Databricks architect here’s how we ultimately fixed it:
1.- Copy the JVM’s cacerts into a volume so Spark can trust Amazon’s MSK certificate bundle. From a notebook cell with shell access, run:
%sh
JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
cp \
$JAVA_HOME/lib/security/cacerts \
/Volumes/<catalog>/<schema>/<volume>/kafka.client.truststore.jks2.- Switch your JAAS config to the SCRAM login module and point Spark at the new truststore. In your spark.readStream call:
df = (
spark.readStream
.format("kafka")
.option("kafka.bootstrap.servers", "<broker1:9096,broker2:9096>")
.option("subscribe", "<topic>")
# Use the SCRAM login module for SCRAM‑SHA‑512
.option(
"kafka.sasl.jaas.config",
'org.apache.kafka.common.security.scram.ScramLoginModule '
'required username="<user>" password="<password>";'
)
.option("kafka.security.protocol", "SASL_SSL")
.option("kafka.sasl.mechanism", "SCRAM-SHA-512")
# Truststore location on your mounted volume
.option(
"kafka.ssl.truststore.location",
"/Volumes/<catalog>/<schema>/<volume>/kafka.client.truststore.jks"
)
# Default Java keystore password (“changeit” unless you’ve overridden it)
.option("kafka.ssl.truststore.password", "changeit")
.option("maxOffsetsPerTrigger", 10)
.option("group.id", "group_read_1")
.load()
)
display(df)Because Spark runs inside its own VM it didn’t pick up the bundled Java certs by default. Copying the cacerts file into a volume and pointing kafka.ssl.truststore.location at it lets Spark complete the TLS handshake. Switching to the official SCRAM login module (org.apache.kafka.common.security.scram.ScramLoginModule) ensures compatibility with SCRAM‑SHA‑512. With those two changes in place, the stream connected immediately and ran without errors.