Skip to content

Commit 7c59e8e

Browse files
authored
Merge commit from fork
Fix directory permissions
2 parents 083b53c + 910171e commit 7c59e8e

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

cmd/containerd/server/server.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error {
8080
return errors.New("root and state must be different paths")
8181
}
8282

83-
if err := sys.MkdirAllWithACL(config.Root, 0o711); err != nil {
83+
if err := sys.MkdirAllWithACL(config.Root, 0o700); err != nil {
84+
return err
85+
}
86+
// chmod is needed for upgrading from an older release that created the dir with 0o711
87+
if err := os.Chmod(config.Root, 0o700); err != nil {
8488
return err
8589
}
8690

91+
// For supporting userns-remapped containers, the state dir cannot be just mkdired with 0o700.
92+
// Each of plugins creates a dedicated directory beneath the state dir with appropriate permission bits.
8793
if err := sys.MkdirAllWithACL(config.State, 0o711); err != nil {
8894
return err
8995
}
@@ -98,7 +104,11 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error {
98104
}
99105

100106
if config.TempDir != "" {
101-
if err := sys.MkdirAllWithACL(config.TempDir, 0o711); err != nil {
107+
if err := sys.MkdirAllWithACL(config.TempDir, 0o700); err != nil {
108+
return err
109+
}
110+
// chmod is needed for upgrading from an older release that created the dir with 0o711
111+
if err := os.Chmod(config.Root, 0o700); err != nil {
102112
return err
103113
}
104114
if runtime.GOOS == "windows" {

core/runtime/v2/task_manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ func init() {
9292
}
9393
root, state := ic.Properties[plugins.PropertyRootDir], ic.Properties[plugins.PropertyStateDir]
9494
for _, d := range []string{root, state} {
95+
// root: the parent of this directory is created as 0o700, not 0o711.
96+
// state: the parent of this directory is created as 0o711 too, so as to support userns-remapped containers.
9597
if err := os.MkdirAll(d, 0711); err != nil {
9698
return nil, err
9799
}

plugins/cri/runtime/plugin.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ func initCRIRuntime(ic *plugin.InitContext) (interface{}, error) {
7979
rootDir := filepath.Join(containerdRootDir, "io.containerd.grpc.v1.cri")
8080
containerdStateDir := filepath.Dir(ic.Properties[plugins.PropertyStateDir])
8181
stateDir := filepath.Join(containerdStateDir, "io.containerd.grpc.v1.cri")
82+
if err := os.MkdirAll(stateDir, 0o700); err != nil {
83+
return nil, err
84+
}
85+
// chmod is needed for upgrading from an older release that created the dir with 0o755
86+
if err := os.Chmod(stateDir, 0o700); err != nil {
87+
return nil, err
88+
}
8289
c := criconfig.Config{
8390
RuntimeConfig: *pluginConfig,
8491
ContainerdRootDir: containerdRootDir,

plugins/sandbox/controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ func init() {
6868
state := ic.Properties[plugins.PropertyStateDir]
6969
root := ic.Properties[plugins.PropertyRootDir]
7070
for _, d := range []string{root, state} {
71-
if err := os.MkdirAll(d, 0711); err != nil {
71+
if err := os.MkdirAll(d, 0700); err != nil {
72+
return nil, err
73+
}
74+
// chmod is needed for upgrading from an older release that created the dir with 0o711
75+
if err := os.Chmod(d, 0o700); err != nil {
7276
return nil, err
7377
}
7478
}

0 commit comments

Comments
 (0)