Skip to content

Commit

Permalink
Avoid copying an AMRM delegation token from driver to AM in deploy-mo…
Browse files Browse the repository at this point in the history
…de client

An AMRM delegation token can exist when the spark submit is issue from another hadoop container (example of how cuttle launches jobs on hadoop)

---------

Co-authored-by: w.montaz <w.montaz@criteo.com>
  • Loading branch information
w.montaz committed Jun 14, 2024
1 parent 1f247d4 commit 18cd536
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/src/main/scala/org/apache/spark/deploy/SparkHadoopUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.apache.hadoop.mapred.JobConf
import org.apache.hadoop.security.{Credentials, UserGroupInformation}
import org.apache.hadoop.security.token.{Token, TokenIdentifier}
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier
import org.apache.hadoop.yarn.security.AMRMTokenIdentifier

import org.apache.spark.{SparkConf, SparkException}
import org.apache.spark.internal.Logging
Expand Down Expand Up @@ -154,9 +155,20 @@ private[spark] class SparkHadoopUtil extends Logging {
private[spark] def addDelegationTokens(tokens: Array[Byte], sparkConf: SparkConf): Unit = {
UserGroupInformation.setConfiguration(newConfiguration(sparkConf))
val creds = deserialize(tokens)

val filteredCreds = new Credentials()
for ((k, v) <- creds.getSecretKeyMap.asScala) {
filteredCreds.addSecretKey(k, v)
}
for ((k, token) <- creds.getTokenMap.asScala) {
if (!token.getKind.equals(AMRMTokenIdentifier.KIND_NAME)) {
filteredCreds.addToken(k, token)
}
}

logInfo("Updating delegation tokens for current user.")
logDebug(s"Adding/updating delegation tokens ${dumpTokens(creds)}")
addCurrentUserCredentials(creds)
logDebug(s"Adding/updating delegation tokens ${dumpTokens(filteredCreds)}")
addCurrentUserCredentials(filteredCreds)
}

/**
Expand Down

0 comments on commit 18cd536

Please sign in to comment.