Skip to content

Commit 77914dd

Browse files
WIP: Add kerberos principal and keytab to YARN client.
1 parent e945aa6 commit 77914dd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
package org.apache.spark.deploy.yarn
1919

20+
import java.io.File
2021
import java.net.{InetAddress, UnknownHostException, URI, URISyntaxException}
2122
import java.nio.ByteBuffer
23+
import java.nio.file.Files
2224

2325
import scala.collection.JavaConversions._
2426
import scala.collection.mutable.{ArrayBuffer, HashMap, ListBuffer, Map}
@@ -61,7 +63,7 @@ private[spark] class Client(
6163

6264
private val yarnClient = YarnClient.createYarnClient
6365
private val yarnConf = new YarnConfiguration(hadoopConf)
64-
private val credentials = UserGroupInformation.getCurrentUser.getCredentials
66+
private var credentials: Credentials = null
6567
private val amMemoryOverhead = args.amMemoryOverhead // MB
6668
private val executorMemoryOverhead = args.executorMemoryOverhead // MB
6769
private val distCacheMgr = new ClientDistributedCacheManager()
@@ -540,6 +542,23 @@ private[spark] class Client(
540542
amContainer
541543
}
542544

545+
def setupCredentials(): Unit = {
546+
Option(args.principal) match {
547+
case Some(principal) =>
548+
Option(args.keytab) match {
549+
case Some(keytabPath) =>
550+
File principalFile = Files.createTempF
551+
val ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytabPath)
552+
credentials = ugi.getCredentials
553+
case None =>
554+
}
555+
case None =>
556+
credentials = UserGroupInformation.getCurrentUser.getCredentials
557+
558+
}
559+
560+
}
561+
543562
/**
544563
* Report the state of an application until it has exited, either successfully or
545564
* due to some failure, then return a pair of the yarn application state (FINISHED, FAILED,

yarn/src/main/scala/org/apache/spark/deploy/yarn/ClientArguments.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ private[spark] class ClientArguments(args: Array[String], sparkConf: SparkConf)
4141
var amCores: Int = 1
4242
var appName: String = "Spark"
4343
var priority = 0
44+
var principal: String = null
45+
var keytab: String = null
4446
def isClusterMode: Boolean = userClass != null
4547

4648
private var driverMemory: Int = 512 // MB
@@ -222,6 +224,14 @@ private[spark] class ClientArguments(args: Array[String], sparkConf: SparkConf)
222224
archives = value
223225
args = tail
224226

227+
case ("--principal") :: value :: tail =>
228+
principal = value
229+
args = tail
230+
231+
case ("--keytab") :: value :: tail =>
232+
keytab = value
233+
args = tail
234+
225235
case Nil =>
226236

227237
case _ =>

0 commit comments

Comments
 (0)