Skip to content

Commit 909da96

Browse files
peter-tothNgone51
authored andcommitted
[SPARK-41958][CORE] Disallow arbitrary custom classpath with proxy user in cluster mode
### What changes were proposed in this pull request? This PR proposes to disallow arbitrary custom classpath with proxy user in cluster mode by default. ### Why are the changes needed? To avoid arbitrary classpath in spark cluster. ### Does this PR introduce _any_ user-facing change? Yes. User should reenable this feature by `spark.submit.proxyUser.allowCustomClasspathInClusterMode`. ### How was this patch tested? Manually tested. Closes #39474 from Ngone51/dev. Lead-authored-by: Peter Toth <[email protected]> Co-authored-by: Yi Wu <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 51b709b commit 909da96

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ private[spark] class SparkSubmit extends Logging {
306306
val isKubernetesClient = clusterManager == KUBERNETES && deployMode == CLIENT
307307
val isKubernetesClusterModeDriver = isKubernetesClient &&
308308
sparkConf.getBoolean("spark.kubernetes.submitInDriver", false)
309+
val isCustomClasspathInClusterModeDisallowed =
310+
!sparkConf.get(ALLOW_CUSTOM_CLASSPATH_BY_PROXY_USER_IN_CLUSTER_MODE) &&
311+
args.proxyUser != null &&
312+
(isYarnCluster || isMesosCluster || isStandAloneCluster || isKubernetesCluster)
309313

310314
if (!isMesosCluster && !isStandAloneCluster) {
311315
// Resolve maven dependencies if there are any and add classpath to jars. Add them to py-files
@@ -887,6 +891,13 @@ private[spark] class SparkSubmit extends Logging {
887891

888892
sparkConf.set("spark.app.submitTime", System.currentTimeMillis().toString)
889893

894+
if (childClasspath.nonEmpty && isCustomClasspathInClusterModeDisallowed) {
895+
childClasspath.clear()
896+
logWarning(s"Ignore classpath ${childClasspath.mkString(", ")} with proxy user specified " +
897+
s"in Cluster mode when ${ALLOW_CUSTOM_CLASSPATH_BY_PROXY_USER_IN_CLUSTER_MODE.key} is " +
898+
s"disabled")
899+
}
900+
890901
(childArgs.toSeq, childClasspath.toSeq, sparkConf, childMainClass)
891902
}
892903

@@ -940,6 +951,10 @@ private[spark] class SparkSubmit extends Logging {
940951
logInfo(s"Classpath elements:\n${childClasspath.mkString("\n")}")
941952
logInfo("\n")
942953
}
954+
assert(!(args.deployMode == "cluster" && args.proxyUser != null && childClasspath.nonEmpty) ||
955+
sparkConf.get(ALLOW_CUSTOM_CLASSPATH_BY_PROXY_USER_IN_CLUSTER_MODE),
956+
s"Classpath of spark-submit should not change in cluster mode if proxy user is specified " +
957+
s"when ${ALLOW_CUSTOM_CLASSPATH_BY_PROXY_USER_IN_CLUSTER_MODE.key} is disabled")
943958
val loader = getSubmitClassLoader(sparkConf)
944959
for (jar <- childClasspath) {
945960
addJarToClasspath(jar, loader)

core/src/main/scala/org/apache/spark/internal/config/package.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,4 +2461,11 @@ package object config {
24612461
.version("3.4.0")
24622462
.timeConf(TimeUnit.MILLISECONDS)
24632463
.createWithDefaultString("5s")
2464+
2465+
private[spark] val ALLOW_CUSTOM_CLASSPATH_BY_PROXY_USER_IN_CLUSTER_MODE =
2466+
ConfigBuilder("spark.submit.proxyUser.allowCustomClasspathInClusterMode")
2467+
.internal()
2468+
.version("3.4.0")
2469+
.booleanConf
2470+
.createWithDefault(false)
24642471
}

0 commit comments

Comments
 (0)