You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ma...@apache.org on 2018/07/31 11:42:20 UTC

[incubator-openwhisk] branch master updated: Manually create user log files with correct permissions. (#3903)

This is an automated email from the ASF dual-hosted git repository.

markusthoemmes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new bcd32ed  Manually create user log files with correct permissions. (#3903)
bcd32ed is described below

commit bcd32ed3549cd7b31ddc33c2de77fd597d456a8a
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Tue Jul 31 07:42:16 2018 -0400

    Manually create user log files with correct permissions. (#3903)
    
    Do not rely on LogRotatorSink to create user log files. Instead manually create the user log files with custom permissions.
---
 .../logging/DockerToActivationFileLogStore.scala      | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala b/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
index 0f3b440..e477696 100644
--- a/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
+++ b/common/scala/src/main/scala/whisk/core/containerpool/logging/DockerToActivationFileLogStore.scala
@@ -17,7 +17,9 @@
 
 package whisk.core.containerpool.logging
 
-import java.nio.file.{Path, Paths}
+import java.nio.file.{Files, Path, Paths}
+import java.nio.file.attribute.PosixFilePermission.{GROUP_READ, GROUP_WRITE, OTHERS_READ, OWNER_READ, OWNER_WRITE}
+import java.util.EnumSet
 import java.time.Instant
 
 import akka.NotUsed
@@ -75,6 +77,7 @@ class DockerToActivationFileLogStore(system: ActorSystem, destinationDirectory:
    * once the defined limit is reached.
    */
   val bufferSize = 100.MB
+  val perms = EnumSet.of(OWNER_READ, OWNER_WRITE, GROUP_READ, GROUP_WRITE, OTHERS_READ)
   protected val writeToFile: Sink[ByteString, _] = MergeHub
     .source[ByteString]
     .batchWeighted(bufferSize.toBytes, _.length, identity)(_ ++ _)
@@ -87,9 +90,17 @@ class DockerToActivationFileLogStore(system: ActorSystem, destinationDirectory:
             val size = element.size
             if (bytesRead + size > maxSize) {
               bytesRead = size
-              val newLogFile = destinationDirectory.resolve(s"userlogs-${Instant.now.toEpochMilli}.log")
-              logging.info(this, s"Rotating log file to '$newLogFile'")
-              Some(newLogFile)
+              val logFilePath = destinationDirectory.resolve(s"userlogs-${Instant.now.toEpochMilli}.log")
+              logging.info(this, s"Rotating log file to '$logFilePath'")
+              try {
+                Files.createFile(logFilePath)
+                Files.setPosixFilePermissions(logFilePath, perms)
+              } catch {
+                case t: Throwable =>
+                  logging.error(this, s"Couldn't create userlogs file: $t")
+                  throw t
+              }
+              Some(logFilePath)
             } else {
               bytesRead += size
               None