You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/08/27 13:57:14 UTC

[GitHub] [spark] gaborgsomogyi commented on a change in pull request #25477: [SPARK-28760][SS][TESTS] Add Kafka delegation token end-to-end test with mini KDC

gaborgsomogyi commented on a change in pull request #25477: [SPARK-28760][SS][TESTS] Add Kafka delegation token end-to-end test with mini KDC
URL: https://github.com/apache/spark/pull/25477#discussion_r318096008
 
 

 ##########
 File path: external/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaDelegationTokenSuite.scala
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.kafka010
+
+import java.util.UUID
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.security.{Credentials, UserGroupInformation}
+import org.apache.kafka.common.security.auth.SecurityProtocol.SASL_PLAINTEXT
+
+import org.apache.spark.deploy.SparkHadoopUtil
+import org.apache.spark.deploy.security.HadoopDelegationTokenManager
+import org.apache.spark.internal.config.{KEYTAB, PRINCIPAL}
+import org.apache.spark.sql.execution.streaming.MemoryStream
+import org.apache.spark.sql.streaming.{OutputMode, StreamTest}
+import org.apache.spark.sql.test.SharedSQLContext
+
+class KafkaDelegationTokenSuite extends StreamTest with SharedSQLContext with KafkaTest {
+
+  import testImplicits._
+
+  protected var testUtils: KafkaTestUtils = _
+
+  protected override def sparkConf = super.sparkConf
+    .set("spark.security.credentials.hadoopfs.enabled", "false")
+    .set("spark.security.credentials.hbase.enabled", "false")
+    .set(KEYTAB, testUtils.clientKeytab)
+    .set(PRINCIPAL, testUtils.clientPrincipal)
+    .set("spark.kafka.clusters.cluster1.auth.bootstrap.servers", testUtils.brokerAddress)
+    .set("spark.kafka.clusters.cluster1.security.protocol", SASL_PLAINTEXT.name)
+
+  override def beforeAll(): Unit = {
+    testUtils = new KafkaTestUtils(Map.empty, true)
+    testUtils.setup()
+    super.beforeAll()
+  }
+
+  override def afterAll(): Unit = {
+    try {
+      if (testUtils != null) {
+        testUtils.teardown()
+        testUtils = null
+      }
+      UserGroupInformation.reset()
+    } finally {
+      super.afterAll()
+    }
+  }
+
+  test("Roundtrip") {
+    val hadoopConf = new Configuration()
+    val manager = new HadoopDelegationTokenManager(spark.sparkContext.conf, hadoopConf, null)
+    val credentials = new Credentials()
+    manager.obtainDelegationTokens(credentials)
+    val serializedCredentials = SparkHadoopUtil.get.serialize(credentials)
+    SparkHadoopUtil.get.addDelegationTokens(serializedCredentials, spark.sparkContext.conf)
+
+    val topic = "topic-" + UUID.randomUUID().toString
+    testUtils.createTopic(topic, partitions = 5)
+
+    withTempDir { checkpointDir =>
+      val input = MemoryStream[String]
+
+      val df = input.toDF()
+      val writer = df.writeStream
+        .outputMode(OutputMode.Append)
+        .format("kafka")
+        .option("checkpointLocation", checkpointDir.getCanonicalPath)
+        .option("kafka.bootstrap.servers", testUtils.brokerAddress)
+        .option("kafka.security.protocol", SASL_PLAINTEXT.name)
 
 Review comment:
   I was thinking about that before and the conclusion was not to inherit it. Obtaining a token should not necessarily use the same protocol as data fetching.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org