Skip to content

Commit 6034c19

Browse files
author
John Howard
committed
Windows:Create root/state with ACL
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent ceba568 commit 6034c19

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

services/server/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
srvconfig "github.com/containerd/containerd/services/server/config"
4444
"github.com/containerd/containerd/snapshots"
4545
ssproxy "github.com/containerd/containerd/snapshots/proxy"
46+
"github.com/containerd/containerd/sys"
4647
metrics "github.com/docker/go-metrics"
4748
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
4849
"github.com/pkg/errors"
@@ -61,10 +62,10 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error {
6162
return errors.New("root and state must be different paths")
6263
}
6364

64-
if err := os.MkdirAll(config.Root, 0711); err != nil {
65+
if err := sys.MkdirAllWithACL(config.Root, 0711); err != nil {
6566
return err
6667
}
67-
if err := os.MkdirAll(config.State, 0711); err != nil {
68+
if err := sys.MkdirAllWithACL(config.State, 0711); err != nil {
6869
return err
6970
}
7071
return nil

sys/filesys_unix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ import "os"
2424
func ForceRemoveAll(path string) error {
2525
return os.RemoveAll(path)
2626
}
27+
28+
// MkdirAllWithACL is a wrapper for os.MkdirAll on Unix systems.
29+
func MkdirAllWithACL(path string, perm os.FileMode) error {
30+
return os.MkdirAll(path, perm)
31+
}

sys/filesys_windows.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import (
3030
"github.com/Microsoft/hcsshim"
3131
)
3232

33+
const (
34+
// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System
35+
SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
36+
)
37+
3338
// MkdirAllWithACL is a wrapper for MkdirAll that creates a directory
3439
// ACL'd for Builtin Administrators and Local System.
3540
func MkdirAllWithACL(path string, perm os.FileMode) error {
@@ -78,7 +83,7 @@ func mkdirall(path string, adminAndLocalSystem bool) error {
7883

7984
if j > 1 {
8085
// Create parent
81-
err = mkdirall(path[0:j-1], false)
86+
err = mkdirall(path[0:j-1], adminAndLocalSystem)
8287
if err != nil {
8388
return err
8489
}
@@ -112,8 +117,7 @@ func mkdirall(path string, adminAndLocalSystem bool) error {
112117
// and Local System.
113118
func mkdirWithACL(name string) error {
114119
sa := syscall.SecurityAttributes{Length: 0}
115-
sddl := "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
116-
sd, err := winio.SddlToSecurityDescriptor(sddl)
120+
sd, err := winio.SddlToSecurityDescriptor(SddlAdministratorsLocalSystem)
117121
if err != nil {
118122
return &os.PathError{Op: "mkdir", Path: name, Err: err}
119123
}

0 commit comments

Comments
 (0)