This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 2e38646ec05f [SPARK-57920][CORE][SQL][YARN] Use `Files.createTempFile`
to create temporary files with owner-only permissions
2e38646ec05f is described below
commit 2e38646ec05f463312bcac7f899b3b875ae847fd
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Fri Jul 3 03:20:55 2026 -0700
[SPARK-57920][CORE][SQL][YARN] Use `Files.createTempFile` to create
temporary files with owner-only permissions
This PR aims to use `java.nio.file.Files.createTempFile` instead of
`java.io.File.createTempFile` in the main source code (`Utils`, `yarn.Client`,
`PythonRDD`, `RowQueue`, `LogBlockWriter`, `StandaloneResourceUtils`) to create
temporary files with owner-only permissions (`600`) on POSIX file systems.
`File.createTempFile` creates files with umask-based default permissions
(typically `644`), while `Files.createTempFile` guarantees `600`. Some of these
temp files may contain sensitive data (fetched keytabs, YARN conf archives) and
are not always created under a `chmod 700` directory.
No functional change. On POSIX systems, these temporary files are now
created with owner-only permissions.
Pass the CIs.
Generated-by: Claude Fable 5
Closes #56982 from dongjoon-hyun/SPARK-57920.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit fae36fb978bb20ce2819b90782356b09833b7df8)
---
core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala | 3 ++-
.../scala/org/apache/spark/deploy/StandaloneResourceUtils.scala | 3 ++-
core/src/main/scala/org/apache/spark/util/Utils.scala | 4 ++--
.../yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala | 8 ++++----
.../scala/org/apache/spark/sql/execution/python/RowQueue.scala | 3 ++-
5 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
b/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
index d643983ef5df..b90d67ff1097 100644
--- a/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
+++ b/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
@@ -20,6 +20,7 @@ package org.apache.spark.api.python
import java.io._
import java.net._
import java.nio.charset.StandardCharsets
+import java.nio.file.Files
import java.util.{ArrayList => JArrayList, List => JList, Map => JMap}
import scala.collection.mutable
@@ -807,7 +808,7 @@ private[spark] class PythonBroadcast(@transient var path:
String) extends Serial
if (!diskBlockManager.containsBlock(blockId)) {
Utils.tryOrIOException {
val dir = new File(Utils.getLocalDir(SparkEnv.get.conf))
- val file = File.createTempFile("broadcast", "", dir)
+ val file = Files.createTempFile(dir.toPath, "broadcast", "").toFile
val out = new FileOutputStream(file)
Utils.tryWithSafeFinally {
val size = Utils.copyStream(in, out)
diff --git
a/core/src/main/scala/org/apache/spark/deploy/StandaloneResourceUtils.scala
b/core/src/main/scala/org/apache/spark/deploy/StandaloneResourceUtils.scala
index 7b98461b01ac..e272f796de27 100644
--- a/core/src/main/scala/org/apache/spark/deploy/StandaloneResourceUtils.scala
+++ b/core/src/main/scala/org/apache/spark/deploy/StandaloneResourceUtils.scala
@@ -109,7 +109,8 @@ private[spark] object StandaloneResourceUtils extends
Logging {
logError(errMsg, e)
throw new SparkException(errMsg.message, e)
}
- val resourcesFile = File.createTempFile(s"resource-$compShortName-",
".json", dir)
+ val resourcesFile = Files.createTempFile(dir.toPath,
s"resource-$compShortName-", ".json")
+ .toFile
tmpFile.renameTo(resourcesFile)
Some(resourcesFile)
}
diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala
b/core/src/main/scala/org/apache/spark/util/Utils.scala
index 3d7cfdfd98b9..e2603d735369 100644
--- a/core/src/main/scala/org/apache/spark/util/Utils.scala
+++ b/core/src/main/scala/org/apache/spark/util/Utils.scala
@@ -502,8 +502,8 @@ private[spark] object Utils
in: InputStream,
destFile: File,
fileOverwrite: Boolean): Unit = {
- val tempFile = File.createTempFile("fetchFileTemp", null,
- new File(destFile.getParentFile.getAbsolutePath))
+ val tempFile = Files.createTempFile(
+ new File(destFile.getParentFile.getAbsolutePath).toPath,
"fetchFileTemp", null).toFile
logInfo(log"Fetching ${MDC(LogKeys.URL, url)} to ${MDC(FILE_ABSOLUTE_PATH,
tempFile)}")
try {
diff --git
a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
index 8b621e82afe2..78e647599b70 100644
---
a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
+++
b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
@@ -709,8 +709,8 @@ private[spark] class Client(
log"libraries under SPARK_HOME.")
val jarsDir = new File(YarnCommandBuilderUtils.findJarsDir(
sparkConf.getenv("SPARK_HOME")))
- val jarsArchive = File.createTempFile(LOCALIZED_LIB_DIR, ".zip",
- new File(Utils.getLocalDir(sparkConf)))
+ val jarsArchive = Files.createTempFile(
+ Paths.get(Utils.getLocalDir(sparkConf)), LOCALIZED_LIB_DIR,
".zip").toFile
val jarsStream = new ZipOutputStream(new
FileOutputStream(jarsArchive))
try {
@@ -897,8 +897,8 @@ private[spark] class Client(
}
}
- val confArchive = File.createTempFile(LOCALIZED_CONF_DIR, ".zip",
- new File(Utils.getLocalDir(sparkConf)))
+ val confArchive = Files.createTempFile(
+ Paths.get(Utils.getLocalDir(sparkConf)), LOCALIZED_CONF_DIR,
".zip").toFile
val confStream = new ZipOutputStream(new FileOutputStream(confArchive))
logDebug(s"Creating an archive with the config files for distribution at
$confArchive.")
diff --git
a/sql/core/src/main/scala/org/apache/spark/sql/execution/python/RowQueue.scala
b/sql/core/src/main/scala/org/apache/spark/sql/execution/python/RowQueue.scala
index ce30a54c8d4e..7f48517d16c5 100644
---
a/sql/core/src/main/scala/org/apache/spark/sql/execution/python/RowQueue.scala
+++
b/sql/core/src/main/scala/org/apache/spark/sql/execution/python/RowQueue.scala
@@ -18,6 +18,7 @@
package org.apache.spark.sql.execution.python
import java.io._
+import java.nio.file.Files
import com.google.common.io.Closeables
@@ -221,7 +222,7 @@ private[python] case class HybridRowQueue(
}
private def createDiskQueue(): RowQueue = {
- DiskRowQueue(File.createTempFile("buffer", "", tempDir), numFields, serMgr)
+ DiskRowQueue(Files.createTempFile(tempDir.toPath, "buffer", "").toFile,
numFields, serMgr)
}
private def createNewQueue(required: Long): RowQueue = {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]