apache / apache/kyuubi

[FEATURE] Support starting SparkSQLEngine with an external delegation token file to reduce unnecessary delegation token creation.

Open
#7,188 0 comments 0 reactions 0 assignees View on GitHub
kind:feature priority:major
Dominant language
Scala
Stars
2.4k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)

### Search before asking

- [x] I have searched in the [issues](https://github.com/apache/kyuubi/issues?q=is%3Aissue) and found no similar issues.

### Describe the feature

- Support starting SparkSQLEngine with an external delegation token file to reduce unnecessary delegation token creation.
- Add YarnRMDelegationTokenProvider to get Yarn RM delegation token which is required when submitting spark yarn application without tgt or keytabs.

### Motivation

Spark applications launched in the proxy-user + cluster mode will automatically request delegation tokens in `spark-submit`.
``` scala
// org.apache.spark.scheduler.cluster.CoarseGrainedSchedulerBackend#start
override def start(): Unit = {
if (UserGroupInformation.isSecurityEnabled()) {
delegationTokenManager = createTokenManager()
delegationTokenManager.foreach { dtm =>
val ugi = UserGroupInformation.getCurrentUser()
val tokens = if (dtm.renewalEnabled) {
dtm.start()
} else {
val creds = ugi.getCredentials()
// fetch all related delegation tokens
dtm.obtainDelegationTokens(creds)
if (creds.numberOfTokens() > 0 || creds.numberOfSecretKeys() > 0) {
SparkHadoopUtil.get.serialize(creds)
} else {
null
}
}
if (tokens != null) {
updateDelegationTokens(tokens)
}
}
}
}
```
However, when `SparkSQLEngine` starts, these tokens will be overwritten (without canceling) by the tokens configured in spark-conf by Kyuubi Server . As we can see in the code below :
```scala
// org.apache.kyuubi.engine.spark.SparkSQLEngine#createSpark
def createSpark(): SparkSession = {
val engineCredentials = kyuubiConf.getOption(KyuubiReservedKeys.KYUUBI_ENGINE_CREDENTIALS_KEY)
kyuubiConf.unset(KyuubiReservedKeys.KYUUBI_ENGINE_CREDENTIALS_KEY)
_sparkConf.set(s"spark.${KyuubiReservedKeys.KYUUBI_ENGINE_CREDENTIALS_KEY}", "")

val session = SparkSession.builder.config(_sparkConf).getOrCreate

engineCredentials.filter(_.nonEmpty).foreach { credentials =>
// reset all delegation token
SparkTBinaryFrontendService.renewDelegationToken(session.sparkContext, credentials)
}
....
}
```

In our production environment, more than 100000 SparkSQLEngine are launched every day through kyuubi, which creates lots of unnecessary delegation tokens in shared delegation token storage.

Image

### Describe the solution

Spark natively supports passing tokens through an external Delegation Token File. As we can see in this doc https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/deploy/security/README.md

We can submit spark application with external delegation token file to avoid unnecessary token creation in `spark-submit` and let kyuubi server manage all delegation tokens for SparkSQLEngine.

### Additional context

_No response_

### Are you willing to submit PR?

- [x] Yes. I would be willing to submit a PR with guidance from the Kyuubi community to improve.
- [ ] No. I cannot submit a PR at this time.

Contributor guide

Open the contributing guide

Research direction

Start with org.apache.kyuubi.engine.spark.SparkSQLEngine#createSpark and the Spark CoarseGrainedSchedulerBackend#start flow described in the issue. Read Spark's external Delegation Token File documentation and investigate the proposed YarnRMDelegationTokenProvider. Done means SparkSQLEngine can start with an external token file while avoiding unnecessary delegation-token creation and preserving Kyuubi server token management.

Written by the indexing model from the issue text.

Assessment

Tech stack
hadoop, scala, spark
Domain
backend, distributed-systems, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.