Skip to content

Commit cf1ee2a

Browse files
authored
Merge pull request #24 from riptano/DSP-19490-dse-2
Dsp 19490 dse 2
2 parents 907cbcf + 0fef08a commit cf1ee2a

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

bin/server_package.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ else
3232
exit 1
3333
fi
3434

35+
set +u
36+
if [ -z "${SBT_BIN}" ]; then
37+
export SBT_BIN="sbt"
38+
fi
39+
set -u
40+
3541
echo Packaging job-server for environment $ENV...
3642

3743
cd $(dirname $0)/..
38-
sbt ++$SCALA_VERSION job-server-extras/assembly
44+
"$SBT_BIN" ++$SCALA_VERSION job-server-extras/assembly
3945
if [ "$?" != "0" ]; then
4046
echo "Assembly failed"
4147
exit 1

job-server/src/main/scala/spark/jobserver/JobServer.scala

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package spark.jobserver
22

3-
import akka.actor.{ActorSystem, ActorRef}
3+
import akka.actor.{ActorRef, ActorSystem}
44
import akka.actor.Props
55
import akka.pattern.ask
6-
import com.typesafe.config.{ConfigValueFactory, Config, ConfigFactory}
7-
6+
import com.typesafe.config.{Config, ConfigFactory, ConfigValueFactory}
87
import java.io.File
9-
import spark.jobserver.io.{BinaryType, JobDAOActor, JobDAO, DataFileDAO}
8+
9+
import spark.jobserver.io.{BinaryType, DataFileDAO, JobDAO, JobDAOActor}
1010
import org.slf4j.LoggerFactory
1111

1212
import scala.collection.JavaConverters._
1313
import scala.concurrent.{Await, ExecutionContext}
1414
import scala.concurrent.duration._
15+
import scala.util.matching.Regex
1516

1617
/**
1718
* The Spark Job Server is a web service that allows users to submit and run Spark jobs, check status,
@@ -31,7 +32,9 @@ import scala.concurrent.duration._
3132
*/
3233
object JobServer {
3334
val logger = LoggerFactory.getLogger(getClass)
34-
35+
final val DEFAULT_CREDENTIAL_KEYS = "credentials,password,secret,token"
36+
final val EMPTY_VALUE_PATTERN = "\"\",?".r
37+
final val CREDENTIAL_MASK = " \"xxx\""
3538
// Allow custom function to create ActorSystem. An example of why this is useful:
3639
// we can have something that stores the ActorSystem so it could be shut down easily later.
3740
def start(args: Array[String], makeSystem: Config => ActorSystem) {
@@ -46,8 +49,12 @@ object JobServer {
4649
} else {
4750
defaultConfig
4851
}
49-
logger.info("Starting JobServer with config {}", config.getConfig("spark").root.render())
50-
logger.info("Spray config: {}", config.getConfig("spray.can.server").root.render())
52+
53+
val credentialPattern = credentialRegex(config)
54+
val sparkConfig = config.getConfig("spark").root
55+
logger.info("Starting JobServer with config {}", maskCredentials(sparkConfig.render(), credentialPattern))
56+
val sprayConfig = config.getConfig("spray.can.server").root
57+
logger.info("Spray config: {}", maskCredentials(sprayConfig.render(), credentialPattern))
5158
val port = config.getInt("spark.jobserver.port")
5259

5360
// TODO: Hardcode for now to get going. Make it configurable later.
@@ -90,6 +97,36 @@ object JobServer {
9097
}
9198
}
9299

100+
private def maskCredentials(lines: String, credentialRegex: Regex): String = {
101+
lines
102+
.split("\n")
103+
.toSeq
104+
.map {
105+
line => line.split(":") match {
106+
// if key matches credential keys pattern and value is not empty, mask credentials
107+
case Array(key, value) if (credentialRegex.findFirstIn(key).nonEmpty
108+
&& EMPTY_VALUE_PATTERN.findFirstIn(value.stripMargin).isEmpty) =>
109+
Array(key, CREDENTIAL_MASK).mkString(":")
110+
case _ => line
111+
}
112+
}.mkString("\n")
113+
}
114+
115+
private def credentialRegex(config: Config): Regex = {
116+
// Use default credential keys if spark.ui.confidentialKeys is not set
117+
val credentialKeys = try {
118+
config.getString("spark.ui.confidentialKeys")
119+
} catch {
120+
case _: Exception =>
121+
logger.info(s"spark.ui.confidentialKeys is not set, " +
122+
s"use default credential keys $DEFAULT_CREDENTIAL_KEYS")
123+
DEFAULT_CREDENTIAL_KEYS
124+
}
125+
126+
// Case insensitive
127+
s"""(?i)(${credentialKeys.split(",").mkString("|")})" """.r
128+
}
129+
93130
private def parseInitialBinaryConfig(key: String, config: Config): Map[String, String] = {
94131
if (config.hasPath(key)) {
95132
val initialJarsConfig = config.getConfig(key).root

0 commit comments

Comments
 (0)