spark-test commented on code in PR #57796:
URL: https://github.com/apache/spark/pull/57796#discussion_r4508451766
##########
core/src/test/scala/org/apache/spark/deploy/master/MasterSuite.scala:
##########
@@ -293,4 +295,114 @@ class MasterSuite extends MasterSuiteBase {
makeMaster(conf)
}
}
+
+ test("SPARK-58592: redactedCopy redacts secrets in ApplicationInfo and
DriverInfo") {
+ val conf = new SparkConf()
+ val secretEnv = Map(
+ "PASSWORD" -> "topsecret",
+ "JAVA_HOME" -> "/usr/lib/jvm/default")
+ val secretJavaOpts = Seq(
+ "-Dspark.executorEnv.TOKEN=env-token",
+ "-Xmx2g")
+ val cmd = Command("mainClass", List("arg1"), secretEnv, Seq(), Seq(),
secretJavaOpts)
+
+ val appDesc = ApplicationDescription(
+ "name", Some(4), cmd, "appUiUrl", DeployTestUtils.defaultResourceProfile)
+ val appInfo = new ApplicationInfo(0, "app-1", appDesc, new Date(0), null,
Int.MaxValue)
+ appInfo.incrementRetryCount()
+ val redactedApp = appInfo.redactedCopy(conf)
+
assert(!redactedApp.desc.command.environment.values.exists(_.contains("topsecret")))
+ assert(redactedApp.desc.command.environment("PASSWORD") ==
Utils.REDACTION_REPLACEMENT_TEXT)
+ assert(redactedApp.desc.command.environment("JAVA_HOME") ==
"/usr/lib/jvm/default")
+ assert(redactedApp.desc.command.javaOpts.contains(
+ s"-Dspark.executorEnv.TOKEN=${Utils.REDACTION_REPLACEMENT_TEXT}"))
+ assert(redactedApp.desc.command.javaOpts.contains("-Xmx2g"))
+ assert(redactedApp.retryCount == 1)
+
+ val driverDesc = DriverDescription("hdfs://some.jar", 100, 3, false, cmd)
+ val driverInfo = new DriverInfo(0, "driver-1", driverDesc, new Date(0))
Review Comment:
**Nit (P3):** This fixture has start time 0 and no resources, and the copy
made on the next line is checked only for redaction. Apart from `retryCount`,
no new test compares a redacted copy's id, start time, submit date, driver ref
or resources with the original, before or after serialization. The copies carry
these fields today, but the tests would still pass after deleting
`copy.withResources(_resources)` in `DriverInfo.redactedCopy`, or after passing
0 instead of `startTime` in `ApplicationInfo.redactedCopy`, while remote
callers would receive drivers without their resources or applications with a
wrong start time.
The comments on both `redactedCopy` methods require every non-transient
field to be carried, and an earlier revision of this PR already dropped
`_retryCount`, so non-default fixture values with assertions on these fields
are what would catch the next omission.
See **Shared repair plan 1** in the review body.
##########
core/src/main/scala/org/apache/spark/deploy/DeployMessage.scala:
##########
@@ -292,6 +293,29 @@ private[deploy] object DeployMessages {
def uri: String = "spark://" + host + ":" + port
def restUri: Option[String] = restPort.map { p => "spark://" + host + ":"
+ p }
+
+ // Must be called before sending the response so writeReplace redacts
secrets.
Review Comment:
**Nit (P3):** "Must be called before sending the response" sits on the
`_conf` field, which cannot be called; the call it means is `withConf`, which
the comment never names. This is the only in-code statement that a reply must
attach the Master's conf, and `writeReplace` returns the response unredacted
when none is attached, so a maintainer adding another `MasterStateResponse`
reply site could miss the call and send plaintext secrets. Naming `withConf`
makes the obligation explicit:
```suggestion
// withConf must be called before sending the response so writeReplace
redacts secrets.
```
**Verification:**
- **Inspection:** The comment on the master state response's redaction
members names withConf as the call required before the response is sent, and
states that writeReplace falls back to the unredacted object only when no conf
is attached.
##########
core/src/test/scala/org/apache/spark/deploy/master/MasterSuite.scala:
##########
@@ -293,4 +295,114 @@ class MasterSuite extends MasterSuiteBase {
makeMaster(conf)
}
}
+
+ test("SPARK-58592: redactedCopy redacts secrets in ApplicationInfo and
DriverInfo") {
+ val conf = new SparkConf()
+ val secretEnv = Map(
+ "PASSWORD" -> "topsecret",
+ "JAVA_HOME" -> "/usr/lib/jvm/default")
+ val secretJavaOpts = Seq(
+ "-Dspark.executorEnv.TOKEN=env-token",
+ "-Xmx2g")
+ val cmd = Command("mainClass", List("arg1"), secretEnv, Seq(), Seq(),
secretJavaOpts)
+
+ val appDesc = ApplicationDescription(
+ "name", Some(4), cmd, "appUiUrl", DeployTestUtils.defaultResourceProfile)
+ val appInfo = new ApplicationInfo(0, "app-1", appDesc, new Date(0), null,
Int.MaxValue)
+ appInfo.incrementRetryCount()
+ val redactedApp = appInfo.redactedCopy(conf)
+
assert(!redactedApp.desc.command.environment.values.exists(_.contains("topsecret")))
+ assert(redactedApp.desc.command.environment("PASSWORD") ==
Utils.REDACTION_REPLACEMENT_TEXT)
+ assert(redactedApp.desc.command.environment("JAVA_HOME") ==
"/usr/lib/jvm/default")
+ assert(redactedApp.desc.command.javaOpts.contains(
+ s"-Dspark.executorEnv.TOKEN=${Utils.REDACTION_REPLACEMENT_TEXT}"))
+ assert(redactedApp.desc.command.javaOpts.contains("-Xmx2g"))
+ assert(redactedApp.retryCount == 1)
+
+ val driverDesc = DriverDescription("hdfs://some.jar", 100, 3, false, cmd)
+ val driverInfo = new DriverInfo(0, "driver-1", driverDesc, new Date(0))
+ val redactedDriver = driverInfo.redactedCopy(conf)
+
assert(!redactedDriver.desc.command.environment.values.exists(_.contains("topsecret")))
+ assert(redactedDriver.desc.command.environment("PASSWORD") ==
Utils.REDACTION_REPLACEMENT_TEXT)
+ assert(redactedDriver.desc.command.environment("JAVA_HOME") ==
"/usr/lib/jvm/default")
+ assert(redactedDriver.desc.command.javaOpts.contains(
+ s"-Dspark.executorEnv.TOKEN=${Utils.REDACTION_REPLACEMENT_TEXT}"))
+ assert(redactedDriver.desc.command.javaOpts.contains("-Xmx2g"))
+ }
+
+ test("SPARK-58592: writeReplace redacts secrets during RPC serialization") {
+ val conf = new SparkConf()
+ val secretEnv = Map("PASSWORD" -> "topsecret", "JAVA_HOME" ->
"/usr/lib/jvm/default")
+ val secretJavaOpts = Seq("-Dspark.executorEnv.TOKEN=env-token", "-Xmx2g")
+ val cmd = Command("mainClass", List("arg1"), secretEnv, Seq(), Seq(),
secretJavaOpts)
+ val appDesc = ApplicationDescription(
+ "name", Some(4), cmd, "appUiUrl", DeployTestUtils.defaultResourceProfile)
+ val appInfo = new ApplicationInfo(0, "app-1", appDesc, new Date(0), null,
Int.MaxValue)
+ appInfo.incrementRetryCount()
+ val driverDesc = DriverDescription("hdfs://some.jar", 100, 3, false, cmd)
+ val driverInfo = new DriverInfo(0, "driver-1", driverDesc, new Date(0))
+
+ val stateResponse = new MasterStateResponse(
Review Comment:
**Nit (P3):** This test builds the `MasterStateResponse` itself and attaches
the conf with `withConf(conf)`, so it never runs the Master's
`RequestMasterState` handler or a real RPC reply. The other new tests do the
same or call `redactedCopy` directly, and every existing `RequestMasterState`
ask in the suites either goes through `master.self.askSync`, which Netty RPC
delivers in-process without serializing the reply, or uses a mocked endpoint
ref. The fixtures also use the default `spark.redaction.regex`, which already
matches `PASSWORD` and `spark.executorEnv.TOKEN`, and always leave the
completed lists empty.
The production path is correct today, but nothing would catch a regression
in it: deleting `.withConf(conf)` at `Master.scala:522`, passing
`completedApps` or `completedDrivers` through unredacted in `writeReplace`, or
redacting with a fresh `SparkConf` instead of the Master's would all leave the
suite green while remote callers again receive plaintext `Command.environment`
and `javaOpts`. Asking a running Master for its state from a separate `RpcEnv`
would exercise that path.
See **Shared repair plan 1** in the review body.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]