Skip to content

Commit 6605b5f

Browse files
bdoyle0182Brendan Doyle
andauthored
add config to mask docker run args when logging (#5310)
Co-authored-by: Brendan Doyle <[email protected]>
1 parent 4007766 commit 6605b5f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

core/invoker/src/main/resources/application.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ whisk {
3333
# 0 means that there are infinite parallel runs.
3434
parallel-runs: 10
3535

36+
# hide args passed into docker run command when logging docker run command
37+
mask-docker-run-args: false
38+
3639
# Timeouts for docker commands. Set to "Inf" to disable timeout.
3740
timeouts {
3841
run: 1 minute

core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/docker/DockerClient.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ case class DockerClientTimeoutConfig(run: Duration,
6868
/**
6969
* Configuration for docker client
7070
*/
71-
case class DockerClientConfig(parallelRuns: Int, timeouts: DockerClientTimeoutConfig)
71+
case class DockerClientConfig(parallelRuns: Int, timeouts: DockerClientTimeoutConfig, maskDockerRunArgs: Boolean)
7272

7373
/**
7474
* Serves as interface to the docker CLI tool.
@@ -135,7 +135,10 @@ class DockerClient(dockerHost: Option[String] = None,
135135
}
136136
}.flatMap { _ =>
137137
// Iff the semaphore was acquired successfully
138-
runCmd(Seq("run", "-d") ++ args ++ Seq(image), config.timeouts.run)
138+
runCmd(
139+
Seq("run", "-d") ++ args ++ Seq(image),
140+
config.timeouts.run,
141+
if (config.maskDockerRunArgs) Some(Seq("run", "-d", "**ARGUMENTS HIDDEN**", image)) else None)
139142
.andThen {
140143
// Release the semaphore as quick as possible regardless of the runCmd() result
141144
case _ => runSemaphore.release()
@@ -200,12 +203,13 @@ class DockerClient(dockerHost: Option[String] = None,
200203
def isOomKilled(id: ContainerId)(implicit transid: TransactionId): Future[Boolean] =
201204
runCmd(Seq("inspect", id.asString, "--format", "{{.State.OOMKilled}}"), config.timeouts.inspect).map(_.toBoolean)
202205

203-
protected def runCmd(args: Seq[String], timeout: Duration)(implicit transid: TransactionId): Future[String] = {
206+
protected def runCmd(args: Seq[String], timeout: Duration, maskedArgs: Option[Seq[String]] = None)(
207+
implicit transid: TransactionId): Future[String] = {
204208
val cmd = dockerCmd ++ args
205209
val start = transid.started(
206210
this,
207211
LoggingMarkers.INVOKER_DOCKER_CMD(args.head),
208-
s"running ${cmd.mkString(" ")} (timeout: $timeout)",
212+
s"running ${maskedArgs.map(maskedArgs => (dockerCmd ++ maskedArgs).mkString(" ")).getOrElse(cmd.mkString(" "))} (timeout: $timeout)",
209213
logLevel = InfoLevel)
210214
executeProcess(cmd, timeout).andThen {
211215
case Success(_) => transid.finished(this, start)

core/standalone/src/main/scala/org/apache/openwhisk/standalone/StandaloneDockerSupport.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ class StandaloneDockerClient(pullDisabled: Boolean)(implicit log: Logging, as: A
211211
if (pullDisabled) Future.successful(()) else super.pull(image)
212212
}
213213

214-
override def runCmd(args: Seq[String], timeout: Duration)(implicit transid: TransactionId): Future[String] =
215-
super.runCmd(args, timeout)
214+
override def runCmd(args: Seq[String], timeout: Duration, maskedArgs: Option[Seq[String]] = None)(
215+
implicit transid: TransactionId): Future[String] =
216+
super.runCmd(args, timeout, maskedArgs)
216217

217218
val clientConfig: DockerClientConfig = loadConfigOrThrow[DockerClientConfig](ConfigKeys.dockerClient)
218219

0 commit comments

Comments
 (0)