Skip to content

Commit

Permalink
MapR [SPARK-1108] Parallel jobs running causes errors with manageSSLK…
Browse files Browse the repository at this point in the history
…eys.sh (Permission denied) (apache#1049)

Co-authored-by: Egor Krivokon <>
  • Loading branch information
ekrivokonmapr committed Nov 6, 2023
1 parent f1744fa commit ee0f872
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions core/src/main/scala/org/apache/spark/SecurityManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import java.util.Base64

import scala.sys.process._
import scala.language.postfixOps

import org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.hadoop.io.Text
import org.apache.hadoop.security.{Credentials, UserGroupInformation}

import org.apache.spark.deploy.SparkHadoopUtil
import org.apache.spark.internal.Logging
import org.apache.spark.internal.config._
Expand All @@ -37,6 +35,9 @@ import org.apache.spark.launcher.SparkLauncher
import org.apache.spark.network.sasl.SecretKeyHolder
import org.apache.spark.util.Utils

import scala.annotation.tailrec
import scala.util.{Failure, Try}

/**
* Spark class responsible for security.
*
Expand Down Expand Up @@ -129,6 +130,22 @@ private[spark] class SecurityManager(
s"$sparkBase/spark-$sparkVersion"
}

@tailrec
private def genViaManageSSLScript(stdWriter: PrintWriter,
manageSslKeysScriptLocal: String,
sslKeyStorePass: String,
count: Int): Int = {
Try(s"$manageSslKeysScriptLocal $sslKeyStorePass" ! ProcessLogger(stdWriter println, stdWriter println)) match {
case Failure(_) =>
if (count == 0) -1 else {
logInfo("manageSSLKeys.sh script is busy, waiting...")
Thread.sleep(5000)
genViaManageSSLScript(stdWriter, manageSslKeysScriptLocal, sslKeyStorePass, count - 1)
}
case _ => 0
}
}

def genSSLCertsIfNeededAndPushToMapRFS(): Unit = {
if (isSSLCertGenerationNeededForWebUI(getSSLOptions("ui"))) {
val username = UserGroupInformation.getCurrentUser.getShortUserName
Expand All @@ -150,9 +167,8 @@ private[spark] class SecurityManager(
val localBaseDir = s"$currentUserHomeDir/__spark-internal__/security_keys"
val manageSslKeysScriptLocal = s"$localBaseDir/$certGeneratorName"

if (!fs.exists(new Path(manageSslKeysScriptLocal))) {
fs.copyToLocalFile(new Path(mfsManageSslKeysScriptRemote), new Path(manageSslKeysScriptLocal))
}
fs.copyToLocalFile(new Path(mfsManageSslKeysScriptRemote), new Path(manageSslKeysScriptLocal))

val manageSslKeysLocalFile = new File(manageSslKeysScriptLocal)

manageSslKeysLocalFile.setExecutable(true)
Expand All @@ -163,11 +179,7 @@ private[spark] class SecurityManager(
val stdStream = new OutputStreamWriter(new FileOutputStream(file), UTF_8)
val stdWriter = new PrintWriter(stdStream)

while (s"pgrep -fl $certGeneratorName".lineStream_!.nonEmpty) {
logInfo("manageSSLKeys.sh script is busy, waiting...")
Thread.sleep(5000)
}
val res = s"$manageSslKeysScriptLocal $sslKeyStorePass" ! ProcessLogger(stdWriter println, stdWriter println)
val res = genViaManageSSLScript(stdWriter, manageSslKeysScriptLocal, sslKeyStorePass, 10)
stdWriter.close()

val certGeneratorLogMfsLocation = s"/apps/spark/$certGeneratorLog"
Expand Down

0 comments on commit ee0f872

Please sign in to comment.