This is an automated email from the ASF dual-hosted git repository.
LuciferYang pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 08f07fb627b5 [SPARK-58776][K8S] Propagate spark.ssl.rpc.* passwords to
executors
08f07fb627b5 is described below
commit 08f07fb627b5aadff6b1c07d379c7252105c1028
Author: Florian Müller <[email protected]>
AuthorDate: Tue Nov 10 10:50:26 2026 +0800
[SPARK-58776][K8S] Propagate spark.ssl.rpc.* passwords to executors
### What changes were proposed in this pull request?
The Kubernetes pod allocators (`ExecutorPodsAllocator`,
`StatefulSetPodsAllocator`, `DeploymentPodsAllocator`) now pass the RPC SSL
passwords into `KubernetesExecutorConf`, through a new `sslRpcPasswordEnvs`
field, next to the auth secret they already pass since
[SPARK-59479](https://github.com/apache/spark/pull/58768).
`BasicExecutorFeatureStep` reads that map and populates the executor
environment from it, alongside the existing `_SPARK_AUTH_SECRET` injection. The
values are written [...]
The map comes from a new
`SecurityManager.getEnvironmentForSslRpcPasswordsFromSparkConf`, which only
returns passwords set literally in SparkConf (`spark.ssl.rpc.*` or
`spark.ssl.*`). Passwords the driver resolved from a Hadoop credential
provider, from its environment or through variable substitution are not
forwarded, so no password ends up in the executor pod spec that was not already
in plaintext in the configuration.
Variable names the user already binds through
`spark.kubernetes.executor.secretKeyRef`, `spark.executorEnv` or the executor
pod template `env` are skipped. If the executor pod template container uses
`envFrom`, nothing is injected (env takes precedence over envFrom and the keys
behind it are unknown), and a warning listing the variable names is logged
once. This precedence is the opposite of the standalone worker, where
`CommandUtils` appends its own values after `spark.executorEnv`.
The Java-friendly `KubernetesExecutorConf` constructor (unreleased, 4.4.0)
gains a `java.util.Map` parameter for the passwords. `docs/security.md`
documents the propagation, all four variables and how to bind them via
`secretKeyRef` on driver and executors.
Scope note: this fixes Kubernetes only. YARN has the same issue and
requires a follow up. This is tracked in
https://issues.apache.org/jira/browse/SPARK-59408
### Why are the changes needed?
`spark.ssl.rpc.enabled=true` cannot work on Kubernetes today.
`SparkConf.isExecutorStartupConf` deliberately withholds `spark.ssl.*` keys
containing `Password` from the executor startup conf, with the comment
"Passwords are propagated separately though". That separate channel is the
`_SPARK_SSL_RPC_*` environment variables, read back by `SSLOptions.parse`, and
the Kubernetes backend never wrote them. Executors thus start with no keystore
password and die building their `RpcEnv`:
```
java.lang.RuntimeException: SSLFactory creation failed
at org.apache.spark.network.ssl.SSLFactory.<init>(SSLFactory.java:84)
at org.apache.spark.rpc.netty.NettyRpcEnv.<init>(NettyRpcEnv.scala:69)
Caused by: java.security.UnrecoverableKeyException: Get Key failed:
Cannot read the array length because "password" is null
```
The application then aborts on `Max number of executor failures (4)
reached` without submitting a job. Using RPC SSL on Kubernetes currently
requires setting the four variables by hand, through
`spark.kubernetes.executor.secretKeyRef`, `spark.executorEnv`, or an executor
pod template.
### Does this PR introduce _any_ user-facing change?
Yes. Previously, setting `spark.ssl.rpc.enabled=true` on Kubernetes without
also binding `_SPARK_SSL_RPC_*` on the executors caused every executor to fail
during `RpcEnv` construction and the application to abort. Now passwords set in
SparkConf reach the executors and the application runs.
Users already binding the variables through `secretKeyRef`,
`spark.executorEnv` or the pod template `env` are unaffected: those bindings
still win and no literal password is added beside them. Users whose executor
pod template uses `envFrom` keep today's behavior and get a warning. Passwords
from a credential provider or the driver's environment still have to be bound
on the executors. For passwords set through variable substitution (e.g.
`${env:KS_PASS}`), both the referenced variabl [...]
The `_SPARK_SSL_RPC_*` fallbacks in `SSLOptions.parse` are not scoped to
the `rpc` namespace. Once RPC SSL is enabled, another enabled namespace on the
executor can therefore resolve the RPC password.
On the driver, binding these variables also fills in any `spark.ssl.ui
password` not set explicitly, so the docs now say to set
`spark.ssl.ui.keyPassword` (and `trustStorePassword` with client auth)
alongside them.
### How was this patch tested?
`SecurityManagerSuite`:
- `SPARK-58776: SSL RPC password env is empty when RPC SSL is disabled`
- `SPARK-58776: SSL RPC password env from SparkConf includes passwords set
in spark.ssl.rpc.*`
- `SPARK-58776: SSL RPC password env from SparkConf includes passwords
inherited from spark.ssl.*`
- `SPARK-58776: SSL RPC password env from SparkConf excludes passwords
resolved from the environment`
- `SPARK-58776: SSL RPC password env from SparkConf excludes passwords from
a credential provider`
`BasicExecutorFeatureStepSuite`:
- `SPARK-58776: SSL RPC password propagation`
- `SPARK-58776: SSL RPC passwords shouldn't override an explicit
secretKeyRef`
- `SPARK-58776: SSL RPC passwords shouldn't override an explicit
spark.executorEnv entry`
- `SPARK-58776: SSL RPC passwords shouldn't override an env var predefined
on the pod template`
- `SPARK-58776: SSL RPC passwords aren't injected when the pod template
uses envFrom`
- `SPARK-58776: SSL RPC passwords inherited from the global spark.ssl.*
namespace propagate`
- `SPARK-58776: SSL RPC passwords are escaped for Kubernetes env var
expansion`
`ExecutorPodsAllocatorSuite`, `StatefulSetAllocatorSuite`,
`DeploymentAllocatorSuite`: `SPARK-58776: executor conf carries the auth secret
and SparkConf SSL RPC passwords`, asserting on the conf each allocator builds.
`KubernetesConfSuite`: the Java-friendly constructor test covers the new
parameter.
### Was this patch authored or co-authored using generative AI tooling?
Claude Code was used when debugging the original issue that lead to this PR
- the first version of this PR was drafted in that session as well.
Closes #58010 from sweb/SPARK-58776.
Authored-by: Florian Müller <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
(cherry picked from commit f90fdcb2802093fef73b4fbbb0e39d3a8fda602c)
Signed-off-by: yangjie01 <[email protected]>
skip-checks: true
---
.../main/scala/org/apache/spark/SSLOptions.scala | 19 ++
.../scala/org/apache/spark/SecurityManager.scala | 11 ++
.../org/apache/spark/SecurityManagerSuite.scala | 84 +++++++++
docs/security.md | 36 ++++
.../apache/spark/deploy/k8s/KubernetesConf.scala | 23 ++-
.../k8s/features/BasicExecutorFeatureStep.scala | 38 +++-
.../cluster/k8s/DeploymentPodsAllocator.scala | 3 +-
.../cluster/k8s/ExecutorPodsAllocator.scala | 3 +-
.../cluster/k8s/StatefulSetPodsAllocator.scala | 3 +-
.../spark/deploy/k8s/KubernetesConfSuite.scala | 51 ++++--
.../spark/deploy/k8s/KubernetesTestConf.scala | 6 +-
.../features/BasicExecutorFeatureStepSuite.scala | 195 ++++++++++++++++++++-
.../cluster/k8s/DeploymentAllocatorSuite.scala | 17 +-
.../cluster/k8s/ExecutorLifecycleTestUtils.scala | 15 ++
.../cluster/k8s/ExecutorPodsAllocatorSuite.scala | 20 ++-
.../cluster/k8s/StatefulSetAllocatorSuite.scala | 17 +-
16 files changed, 508 insertions(+), 33 deletions(-)
diff --git a/core/src/main/scala/org/apache/spark/SSLOptions.scala
b/core/src/main/scala/org/apache/spark/SSLOptions.scala
index ce058cec2686..b61e104c3be1 100644
--- a/core/src/main/scala/org/apache/spark/SSLOptions.scala
+++ b/core/src/main/scala/org/apache/spark/SSLOptions.scala
@@ -23,6 +23,8 @@ import java.util.HashMap
import java.util.Map
import javax.net.ssl.SSLContext
+import scala.collection.immutable
+
import org.apache.hadoop.conf.Configuration
import org.eclipse.jetty.util.ssl.SslContextFactory
@@ -344,6 +346,11 @@ private[spark] object SSLOptions extends Logging {
SPARK_RPC_SSL_TRUST_STORE_PASSWORD_CONF
)
+ val SPARK_SSL_KEY_PASSWORD_CONF = "spark.ssl.keyPassword"
+ val SPARK_SSL_PRIVATE_KEY_PASSWORD_CONF = "spark.ssl.privateKeyPassword"
+ val SPARK_SSL_KEY_STORE_PASSWORD_CONF = "spark.ssl.keyStorePassword"
+ val SPARK_SSL_TRUST_STORE_PASSWORD_CONF = "spark.ssl.trustStorePassword"
+
val ENV_RPC_SSL_KEY_PASSWORD = "_SPARK_SSL_RPC_KEY_PASSWORD"
val ENV_RPC_SSL_PRIVATE_KEY_PASSWORD = "_SPARK_SSL_RPC_PRIVATE_KEY_PASSWORD"
val ENV_RPC_SSL_KEY_STORE_PASSWORD = "_SPARK_SSL_RPC_KEY_STORE_PASSWORD"
@@ -354,5 +361,17 @@ private[spark] object SSLOptions extends Logging {
ENV_RPC_SSL_KEY_STORE_PASSWORD,
ENV_RPC_SSL_TRUST_STORE_PASSWORD
)
+
+ /** The `spark.ssl.rpc.*` key and the inherited `spark.ssl.*` key behind
each env variable. */
+ val SPARK_RPC_SSL_PASSWORD_CONFS_BY_ENV: immutable.Map[String, Seq[String]]
= immutable.Map(
+ ENV_RPC_SSL_KEY_PASSWORD ->
+ Seq(SPARK_RPC_SSL_KEY_PASSWORD_CONF, SPARK_SSL_KEY_PASSWORD_CONF),
+ ENV_RPC_SSL_PRIVATE_KEY_PASSWORD ->
+ Seq(SPARK_RPC_SSL_PRIVATE_KEY_PASSWORD_CONF,
SPARK_SSL_PRIVATE_KEY_PASSWORD_CONF),
+ ENV_RPC_SSL_KEY_STORE_PASSWORD ->
+ Seq(SPARK_RPC_SSL_KEY_STORE_PASSWORD_CONF,
SPARK_SSL_KEY_STORE_PASSWORD_CONF),
+ ENV_RPC_SSL_TRUST_STORE_PASSWORD ->
+ Seq(SPARK_RPC_SSL_TRUST_STORE_PASSWORD_CONF,
SPARK_SSL_TRUST_STORE_PASSWORD_CONF)
+ )
}
diff --git a/core/src/main/scala/org/apache/spark/SecurityManager.scala
b/core/src/main/scala/org/apache/spark/SecurityManager.scala
index ddfeae900fca..09b033c8a1d9 100644
--- a/core/src/main/scala/org/apache/spark/SecurityManager.scala
+++ b/core/src/main/scala/org/apache/spark/SecurityManager.scala
@@ -447,6 +447,17 @@ private[spark] class SecurityManager(
Map()
}
}
+
+ /**
+ * Like [[getEnvironmentForSslRpcPasswords]], but limited to passwords
stored in plaintext in
+ * SparkConf (`spark.ssl.rpc.*` or `spark.ssl.*`).
+ */
+ def getEnvironmentForSslRpcPasswordsFromSparkConf: Map[String, String] = {
+ getEnvironmentForSslRpcPasswords.filter { case (env, password) =>
+ SSLOptions.SPARK_RPC_SSL_PASSWORD_CONFS_BY_ENV.getOrElse(env, Nil)
+ .exists(sparkConf.getOption(_).contains(password))
+ }
+ }
}
private[spark] object SecurityManager {
diff --git a/core/src/test/scala/org/apache/spark/SecurityManagerSuite.scala
b/core/src/test/scala/org/apache/spark/SecurityManagerSuite.scala
index b9ec0726074a..f7b437842bff 100644
--- a/core/src/test/scala/org/apache/spark/SecurityManagerSuite.scala
+++ b/core/src/test/scala/org/apache/spark/SecurityManagerSuite.scala
@@ -23,7 +23,9 @@ import java.nio.file.Files
import java.security.PrivilegedExceptionAction
import java.util.Base64
+import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.security.UserGroupInformation
+import org.apache.hadoop.security.alias.CredentialProviderFactory
import org.apache.spark.internal.config._
import org.apache.spark.internal.config.UI._
@@ -510,6 +512,88 @@ class SecurityManagerSuite extends SparkFunSuite with
ResetSystemProperties {
}
}
+ test("SPARK-58776: SSL RPC password env is empty when RPC SSL is disabled") {
+ val conf = new SparkConf()
+ .set("spark.ssl.rpc.enabled", "false")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+ val mgr = new SecurityManager(conf)
+ assert(mgr.getEnvironmentForSslRpcPasswords.isEmpty)
+ assert(mgr.getEnvironmentForSslRpcPasswordsFromSparkConf.isEmpty)
+ }
+
+ test("SPARK-58776: SSL RPC password env from SparkConf includes passwords
set in " +
+ "spark.ssl.rpc.*") {
+ val conf = new SparkConf()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.keyPassword", "keyPass")
+ .set("spark.ssl.rpc.privateKeyPassword", "privateKeyPass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+ val expected = Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "keyStorePass",
+ SSLOptions.ENV_RPC_SSL_KEY_PASSWORD -> "keyPass",
+ SSLOptions.ENV_RPC_SSL_PRIVATE_KEY_PASSWORD -> "privateKeyPass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass")
+ val mgr = new SecurityManager(conf)
+ assert(mgr.getEnvironmentForSslRpcPasswords === expected)
+ assert(mgr.getEnvironmentForSslRpcPasswordsFromSparkConf === expected)
+ }
+
+ test("SPARK-58776: SSL RPC password env from SparkConf includes passwords
inherited " +
+ "from spark.ssl.*") {
+ val conf = new SparkConf()
+ .set("spark.ssl.enabled", "true")
+ .set("spark.ssl.keyStorePassword", "globalKeyStorePass")
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+ val mgr = new SecurityManager(conf)
+ assert(mgr.getEnvironmentForSslRpcPasswordsFromSparkConf === Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "globalKeyStorePass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC password env from SparkConf excludes passwords
resolved " +
+ "from the environment") {
+ val conf = new SparkConfWithEnv(Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "envKeyStorePass",
+ "TRUST_STORE_PASS" -> "substitutedTrustStorePass"))
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.trustStorePassword", "${env:TRUST_STORE_PASS}")
+ .set("spark.ssl.rpc.keyPassword", "keyPass")
+ val mgr = new SecurityManager(conf)
+ assert(mgr.getEnvironmentForSslRpcPasswords === Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "envKeyStorePass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD ->
"substitutedTrustStorePass",
+ SSLOptions.ENV_RPC_SSL_KEY_PASSWORD -> "keyPass"))
+ assert(mgr.getEnvironmentForSslRpcPasswordsFromSparkConf === Map(
+ SSLOptions.ENV_RPC_SSL_KEY_PASSWORD -> "keyPass"))
+ }
+
+ test("SPARK-58776: SSL RPC password env from SparkConf excludes passwords
from a " +
+ "credential provider") {
+ withTempDir { dir =>
+ val providerPath = s"localjceks://file${dir.getAbsolutePath}/test.jceks"
+ val hadoopConf = new Configuration()
+ hadoopConf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
providerPath)
+ val provider = CredentialProviderFactory.getProviders(hadoopConf).get(0)
+ provider.createCredentialEntry(
+ "spark.ssl.rpc.keyStorePassword", "providerKeyStorePass".toCharArray)
+ provider.flush()
+
+ val conf = new SparkConf()
+
.set(s"spark.hadoop.${CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH}",
providerPath)
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+ val mgr = new SecurityManager(conf)
+ assert(mgr.getEnvironmentForSslRpcPasswords === Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "providerKeyStorePass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ assert(mgr.getEnvironmentForSslRpcPasswordsFromSparkConf === Map(
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+ }
+
private def encodeFileAsBase64(secretFile: File) = {
Base64.getEncoder.encodeToString(Files.readAllBytes(secretFile.toPath))
}
diff --git a/docs/security.md b/docs/security.md
index b921598b6d6b..06dcb9af1e67 100644
--- a/docs/security.md
+++ b/docs/security.md
@@ -183,6 +183,42 @@ Unlike the other SSL settings for the UI, the RPC SSL is
*not* automatically ena
`spark.ssl.enabled` is set. It must be explicitly enabled, to ensure a safe
migration path for users
upgrading Spark versions.
+On Kubernetes, RPC SSL passwords set in the Spark configuration are propagated
to executor pods
+using environment variables, like the authentication secret described under
+[Kubernetes](#kubernetes) above, so any user who can list pods in the
namespace can read them. In
+cluster mode they are also stored in plaintext in the driver's ConfigMap. To
avoid both, store the
+passwords in a Kubernetes Secret and bind the following variables on the
driver and the executors
+using `spark.kubernetes.driver.secretKeyRef.<name>` and
+`spark.kubernetes.executor.secretKeyRef.<name>`, instead of setting them in
the Spark configuration:
+
+* `_SPARK_SSL_RPC_KEY_STORE_PASSWORD`
+* `_SPARK_SSL_RPC_KEY_PASSWORD`
+* `_SPARK_SSL_RPC_PRIVATE_KEY_PASSWORD`
+* `_SPARK_SSL_RPC_TRUST_STORE_PASSWORD`
+
+For example:
+`spark.kubernetes.executor.secretKeyRef._SPARK_SSL_RPC_KEY_STORE_PASSWORD=<secret-name>:<key>`.
+
+On the driver, these variables also take precedence over the passwords the UI
inherits from
+`spark.ssl.*`. Any UI password not set in the `spark.ssl.ui` namespace or a
Hadoop credential
+provider is filled from these variables, even if `spark.ssl.*` does not set it
either. With
+`_SPARK_SSL_RPC_KEY_PASSWORD` bound on the driver, `spark.ssl.ui.keyPassword`
has to be set as
+well, usually to the UI keystore password, or the UI cannot recover its
private key and the driver
+exits. If the UI requires client authentication,
`spark.ssl.ui.trustStorePassword` has to be set
+explicitly too. Set these UI passwords, and any other that differs from the
RPC one, in the
+`spark.ssl.ui` namespace, for example through variable substitution
+(`spark.ssl.ui.keyStorePassword=${env:UI_KS_PASS}` with `UI_KS_PASS` bound
using
+`spark.kubernetes.driver.secretKeyRef`) or a Hadoop credential provider, to
keep them out of the
+driver's ConfigMap.
+
+A variable already bound on the executors, through `secretKeyRef`,
`spark.executorEnv` or the
+executor pod template, is not overwritten. Passwords the driver reads from a
Hadoop credential
+provider or from its environment are not propagated and must be provided to
the executors
+directly. Passwords set through variable substitution, for example
+`spark.ssl.rpc.keyStorePassword=${env:KS_PASS}`, are not propagated either;
bind both the
+referenced variable (`KS_PASS`) and the matching `_SPARK_SSL_RPC_*` variable
on the executors.
+If the executor container in the pod template uses `envFrom`, no passwords are
propagated.
+
## AES-based Encryption (Legacy)
Spark supports AES-based encryption for RPC connections. For encryption to be
enabled, RPC
diff --git
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
index 7e5a86e024e6..eb7ab531d5dd 100644
---
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
+++
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/KubernetesConf.scala
@@ -16,7 +16,9 @@
*/
package org.apache.spark.deploy.k8s
-import java.util.{Locale, UUID}
+import java.util.{Locale, Map => JMap, UUID}
+
+import scala.jdk.CollectionConverters._
import io.fabric8.kubernetes.api.model.{LocalObjectReference,
LocalObjectReferenceBuilder, Pod}
@@ -216,12 +218,13 @@ class KubernetesExecutorConf(
val executorId: String,
val driverPod: Option[Pod],
val resourceProfileId: Int = DEFAULT_RESOURCE_PROFILE_ID,
- customAuthSecret: Option[String] = None)
+ customAuthSecret: Option[String] = None,
+ private[spark] val sslRpcPasswordEnvs: Map[String, String] = Map.empty)
extends KubernetesConf(sparkConf) with Logging {
/**
- * Java-friendly constructor that accepts a nullable Pod for driverPod and
- * a nullable String for customAuthSecret instead of Option.
+ * Java-friendly constructor that accepts nullable values instead of Option
and a
+ * java.util.Map instead of a Scala Map.
*/
@Since("4.4.0")
def this(
@@ -230,9 +233,11 @@ class KubernetesExecutorConf(
executorId: String,
driverPod: Pod,
resourceProfileId: Int,
- customAuthSecret: String) =
+ customAuthSecret: String,
+ sslRpcPasswordEnvs: JMap[String, String]) =
this(sparkConf, appId, executorId, Option(driverPod), resourceProfileId,
- Option(customAuthSecret))
+ Option(customAuthSecret),
+ Option(sslRpcPasswordEnvs).map(_.asScala.toMap).getOrElse(Map.empty))
def authSecret: Option[String] = {
customAuthSecret
@@ -356,9 +361,11 @@ private[spark] object KubernetesConf {
appId: String,
driverPod: Option[Pod],
resourceProfileId: Int = DEFAULT_RESOURCE_PROFILE_ID,
- authSecret: Option[String] = None): KubernetesExecutorConf = {
+ authSecret: Option[String],
+ sslRpcPasswordEnvs: Map[String, String]): KubernetesExecutorConf = {
new KubernetesExecutorConf(
- sparkConf.clone(), appId, executorId, driverPod, resourceProfileId,
authSecret)
+ sparkConf.clone(), appId, executorId, driverPod, resourceProfileId,
authSecret,
+ sslRpcPasswordEnvs)
}
def getKubernetesAppId(): String =
diff --git
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStep.scala
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStep.scala
index 5774956b1836..37e5a6210aa6 100644
---
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStep.scala
+++
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStep.scala
@@ -17,6 +17,7 @@
package org.apache.spark.deploy.k8s.features
import java.util.Locale
+import java.util.concurrent.atomic.AtomicBoolean
import scala.jdk.CollectionConverters._
@@ -27,7 +28,7 @@ import org.apache.spark.deploy.k8s._
import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
import org.apache.spark.deploy.k8s.submit.KubernetesClientUtils
-import org.apache.spark.internal.Logging
+import org.apache.spark.internal.{Logging, LogKeys}
import org.apache.spark.internal.config._
import org.apache.spark.resource.{ExecutorResourceRequest, ResourceProfile}
import org.apache.spark.rpc.RpcEndpointAddress
@@ -142,6 +143,35 @@ private[spark] class BasicExecutorFeatureStep(
case _ => Nil
}.getOrElse(Nil)
+ // spark.ssl.* passwords are withheld from the executor conf, so they go
through env.
+ // Unlike standalone, a name the user already binds wins; for
secretKeyRef the skip only
+ // keeps a plaintext copy out of the pod spec. envFrom keys are unknown
and lose to env,
+ // so any envFrom disables the injection. Kubernetes expands $(VAR) and
$$ in env values,
+ // so $ is escaped to keep the password verbatim.
+ val container = Option(pod.container)
+ val userBoundEnvNames = kubernetesConf.secretEnvNamesToKeyRefs.keySet ++
+ kubernetesConf.environment.keySet ++
+ container.flatMap(c => Option(c.getEnv))
+ .map(_.asScala.map(_.getName).toSet).getOrElse(Set.empty)
+ val unboundSslRpcPasswords = kubernetesConf.sslRpcPasswordEnvs.filterNot
{
+ case (name, _) => userBoundEnvNames.contains(name)
+ }
+ val hasEnvFrom = container.flatMap(c =>
Option(c.getEnvFrom)).exists(!_.isEmpty)
+ val sslRpcPasswords = if (hasEnvFrom) {
+ if (unboundSslRpcPasswords.nonEmpty &&
+ BasicExecutorFeatureStep.sslRpcEnvFromWarned.compareAndSet(false,
true)) {
+ val names = unboundSslRpcPasswords.keys.toSeq.sorted.mkString(", ")
+ logWarning(log"Executor container uses envFrom, so RPC SSL passwords
are not " +
+ log"injected. Bind ${MDC(LogKeys.EXECUTOR_ENVS, names)} on the
executors unless " +
+ log"envFrom provides them.")
+ }
+ Seq.empty
+ } else {
+ unboundSslRpcPasswords.toSeq.map { case (name, value) =>
+ name -> value.replace("$", "$$")
+ }
+ }
+
val userOpts = kubernetesConf.get(EXECUTOR_JAVA_OPTIONS).toSeq.flatMap {
opts =>
val subsOpts = Utils.substituteAppNExecIds(opts, kubernetesConf.appId,
kubernetesConf.executorId)
@@ -186,6 +216,7 @@ private[spark] class BasicExecutorFeatureStep(
++ attributes
++ kubernetesConf.environment
++ sparkAuthSecret
+ ++ sslRpcPasswords
++ Seq(ENV_CLASSPATH ->
kubernetesConf.get(EXECUTOR_CLASS_PATH).orNull)
++ Seq(ENV_EXECUTOR_LIBRARY_PATH ->
kubernetesConf.get(EXECUTOR_LIBRARY_PATH).orNull)
++ allOpts) ++
@@ -340,3 +371,8 @@ private[spark] class BasicExecutorFeatureStep(
SparkPod(executorPod, containerWithLifecycle)
}
}
+
+private[spark] object BasicExecutorFeatureStep {
+ /** Logs the envFrom warning at most once per JVM. */
+ private[features] val sslRpcEnvFromWarned = new AtomicBoolean(false)
+}
diff --git
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentPodsAllocator.scala
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentPodsAllocator.scala
index 0f970567080f..8e2beab5c9dc 100644
---
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentPodsAllocator.scala
+++
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentPodsAllocator.scala
@@ -128,7 +128,8 @@ class DeploymentPodsAllocator(
applicationId,
driverPod,
resourceProfileId,
- Option(secMgr.getSecretKey()))
+ Option(secMgr.getSecretKey()),
+ secMgr.getEnvironmentForSslRpcPasswordsFromSparkConf)
val resolvedExecutorSpec = executorBuilder.buildFromFeatures(
executorConf,
kubernetesClient,
diff --git
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala
index 90135d36a8f8..932bc3ada15a 100644
---
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala
+++
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala
@@ -536,7 +536,8 @@ class ExecutorPodsAllocator(
applicationId,
driverPod,
resourceProfileId,
- Option(secMgr.getSecretKey()))
+ Option(secMgr.getSecretKey()),
+ secMgr.getEnvironmentForSslRpcPasswordsFromSparkConf)
val resolvedExecutorSpec =
executorBuilder.buildFromFeatures(executorConf,
kubernetesClient, rpIdToResourceProfile(resourceProfileId))
val executorPod = resolvedExecutorSpec.pod
diff --git
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetPodsAllocator.scala
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetPodsAllocator.scala
index 799fdaadd08d..7d127bb20acc 100644
---
a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetPodsAllocator.scala
+++
b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetPodsAllocator.scala
@@ -119,7 +119,8 @@ class StatefulSetPodsAllocator(
applicationId,
driverPod,
resourceProfileId,
- Option(secMgr.getSecretKey()))
+ Option(secMgr.getSecretKey()),
+ secMgr.getEnvironmentForSslRpcPasswordsFromSparkConf)
val resolvedExecutorSpec =
executorBuilder.buildFromFeatures(executorConf,
kubernetesClient, rpIdToResourceProfile(resourceProfileId))
val executorPod = resolvedExecutorSpec.pod
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
index 8a70927b30e6..b57620b4d380 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesConfSuite.scala
@@ -17,9 +17,13 @@
package org.apache.spark.deploy.k8s
+import java.util.{Map => JMap}
+
+import scala.jdk.CollectionConverters._
+
import io.fabric8.kubernetes.api.model.{LocalObjectReferenceBuilder, Pod,
PodBuilder}
-import org.apache.spark.{SPARK_VERSION, SparkConf, SparkFunSuite}
+import org.apache.spark.{SPARK_VERSION, SparkConf, SparkFunSuite, SSLOptions}
import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
import org.apache.spark.deploy.k8s.submit._
@@ -156,14 +160,16 @@ class KubernetesConfSuite extends SparkFunSuite {
new SparkConf(false),
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
- Some(DRIVER_POD))
+ Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(conf.executorId === EXECUTOR_ID)
assert(conf.driverPod.get === DRIVER_POD)
assert(conf.resourceProfileId === DEFAULT_RESOURCE_PROFILE_ID)
assert(conf.authSecret.isEmpty)
}
- test("Java-friendly KubernetesExecutorConf constructor with nullable
driverPod and secret") {
+ test("Java-friendly KubernetesExecutorConf constructor with nullable
arguments") {
val sparkConf = new SparkConf(false)
val conf = new KubernetesExecutorConf(
sparkConf,
@@ -171,12 +177,14 @@ class KubernetesConfSuite extends SparkFunSuite {
EXECUTOR_ID,
null: Pod,
DEFAULT_RESOURCE_PROFILE_ID,
- null: String)
+ null: String,
+ null: JMap[String, String])
assert(conf.appId === KubernetesTestConf.APP_ID)
assert(conf.executorId === EXECUTOR_ID)
assert(conf.driverPod === None)
assert(conf.resourceProfileId === DEFAULT_RESOURCE_PROFILE_ID)
assert(conf.authSecret === None)
+ assert(conf.sslRpcPasswordEnvs === Map.empty)
val confWithValues = new KubernetesExecutorConf(
sparkConf,
@@ -184,10 +192,13 @@ class KubernetesConfSuite extends SparkFunSuite {
EXECUTOR_ID,
DRIVER_POD,
3,
- "custom-secret")
+ "custom-secret",
+ Map(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "keyStorePass").asJava)
assert(confWithValues.driverPod === Some(DRIVER_POD))
assert(confWithValues.resourceProfileId === 3)
assert(confWithValues.authSecret === Some("custom-secret"))
+ assert(confWithValues.sslRpcPasswordEnvs ===
+ Map(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "keyStorePass"))
}
test("KubernetesExecutorConf authSecret resolution.") {
@@ -195,7 +206,9 @@ class KubernetesConfSuite extends SparkFunSuite {
new SparkConf(false),
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
- Some(DRIVER_POD))
+ Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(confWithoutSecret.authSecret.isEmpty)
val confWithCustomSecret = KubernetesConf.createExecutorConf(
@@ -203,7 +216,8 @@ class KubernetesConfSuite extends SparkFunSuite {
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
Some(DRIVER_POD),
- authSecret = Some("custom-secret"))
+ authSecret = Some("custom-secret"),
+ sslRpcPasswordEnvs = Map.empty)
assert(confWithCustomSecret.authSecret === Some("custom-secret"))
val sparkConf = new SparkConf(false)
@@ -212,7 +226,9 @@ class KubernetesConfSuite extends SparkFunSuite {
sparkConf,
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
- Some(DRIVER_POD))
+ Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(confWithSparkConfSecret.authSecret === Some("conf-secret"))
val confWithOverride = KubernetesConf.createExecutorConf(
@@ -220,7 +236,8 @@ class KubernetesConfSuite extends SparkFunSuite {
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
Some(DRIVER_POD),
- authSecret = Some("override-secret"))
+ authSecret = Some("override-secret"),
+ sslRpcPasswordEnvs = Map.empty)
assert(confWithOverride.authSecret === Some("override-secret"))
}
@@ -230,7 +247,9 @@ class KubernetesConfSuite extends SparkFunSuite {
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
Some(DRIVER_POD),
- 10)
+ 10,
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(conf.resourceProfileId === 10)
}
@@ -240,7 +259,9 @@ class KubernetesConfSuite extends SparkFunSuite {
.set(IMAGE_PULL_SECRETS, Seq("my-secret-1", "my-secret-2 ")),
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
- Some(DRIVER_POD))
+ Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(conf.imagePullSecrets ===
Seq(
new LocalObjectReferenceBuilder().withName("my-secret-1").build(),
@@ -266,7 +287,9 @@ class KubernetesConfSuite extends SparkFunSuite {
sparkConf,
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
- Some(DRIVER_POD))
+ Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(conf.labels === Map(
SPARK_VERSION_LABEL -> SPARK_VERSION,
SPARK_EXECUTOR_ID_LABEL -> EXECUTOR_ID,
@@ -294,7 +317,9 @@ class KubernetesConfSuite extends SparkFunSuite {
sparkConf,
EXECUTOR_ID,
KubernetesTestConf.APP_ID,
- Some(DRIVER_POD))
+ Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
assert(conf.environment ===
Map(
"executorEnvVars3_var3" -> "executorEnvVars3",
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesTestConf.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesTestConf.scala
index 1d2977b55e02..bc71293c96e7 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesTestConf.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesTestConf.scala
@@ -82,7 +82,8 @@ object KubernetesTestConf {
secretEnvNamesToKeyRefs: Map[String, String] = Map.empty,
secretNamesToMountPaths: Map[String, String] = Map.empty,
volumes: Seq[KubernetesVolumeSpec] = Seq.empty,
- authSecret: Option[String] = None): KubernetesExecutorConf = {
+ authSecret: Option[String] = None,
+ sslRpcPasswordEnvs: Map[String, String] = Map.empty):
KubernetesExecutorConf = {
val conf = sparkConf.clone()
setPrefixedConfigs(conf, KUBERNETES_EXECUTOR_LABEL_PREFIX, labels)
@@ -92,7 +93,8 @@ object KubernetesTestConf {
setPrefixedConfigs(conf, KUBERNETES_EXECUTOR_SECRET_KEY_REF_PREFIX,
secretEnvNamesToKeyRefs)
setVolumeSpecs(conf, KUBERNETES_EXECUTOR_VOLUMES_PREFIX, volumes)
- new KubernetesExecutorConf(conf, APP_ID, EXECUTOR_ID, driverPod,
customAuthSecret = authSecret)
+ new KubernetesExecutorConf(conf, APP_ID, EXECUTOR_ID, driverPod,
customAuthSecret = authSecret,
+ sslRpcPasswordEnvs = sslRpcPasswordEnvs)
}
private def setPrefixedConfigs(
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStepSuite.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStepSuite.scala
index 7ab53e23d3a8..aa98853a03d0 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStepSuite.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStepSuite.scala
@@ -24,7 +24,7 @@ import com.google.common.net.InternetDomainName
import io.fabric8.kubernetes.api.model._
import org.scalatest.BeforeAndAfter
-import org.apache.spark.{SecurityManager, SparkConf, SparkException,
SparkFunSuite, SparkIllegalArgumentException}
+import org.apache.spark.{SecurityManager, SparkConf, SparkException,
SparkFunSuite, SparkIllegalArgumentException, SSLOptions}
import org.apache.spark.deploy.k8s.{KubernetesExecutorConf,
KubernetesTestConf, SecretVolumeUtils, SparkPod}
import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
@@ -290,7 +290,9 @@ class BasicExecutorFeatureStepSuite extends SparkFunSuite
with BeforeAndAfter {
sparkConf = baseConf,
executorId = "EXECID",
appId = KubernetesTestConf.APP_ID,
- driverPod = Some(DRIVER_POD))
+ driverPod = Some(DRIVER_POD),
+ authSecret = None,
+ sslRpcPasswordEnvs = Map.empty)
val step = new BasicExecutorFeatureStep(executorConf, defaultProfile)
val executor = step.configurePod(SparkPod.initialPod())
@@ -430,6 +432,191 @@ class BasicExecutorFeatureStepSuite extends SparkFunSuite
with BeforeAndAfter {
checkEnv(executor, conf, Map(SecurityManager.ENV_AUTH_SECRET ->
"my-auth-secret"))
}
+ test("SPARK-58776: SSL RPC password propagation") {
+ val conf = baseConf.clone()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.keyPassword", "keyPass")
+ .set("spark.ssl.rpc.privateKeyPassword", "privateKeyPass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+
+ val secMgr = new SecurityManager(conf)
+ val step = new BasicExecutorFeatureStep(
+ KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords),
+ defaultProfile)
+
+ val executor = step.configurePod(SparkPod.initialPod())
+ checkEnv(executor, conf, Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "keyStorePass",
+ SSLOptions.ENV_RPC_SSL_KEY_PASSWORD -> "keyPass",
+ SSLOptions.ENV_RPC_SSL_PRIVATE_KEY_PASSWORD -> "privateKeyPass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC passwords are escaped for Kubernetes env var
expansion") {
+ val conf = baseConf.clone()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "pa$$word$(SPARK_EXECUTOR_ID)")
+ .set("spark.ssl.rpc.keyPassword", "keyPass")
+ .set("spark.ssl.rpc.privateKeyPassword", "privateKeyPass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+
+ val secMgr = new SecurityManager(conf)
+ val step = new BasicExecutorFeatureStep(
+ KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords),
+ defaultProfile)
+
+ val executor = step.configurePod(SparkPod.initialPod())
+ checkEnv(executor, conf, Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD ->
"pa$$$$word$$(SPARK_EXECUTOR_ID)",
+ SSLOptions.ENV_RPC_SSL_KEY_PASSWORD -> "keyPass",
+ SSLOptions.ENV_RPC_SSL_PRIVATE_KEY_PASSWORD -> "privateKeyPass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC passwords shouldn't override an explicit
secretKeyRef") {
+ val conf = baseConf.clone()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+
+ val secMgr = new SecurityManager(conf)
+ val step = new BasicExecutorFeatureStep(
+ KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ secretEnvNamesToKeyRefs = Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD ->
"rpc-secret:keystore-password"),
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords),
+ defaultProfile)
+
+ val executor = step.configurePod(SparkPod.initialPod())
+ checkEnv(executor, conf, Map(
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC passwords shouldn't override an explicit
spark.executorEnv entry") {
+ val conf = baseConf.clone()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+ .set(s"spark.executorEnv.${SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD}",
"userKeyStorePass")
+
+ val secMgr = new SecurityManager(conf)
+ val step = new BasicExecutorFeatureStep(
+ KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords),
+ defaultProfile)
+
+ val executor = step.configurePod(SparkPod.initialPod())
+ checkEnv(executor, conf, Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "userKeyStorePass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC passwords shouldn't override an env var
predefined on the " +
+ "pod template") {
+ val conf = baseConf.clone()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+
+ val secMgr = new SecurityManager(conf)
+ val step = new BasicExecutorFeatureStep(
+ KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords),
+ defaultProfile)
+
+ val templatePod = SparkPod.initialPod()
+ val templateContainer = new ContainerBuilder(templatePod.container)
+ .addNewEnv()
+ .withName(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD)
+ .withNewValueFrom()
+ .withNewSecretKeyRef()
+ .withKey("keystore-password")
+ .withName("rpc-secret")
+ .endSecretKeyRef()
+ .endValueFrom()
+ .endEnv()
+ .build()
+
+ val executor = step.configurePod(SparkPod(templatePod.pod,
templateContainer))
+ checkEnv(executor, conf, Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> null,
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC passwords aren't injected when the pod template
uses envFrom") {
+ BasicExecutorFeatureStep.sslRpcEnvFromWarned.set(false)
+ val conf = baseConf.clone()
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", "keyStorePass")
+ .set("spark.ssl.rpc.trustStorePassword", "trustStorePass")
+
+ val secMgr = new SecurityManager(conf)
+ val executorConf = KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords)
+
+ val templatePod = SparkPod.initialPod()
+ val templateContainer = new ContainerBuilder(templatePod.container)
+ .addNewEnvFrom()
+ .withNewSecretRef()
+ .withName("rpc-secret")
+ .endSecretRef()
+ .endEnvFrom()
+ .build()
+
+ val logAppender = new LogAppender("SSL RPC passwords with envFrom")
+ var executors: Seq[SparkPod] = Seq.empty
+ withLogAppender(logAppender) {
+ executors = Seq.fill(2) {
+ new BasicExecutorFeatureStep(executorConf, defaultProfile)
+ .configurePod(SparkPod(templatePod.pod, templateContainer))
+ }
+ }
+ executors.foreach { executor =>
+ SSLOptions.SPARK_RPC_SSL_PASSWORD_ENVS.foreach { env =>
+
assert(!KubernetesFeaturesTestUtils.containerHasEnvVar(executor.container, env))
+ }
+ assert(executor.container.getEnvFrom.asScala.map(_.getSecretRef.getName)
===
+ Seq("rpc-secret"))
+ }
+ val warnings = logAppender.loggingEvents
+ .map(_.getMessage.getFormattedMessage)
+ .filter(_.contains("envFrom"))
+ assert(warnings.size === 1)
+ assert(warnings.head.contains(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD))
+ assert(warnings.head.contains(SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD))
+ assert(!warnings.head.contains("keyStorePass"))
+ assert(!warnings.head.contains("trustStorePass"))
+ }
+
+ test("SPARK-58776: SSL RPC passwords inherited from the global spark.ssl.*
namespace propagate") {
+ val conf = baseConf.clone()
+ .set("spark.ssl.enabled", "true")
+ .set("spark.ssl.keyStorePassword", "globalKeyStorePass")
+ .set("spark.ssl.trustStorePassword", "globalTrustStorePass")
+ .set("spark.ssl.rpc.enabled", "true")
+
+ val secMgr = new SecurityManager(conf)
+ val step = new BasicExecutorFeatureStep(
+ KubernetesTestConf.createExecutorConf(
+ sparkConf = conf,
+ sslRpcPasswordEnvs = secMgr.getEnvironmentForSslRpcPasswords),
+ defaultProfile)
+
+ val executor = step.configurePod(SparkPod.initialPod())
+ checkEnv(executor, conf, Map(
+ SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD -> "globalKeyStorePass",
+ SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD -> "globalTrustStorePass"))
+ }
+
test("SPARK-32661 test executor offheap memory") {
baseConf.set(MEMORY_OFFHEAP_ENABLED, true)
baseConf.set("spark.memory.offHeap.size", "42m")
@@ -774,6 +961,10 @@ class BasicExecutorFeatureStepSuite extends SparkFunSuite
with BeforeAndAfter {
s"$ENV_JAVA_OPT_PREFIX${ind + extraJavaOptsStart}" -> opt
}.toMap
+ val duplicateEnvNames = executorPod.container.getEnv.asScala
+ .groupBy(_.getName).filter(_._2.size > 1).keys
+ assert(duplicateEnvNames.isEmpty, s"duplicate env names:
${duplicateEnvNames.mkString(", ")}")
+
val containerEnvs = executorPod.container.getEnv.asScala.map {
x => (x.getName, x.getValue)
}.toMap
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentAllocatorSuite.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentAllocatorSuite.scala
index ab05c12c315f..57ad3de5564c 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentAllocatorSuite.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/DeploymentAllocatorSuite.scala
@@ -27,7 +27,7 @@ import org.mockito.ArgumentMatchers.{any, eq => meq}
import org.mockito.Mockito.{clearInvocations, never, times, verify, when}
import org.scalatest.BeforeAndAfter
-import org.apache.spark.{SecurityManager, SparkConf, SparkException,
SparkFunSuite}
+import org.apache.spark.{SecurityManager, SparkConf, SparkException,
SparkFunSuite, SSLOptions}
import org.apache.spark.deploy.k8s.{KubernetesExecutorConf,
KubernetesExecutorSpec}
import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
@@ -130,6 +130,21 @@ class DeploymentAllocatorSuite extends SparkFunSuite with
BeforeAndAfter {
verify(driverPodResource, never()).waitUntilReady(any(), any())
}
+ test("SPARK-58776: executor conf carries the auth secret and SparkConf SSL
RPC passwords") {
+ val sslConf = confWithAuthAndSslRpc(conf)
+ val sslAllocator = new DeploymentPodsAllocator(sslConf, new
SecurityManager(sslConf),
+ executorBuilder, kubernetesClient, snapshotsStore, snapshotsStore.clock)
+ sslAllocator.start(TEST_SPARK_APP_ID, schedulerBackend)
+ sslAllocator.setTotalExpectedExecutors(Map(defaultProfile -> 1))
+
+ val captor = ArgumentCaptor.forClass(classOf[KubernetesExecutorConf])
+ verify(executorBuilder).buildFromFeatures(
+ captor.capture(), meq(kubernetesClient), any(classOf[ResourceProfile]))
+ assert(captor.getValue.authSecret === Some(TEST_AUTH_SECRET))
+ assert(captor.getValue.sslRpcPasswordEnvs ===
+ Map(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD ->
TEST_RPC_SSL_KEY_STORE_PASSWORD))
+ }
+
test("creates deployments per resource profile and seeds deletion cost
annotation") {
val rpBuilder = new ResourceProfileBuilder()
val secondProfile = rpBuilder.build()
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorLifecycleTestUtils.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorLifecycleTestUtils.scala
index 272f41f30b58..1ebe1cddba8c 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorLifecycleTestUtils.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorLifecycleTestUtils.scala
@@ -22,14 +22,19 @@ import scala.jdk.CollectionConverters._
import io.fabric8.kubernetes.api.model._
+import org.apache.spark.{SparkConf, SSLOptions}
import org.apache.spark.deploy.k8s.Constants._
import org.apache.spark.deploy.k8s.SparkPod
+import org.apache.spark.internal.config.{AUTH_SECRET, NETWORK_AUTH_ENABLED}
import org.apache.spark.resource.ResourceProfile.DEFAULT_RESOURCE_PROFILE_ID
+import org.apache.spark.util.SparkConfWithEnv
object ExecutorLifecycleTestUtils {
val TEST_SPARK_APP_ID = "spark-app-id"
val TEST_SPARK_EXECUTOR_CONTAINER_NAME = "spark-executor"
+ val TEST_AUTH_SECRET = "authSecret"
+ val TEST_RPC_SSL_KEY_STORE_PASSWORD = "keyStorePass"
def failedExecutorWithoutDeletion(
executorId: Long, rpId: Int = DEFAULT_RESOURCE_PROFILE_ID): Pod = {
@@ -266,4 +271,14 @@ object ExecutorLifecycleTestUtils {
.endSpec()
.build()
}
+
+ /** Copy of `conf` with auth and RPC SSL enabled; the trust store password
is env-only. */
+ def confWithAuthAndSslRpc(conf: SparkConf): SparkConf = {
+ new SparkConfWithEnv(Map(SSLOptions.ENV_RPC_SSL_TRUST_STORE_PASSWORD ->
"envTrustStorePass"))
+ .setAll(conf.getAll)
+ .set(NETWORK_AUTH_ENABLED, true)
+ .set(AUTH_SECRET, TEST_AUTH_SECRET)
+ .set("spark.ssl.rpc.enabled", "true")
+ .set("spark.ssl.rpc.keyStorePassword", TEST_RPC_SSL_KEY_STORE_PASSWORD)
+ }
}
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala
index 5a4316553c8f..6232a8b73c11 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala
@@ -26,7 +26,7 @@ import scala.jdk.CollectionConverters._
import io.fabric8.kubernetes.api.model._
import io.fabric8.kubernetes.client.{KubernetesClient,
KubernetesClientException}
import io.fabric8.kubernetes.client.dsl.PodResource
-import org.mockito.{Mock, MockitoAnnotations}
+import org.mockito.{ArgumentCaptor, Mock, MockitoAnnotations}
import org.mockito.ArgumentMatchers.{any, anyString, eq => meq}
import org.mockito.Mockito.{clearInvocations, never, times, verify, when}
import org.mockito.invocation.InvocationOnMock
@@ -34,7 +34,7 @@ import org.mockito.stubbing.Answer
import org.scalatest.BeforeAndAfter
import org.scalatest.PrivateMethodTester._
-import org.apache.spark.{SecurityManager, SparkConf, SparkException,
SparkFunSuite}
+import org.apache.spark.{SecurityManager, SparkConf, SparkException,
SparkFunSuite, SSLOptions}
import org.apache.spark.deploy.k8s.{KubernetesExecutorConf,
KubernetesExecutorSpec}
import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
@@ -366,6 +366,22 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite
with BeforeAndAfter {
assert(m.contains("Exceed the pod creation limit: 1"))
}
+ test("SPARK-58776: executor conf carries the auth secret and SparkConf SSL
RPC passwords") {
+ val sslConf = confWithAuthAndSslRpc(conf)
+ val sslAllocator = new ExecutorPodsAllocator(sslConf, new
SecurityManager(sslConf),
+ executorBuilder, kubernetesClient, snapshotsStore,
waitForExecutorPodsClock)
+ sslAllocator.setExecutorPodsLifecycleManager(lifecycleManager)
+ sslAllocator.start(TEST_SPARK_APP_ID, schedulerBackend)
+ sslAllocator.setTotalExpectedExecutors(Map(defaultProfile -> 1))
+
+ val captor = ArgumentCaptor.forClass(classOf[KubernetesExecutorConf])
+ verify(executorBuilder).buildFromFeatures(
+ captor.capture(), meq(kubernetesClient), any(classOf[ResourceProfile]))
+ assert(captor.getValue.authSecret === Some(TEST_AUTH_SECRET))
+ assert(captor.getValue.sslRpcPasswordEnvs ===
+ Map(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD ->
TEST_RPC_SSL_KEY_STORE_PASSWORD))
+ }
+
test("Request executors in batches. Allow another batch to be requested if" +
" all pending executors start running.") {
val counter = PrivateMethod[AtomicInteger](Symbol("EXECUTOR_ID_COUNTER"))()
diff --git
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetAllocatorSuite.scala
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetAllocatorSuite.scala
index cac78d2631b6..12e459d2d431 100644
---
a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetAllocatorSuite.scala
+++
b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/StatefulSetAllocatorSuite.scala
@@ -27,7 +27,7 @@ import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.scalatest.BeforeAndAfter
-import org.apache.spark.{SecurityManager, SparkConf, SparkFunSuite}
+import org.apache.spark.{SecurityManager, SparkConf, SparkFunSuite, SSLOptions}
import org.apache.spark.deploy.k8s.{KubernetesExecutorConf,
KubernetesExecutorSpec}
import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
@@ -143,6 +143,21 @@ class StatefulSetAllocatorSuite extends SparkFunSuite with
BeforeAndAfter {
verify(driverPodOperations, never()).waitUntilReady(any(), any())
}
+ test("SPARK-58776: executor conf carries the auth secret and SparkConf SSL
RPC passwords") {
+ val sslConf = confWithAuthAndSslRpc(conf)
+ val sslAllocator = new StatefulSetPodsAllocator(sslConf, new
SecurityManager(sslConf),
+ executorBuilder, kubernetesClient, snapshotsStore, null)
+ sslAllocator.start(TEST_SPARK_APP_ID, schedulerBackend)
+ sslAllocator.setTotalExpectedExecutors(Map(defaultProfile -> 1))
+
+ val captor = ArgumentCaptor.forClass(classOf[KubernetesExecutorConf])
+ verify(executorBuilder).buildFromFeatures(
+ captor.capture(), meq(kubernetesClient), any(classOf[ResourceProfile]))
+ assert(captor.getValue.authSecret === Some(TEST_AUTH_SECRET))
+ assert(captor.getValue.sslRpcPasswordEnvs ===
+ Map(SSLOptions.ENV_RPC_SSL_KEY_STORE_PASSWORD ->
TEST_RPC_SSL_KEY_STORE_PASSWORD))
+ }
+
test("Validate initial statefulSet creation & cleanup with two resource
profiles") {
val rprof = new ResourceProfileBuilder()
val taskReq = new TaskResourceRequests().resource("gpu", 1)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]