Skip to content

Commit da27f91

Browse files
AngersZhuuuudongjoon-hyun
authored andcommitted
[SPARK-29957][TEST] Reset MiniKDC's default enctypes to fit jdk8/jdk11
### What changes were proposed in this pull request? Hadoop jira: https://issues.apache.org/jira/browse/HADOOP-12911 In this jira, the author said to replace origin Apache Directory project which is not maintained (but not said it won't work well in jdk11) to Apache Kerby which is java binding(fit java version). And in Flink: apache/flink#9622 Author show the reason why hadoop-2.7.2's `MminiKdc` failed with jdk11. Because new encryption types of `es128-cts-hmac-sha256-128` and `aes256-cts-hmac-sha384-192` (for Kerberos 5) enabled by default were added in Java 11. Spark with `hadoop-2.7's MiniKdc`does not support these encryption types and does not work well when these encryption types are enabled, which results in the authentication failure. And when I test hadoop-2.7.2's minikdc in local, the kerberos 's debug error message is read message stream failed, message can't match. ### Why are the changes needed? Support jdk11 with hadoop-2.7 ### Does this PR introduce any user-facing change? NO ### How was this patch tested? Existed UT Closes apache#26594 from AngersZhuuuu/minikdc-3.2.0. Lead-authored-by: angerszhu <[email protected]> Co-authored-by: AngersZhuuuu <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 25431d7 commit da27f91

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

external/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaTestUtils.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit
2525
import javax.security.auth.login.Configuration
2626

2727
import scala.collection.JavaConverters._
28+
import scala.io.Source
2829
import scala.util.Random
2930

3031
import com.google.common.io.Files
@@ -136,9 +137,44 @@ class KafkaTestUtils(
136137
kdcConf.setProperty(MiniKdc.DEBUG, "true")
137138
kdc = new MiniKdc(kdcConf, kdcDir)
138139
kdc.start()
140+
// TODO https://issues.apache.org/jira/browse/SPARK-30037
141+
// Need to build spark's own MiniKDC and customize krb5.conf like Kafka
142+
rewriteKrb5Conf()
139143
kdcReady = true
140144
}
141145

146+
/**
147+
* In this method we rewrite krb5.conf to make kdc and client use the same enctypes
148+
*/
149+
private def rewriteKrb5Conf(): Unit = {
150+
val krb5Conf = Source.fromFile(kdc.getKrb5conf, "UTF-8").getLines()
151+
var rewritten = false
152+
val addedConfig =
153+
addedKrb5Config("default_tkt_enctypes", "aes128-cts-hmac-sha1-96") +
154+
addedKrb5Config("default_tgs_enctypes", "aes128-cts-hmac-sha1-96")
155+
val rewriteKrb5Conf = krb5Conf.map(s =>
156+
if (s.contains("libdefaults")) {
157+
rewritten = true
158+
s + addedConfig
159+
} else {
160+
s
161+
}).filter(!_.trim.startsWith("#")).mkString(System.lineSeparator())
162+
163+
val krb5confStr = if (!rewritten) {
164+
"[libdefaults]" + addedConfig + System.lineSeparator() +
165+
System.lineSeparator() + rewriteKrb5Conf
166+
} else {
167+
rewriteKrb5Conf
168+
}
169+
170+
kdc.getKrb5conf.delete()
171+
Files.write(krb5confStr, kdc.getKrb5conf, StandardCharsets.UTF_8)
172+
}
173+
174+
private def addedKrb5Config(key: String, value: String): String = {
175+
System.lineSeparator() + s" $key=$value"
176+
}
177+
142178
private def createKeytabsAndJaasConfigFile(): String = {
143179
assert(kdcReady, "KDC should be set up beforehand")
144180
val baseDir = Utils.createTempDir()
@@ -171,6 +207,7 @@ class KafkaTestUtils(
171207
| useKeyTab=true
172208
| storeKey=true
173209
| useTicketCache=false
210+
| refreshKrb5Config=true
174211
| keyTab="${zkServerKeytabFile.getAbsolutePath()}"
175212
| principal="$zkServerUser@$realm";
176213
|};
@@ -180,6 +217,7 @@ class KafkaTestUtils(
180217
| useKeyTab=true
181218
| storeKey=true
182219
| useTicketCache=false
220+
| refreshKrb5Config=true
183221
| keyTab="${zkClientKeytabFile.getAbsolutePath()}"
184222
| principal="$zkClientUser@$realm";
185223
|};

0 commit comments

Comments
 (0)