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

KAFKA-3070: Use IBM Kerberos module for SASL tests if running on IBM JDK #738

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 25 additions & 13 deletions core/src/test/scala/unit/kafka/utils/JaasTestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ object JaasTestUtils {
val kafkaClientContextName = "KafkaClient"
val kafkaServerPrincipal = "client@EXAMPLE.COM"
val kafkaClientPrincipal = "kafka/localhost@EXAMPLE.COM"
val kafkaModule = "com.sun.security.auth.module.Krb5LoginModule"
val isIBMJdk = System.getProperty("java.vendor").contains("IBM")
val kafkaModule = if (isIBMJdk) "com.ibm.security.auth.module.Krb5LoginModule" else "com.sun.security.auth.module.Krb5LoginModule"

def genZkFile: String = {
val jaasFile = java.io.File.createTempFile("jaas", ".conf")
Expand Down Expand Up @@ -71,17 +72,28 @@ object JaasTestUtils {
}

private def writeKafkaToOutputStream(jaasOutputStream: java.io.FileOutputStream, keytabLocation: String) {
jaasOutputStream.write(s"$kafkaClientContextName {\n\t$kafkaModule required debug=true\n".getBytes)
jaasOutputStream.write(s"\tuseKeyTab=true\n".getBytes)
jaasOutputStream.write(s"\tstoreKey=true\n".getBytes)
jaasOutputStream.write(s"""\tserviceName="kafka"\n""".getBytes)
jaasOutputStream.write(s"""\tkeyTab="$keytabLocation"\n""".getBytes)
jaasOutputStream.write(s"""\tprincipal="$kafkaServerPrincipal";\n};\n\n""".getBytes)
jaasOutputStream.write(s"""$kafkaServerContextName {\n\t$kafkaModule required debug=true\n""".getBytes)
jaasOutputStream.write(s"\tuseKeyTab=true\n".getBytes)
jaasOutputStream.write(s"\tstoreKey=true\n".getBytes)
jaasOutputStream.write(s"""\tserviceName="kafka"\n""".getBytes)
jaasOutputStream.write(s"""\tkeyTab="$keytabLocation"\n""".getBytes)
jaasOutputStream.write(s"""\tprincipal="$kafkaClientPrincipal";\n};""".getBytes)
if (isIBMJdk) {
jaasOutputStream.write(s"$kafkaClientContextName {\n\t$kafkaModule required debug=true\n".getBytes)
jaasOutputStream.write(s"\tcredsType=both\n".getBytes)
jaasOutputStream.write(s"""\tuseKeytab="file:$keytabLocation"\n""".getBytes)
jaasOutputStream.write(s"""\tprincipal="$kafkaServerPrincipal";\n};\n\n""".getBytes)
jaasOutputStream.write(s"""$kafkaServerContextName {\n\t$kafkaModule required debug=true\n""".getBytes)
jaasOutputStream.write(s"\tcredsType=both\n".getBytes)
jaasOutputStream.write(s"""\tuseKeytab="file:$keytabLocation"\n""".getBytes)
jaasOutputStream.write(s"""\tprincipal="$kafkaClientPrincipal";\n};""".getBytes)
} else {
jaasOutputStream.write(s"$kafkaClientContextName {\n\t$kafkaModule required debug=true\n".getBytes)
jaasOutputStream.write(s"\tuseKeyTab=true\n".getBytes)
jaasOutputStream.write(s"\tstoreKey=true\n".getBytes)
jaasOutputStream.write(s"""\tserviceName="kafka"\n""".getBytes)
jaasOutputStream.write(s"""\tkeyTab="$keytabLocation"\n""".getBytes)
jaasOutputStream.write(s"""\tprincipal="$kafkaServerPrincipal";\n};\n\n""".getBytes)
jaasOutputStream.write(s"""$kafkaServerContextName {\n\t$kafkaModule required debug=true\n""".getBytes)
jaasOutputStream.write(s"\tuseKeyTab=true\n".getBytes)
jaasOutputStream.write(s"\tstoreKey=true\n".getBytes)
jaasOutputStream.write(s"""\tserviceName="kafka"\n""".getBytes)
jaasOutputStream.write(s"""\tkeyTab="$keytabLocation"\n""".getBytes)
jaasOutputStream.write(s"""\tprincipal="$kafkaClientPrincipal";\n};""".getBytes)
}
}
}
10 changes: 10 additions & 0 deletions core/src/test/scala/unit/kafka/utils/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import org.apache.kafka.common.network.Mode

import scala.collection.Map
import scala.collection.JavaConversions._
import org.apache.kafka.common.config.SaslConfigs

/**
* Utility functions to help with testing
Expand Down Expand Up @@ -213,6 +214,8 @@ object TestUtils extends Logging {

if (protocolAndPorts.exists { case (protocol, _) => usesSslTransportLayer(protocol) })
props.putAll(sslConfigs(Mode.SERVER, false, trustStoreFile, s"server$nodeId"))
if (protocolAndPorts.exists { case (protocol, _) => usesSaslTransportLayer(protocol) })
props.put(KafkaConfig.SaslKerberosServiceNameProp, "kafka")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering how this change is related to using the IBM JDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fpj Thank you for the review. serviceName is not a standard property of the Kerberos module and IBM Kerberos module throws an exception if this property is specified. The alternative configuration option for serviceName works with any JDK.


interBrokerSecurityProtocol.foreach { protocol =>
props.put(KafkaConfig.InterBrokerSecurityProtocolProp, protocol.name)
Expand Down Expand Up @@ -443,6 +446,8 @@ object TestUtils extends Logging {
val props = new Properties
if (usesSslTransportLayer(securityProtocol))
props.putAll(sslConfigs(mode, securityProtocol == SecurityProtocol.SSL, trustStoreFile, certAlias))
if (usesSaslTransportLayer(securityProtocol))
props.put(SaslConfigs.SASL_KERBEROS_SERVICE_NAME, "kafka")
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol.name)
props
}
Expand Down Expand Up @@ -500,6 +505,11 @@ object TestUtils extends Logging {
case _ => false
}

private def usesSaslTransportLayer(securityProtocol: SecurityProtocol): Boolean = securityProtocol match {
case SecurityProtocol.SASL_PLAINTEXT | SecurityProtocol.SASL_SSL => true
case _ => false
}

def consumerSecurityConfigs(securityProtocol: SecurityProtocol, trustStoreFile: Option[File]): Properties =
securityConfigs(Mode.CLIENT, securityProtocol, trustStoreFile, "consumer")

Expand Down