From 7746fa7839dc6780379cb732c7122efaa07834f7 Mon Sep 17 00:00:00 2001
From: wangfengtu <wangfentu@huawei.com>
Date: Fri, 21 Dec 2018 15:02:16 +0800
Subject: [PATCH] runc:support specify umask

reason:support specify umask.
Umask can be 0022 or 0027(default) by specify umask when
start container by command `docker create/run` or start
daemon by command `dockerd`. For example:
$ dockerd --annotation native.umask=normal
$ dockerd --annotation native.umask=secure
$ docker run --exec-opt native.umask=normal
$ docker run --exec-opt native.umask=secure
`normal` reparent umask is 0022, `secure`
reparent umask is 0027.

Change-Id: I49166759ad42dca0ac1f9755f85592e93951c249
Signed-off-by: lujingxiao <lujingxiao@huawei.com>
Signed-off-by: wangfengtu <wangfengtu@huawei.com>
---
 libcontainer/rootfs_linux.go                             | 6 ++++++
 libcontainer/setns_init_linux.go                         | 7 +++++++
 vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go | 2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go
index 499d753..c42e388 100644
--- a/libcontainer/rootfs_linux.go
+++ b/libcontainer/rootfs_linux.go
@@ -192,6 +192,12 @@ func finalizeRootfs(config *configs.Config) (err error) {
 	} else {
 		unix.Umask(0o022)
 	}
+	umask := utils.SearchLabels(config.Labels, "native.umask")
+	if umask == "normal" {
+		unix.Umask(0o022)
+	} else {
+		unix.Umask(0o027)
+	}
 	return nil
 }
 
diff --git a/libcontainer/setns_init_linux.go b/libcontainer/setns_init_linux.go
index 09ab552..e9b8d62 100644
--- a/libcontainer/setns_init_linux.go
+++ b/libcontainer/setns_init_linux.go
@@ -14,6 +14,7 @@ import (
 	"github.com/opencontainers/runc/libcontainer/keys"
 	"github.com/opencontainers/runc/libcontainer/seccomp"
 	"github.com/opencontainers/runc/libcontainer/system"
+	"github.com/opencontainers/runc/libcontainer/utils"
 )
 
 // linuxSetnsInit performs the container's initialization for running a new process
@@ -54,6 +55,12 @@ func (l *linuxSetnsInit) Init() error {
 			return err
 		}
 	}
+        umask := utils.SearchLabels(l.config.Config.Labels, "native.umask")
+        if umask == "normal" {
+                unix.Umask(0o022)
+        } else {
+                unix.Umask(0o027)
+        }
 	if l.config.NoNewPrivileges {
 		if err := unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
 			return err
diff --git a/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go b/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go
index b6fa374..430f646 100644
--- a/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go
+++ b/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go
@@ -2,7 +2,7 @@ package logrus_syslog
 
 import (
 	"fmt"
-	"github.com/Sirupsen/logrus"
+	"github.com/sirupsen/logrus"
 	"log/syslog"
 	"os"
 )
-- 
2.33.0

