-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[Spark-21842][Mesos] Support Kerberos ticket renewal and creation in Mesos #19272
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
Changes from 1 commit
44a6098
781c5a7
18d2c6c
43ab547
f136eaa
488f72a
f5925fd
3f22efe
e522150
837157d
c95f80b
e8bbc9e
1596d80
864ab7e
7e0590a
f93c551
b2fbcf2
4558cea
5f254e5
8df7e37
45b46ed
18d77ff
049e4b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,6 @@ import scala.collection.mutable.{ArrayBuffer, HashMap, HashSet} | |
| import scala.concurrent.Future | ||
|
|
||
| import org.apache.spark.{ExecutorAllocationClient, SparkEnv, SparkException, TaskState} | ||
| import org.apache.spark.deploy.security.HadoopDelegationTokenManager | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.rpc._ | ||
| import org.apache.spark.scheduler._ | ||
|
|
@@ -96,8 +95,7 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp | |
| // The num of current max ExecutorId used to re-register appMaster | ||
| @volatile protected var currentExecutorIdCounter = 0 | ||
|
|
||
| // Hadoop delegation tokens to be sent to the executors, can be updated as necessary. | ||
| protected var hadoopDelegationTokens: Option[Array[Byte]] = initializeHadoopDelegationTokens() | ||
| private val hadoopDelegationTokens: () => Option[Array[Byte]] = fetchHadoopDelegationTokens | ||
|
|
||
| class DriverEndpoint(override val rpcEnv: RpcEnv, sparkProperties: Seq[(String, String)]) | ||
| extends ThreadSafeRpcEndpoint with Logging { | ||
|
|
@@ -156,7 +154,6 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp | |
|
|
||
| case UpdateDelegationTokens(newDelegationTokens) => | ||
| // Update the driver's delegation tokens in case new executors are added later. | ||
| hadoopDelegationTokens = Some(newDelegationTokens) | ||
| executorDataMap.values.foreach { ed => | ||
| ed.executorEndpoint.send(UpdateDelegationTokens(newDelegationTokens)) | ||
| } | ||
|
|
@@ -237,7 +234,7 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp | |
| val reply = SparkAppConfig( | ||
| sparkProperties, | ||
| SparkEnv.get.securityManager.getIOEncryptionKey(), | ||
| hadoopDelegationTokens) | ||
| hadoopDelegationTokens.apply()) | ||
|
||
| context.reply(reply) | ||
| } | ||
|
|
||
|
|
@@ -687,7 +684,7 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp | |
| true | ||
| } | ||
|
|
||
| protected def initializeHadoopDelegationTokens(): Option[Array[Byte]] = { None } | ||
| protected def fetchHadoopDelegationTokens(): Option[Array[Byte]] = { None } | ||
| } | ||
|
|
||
| private[spark] object CoarseGrainedSchedulerBackend { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ package org.apache.spark.scheduler.cluster.mesos | |
| import java.security.PrivilegedExceptionAction | ||
| import java.util.concurrent.{ScheduledExecutorService, TimeUnit} | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.security.UserGroupInformation | ||
|
|
||
| import org.apache.spark.SparkConf | ||
|
|
@@ -32,39 +33,45 @@ import org.apache.spark.util.ThreadUtils | |
|
|
||
|
|
||
| /** | ||
| * The MesosCredentialRenewer will update the Hadoop credentials for Spark drivers accessing | ||
| * secured services using Kerberos authentication. It is modeled after the YARN AMCredential | ||
| * renewer, and similarly will renew the Credentials when 75% of the renewal interval has passed. | ||
| * The MesosHadoopDelegationTokenManager fetches and updates Hadoop delegation tokens on the behalf | ||
| * of the MesosCoarseGrainedSchedulerBackend. It is modeled after the YARN AMCredentialRenewer, | ||
| * and similarly will renew the Credentials when 75% of the renewal interval has passed. | ||
| * The principal difference is that instead of writing the new credentials to HDFS and | ||
| * incrementing the timestamp of the file, the new credentials (called Tokens when they are | ||
| * serialized) are broadcast to all running executors. On the executor side, when new Tokens are | ||
| * recieved they overwrite the current credentials. | ||
| * received they overwrite the current credentials. | ||
| */ | ||
| class MesosCredentialRenewer( | ||
| conf: SparkConf, | ||
| tokenManager: HadoopDelegationTokenManager) extends Logging { | ||
| private[spark] class MesosHadoopDelegationTokenManager( | ||
| conf: SparkConf, hadoopConfig: Configuration, | ||
|
||
| driverEndpoint: RpcEndpointRef) | ||
| extends Logging { | ||
|
|
||
| private val credentialRenewerThread: ScheduledExecutorService = | ||
| ThreadUtils.newDaemonSingleThreadScheduledExecutor("Credential Renewal Thread") | ||
|
|
||
| private val principal = conf.get(config.PRINCIPAL).orNull | ||
| private val tokenManager: HadoopDelegationTokenManager = | ||
| new HadoopDelegationTokenManager(conf, hadoopConfig) | ||
|
|
||
| private val (secretFile, mode) = getSecretFile(conf) | ||
| private val principal: String = conf.get(config.PRINCIPAL).orNull | ||
|
|
||
| var (tokens: Array[Byte], timeOfNextRenewal: Long) = { | ||
| private val (secretFile: String, mode: String) = getSecretFile(conf) | ||
|
|
||
| private var (tokens: Array[Byte], timeOfNextRenewal: Long) = { | ||
| try { | ||
| val creds = UserGroupInformation.getCurrentUser.getCredentials | ||
| val hadoopConf = SparkHadoopUtil.get.newConfiguration(conf) | ||
| val rt = tokenManager.obtainDelegationTokens(hadoopConf, creds) | ||
| logInfo(s"Initialized tokens: ${SparkHadoopUtil.get.dumpTokens(creds)}") | ||
| (SparkHadoopUtil.get.serialize(creds), rt) | ||
| } catch { | ||
| case e: Exception => | ||
| throw new IllegalStateException("Failed to initialize Hadoop delegation tokens\n" + | ||
| s"\tPricipal: $principal\n\tmode: $mode\n\tsecret file $secretFile\n\tException: $e") | ||
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| scheduleTokenRenewal() | ||
|
|
||
| private def getSecretFile(conf: SparkConf): (String, String) = { | ||
| val keytab = conf.get(config.KEYTAB).orNull | ||
| val tgt = conf.getenv("KRB5CCNAME") | ||
|
|
@@ -90,7 +97,7 @@ class MesosCredentialRenewer( | |
| (secretFile, mode) | ||
| } | ||
|
|
||
| def scheduleTokenRenewal(driverEndpoint: RpcEndpointRef): Unit = { | ||
| private def scheduleTokenRenewal(): Unit = { | ||
| def scheduleRenewal(runnable: Runnable): Unit = { | ||
| val remainingTime = timeOfNextRenewal - System.currentTimeMillis() | ||
| if (remainingTime <= 0) { | ||
|
|
@@ -107,7 +114,7 @@ class MesosCredentialRenewer( | |
| override def run(): Unit = { | ||
| try { | ||
| val tokensBytes = getNewDelegationTokens | ||
| broadcastDelegationTokens(tokensBytes, driverEndpoint) | ||
| broadcastDelegationTokens(tokensBytes) | ||
| } catch { | ||
| case e: Exception => | ||
| // Log the error and try to write new tokens back in an hour | ||
|
||
|
|
@@ -151,16 +158,23 @@ class MesosCredentialRenewer( | |
| } else { | ||
| SparkHadoopUtil.getDateOfNextUpdate(nextRenewalTime, 0.75) | ||
| } | ||
| logInfo(s"Time of next renewal is $timeOfNextRenewal") | ||
| logInfo(s"Time of next renewal is in ${timeOfNextRenewal - System.currentTimeMillis()} ms") | ||
|
|
||
| // Add the temp credentials back to the original ones. | ||
| UserGroupInformation.getCurrentUser.addCredentials(tempCreds) | ||
| SparkHadoopUtil.get.serialize(tempCreds) | ||
| } | ||
|
|
||
| private def broadcastDelegationTokens(tokens: Array[Byte], driverEndpoint: RpcEndpointRef) = { | ||
| logInfo("Sending new tokens to all executors") | ||
| private def broadcastDelegationTokens(tokens: Array[Byte]) = { | ||
| logDebug("Sending new tokens to all executors") | ||
|
||
| if (driverEndpoint == null) { | ||
|
||
| throw new IllegalStateException("driver endpoint is Null!") | ||
| } | ||
| driverEndpoint.send(UpdateDelegationTokens(tokens)) | ||
| } | ||
|
|
||
| def getTokens(): Array[Byte] = { | ||
| tokens | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this, |
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale comment?