Add support for Umask

Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
Ashley Cui 2020-07-14 15:54:22 -04:00
parent d81c776fa7
commit 93a6847b2d
8 changed files with 61 additions and 0 deletions

View File

@ -202,6 +202,9 @@ the system uses `65536k`.
`tz="local"`
`tz="America/New_York"`
**umask**="0022"
Sets umask inside the container.
**utsns**="private"
Default way to to create a UTS namespace for the container.
Options are:

View File

@ -168,6 +168,9 @@ type ContainersConfig struct {
//TZ sets the timezone inside the container
TZ string `toml:"tz,omitempty"`
// Umask is the umask inside the container.
Umask string `toml:"umask,omitempty"`
// UTSNS indicates how to create a UTS namespace for the container
UTSNS string `toml:"utsns,omitempty"`
@ -582,6 +585,10 @@ func (c *ContainersConfig) Validate() error {
return err
}
if err := c.validateUmask(); err != nil {
return err
}
if c.LogSizeMax >= 0 && c.LogSizeMax < OCIBufSize {
return fmt.Errorf("log size max should be negative or >= %d", OCIBufSize)
}

View File

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"syscall"
units "github.com/docker/go-units"
@ -88,6 +89,14 @@ func (c *ContainersConfig) validateTZ() error {
return nil
}
func (c *ContainersConfig) validateUmask() error {
validUmask := regexp.MustCompile(`^[0-7]{1,4}$`)
if !validUmask.MatchString(c.Umask) {
return fmt.Errorf("Not a valid Umask %s", c.Umask)
}
return nil
}
func isRemote() bool {
return false
}

View File

@ -277,4 +277,30 @@ var _ = Describe("Config Local", func() {
gomega.Expect(err).To(gomega.BeNil())
defer os.Remove(tmpfile)
})
It("Default Umask", func() {
// Given
// When
config, err := NewConfig("")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Containers.Umask).To(gomega.Equal("0022"))
})
It("Set Umask", func() {
// Given
// When
config, err := NewConfig("testdata/containers_default.conf")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Containers.Umask).To(gomega.Equal("0002"))
})
It("Should fail on bad Umask", func() {
// Given
sut.Containers.Umask = "88888"
// When
err := sut.Containers.Validate()
// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})
})

View File

@ -27,3 +27,7 @@ func (c *ContainersConfig) validateUlimits() error {
func (c *ContainersConfig) validateTZ() error {
return nil
}
func (c *ContainersConfig) validateUmask() error {
return nil
}

View File

@ -210,6 +210,10 @@
#
# tz = ""
# Set umask inside the container
#
# umask="0022"
# Default way to to create a UTS namespace for the container
# Options are:
# `private` Create private UTS Namespace for the container.

View File

@ -191,6 +191,7 @@ func DefaultConfig() (*Config, error) {
SeccompProfile: SeccompDefaultPath,
ShmSize: DefaultShmSize,
TZ: "",
Umask: "0022",
UTSNS: "private",
UserNS: "host",
UserNSSize: DefaultUserNSSize,
@ -504,3 +505,7 @@ func (c *Config) DetachKeys() string {
func (c *Config) TZ() string {
return c.Containers.TZ
}
func (c *Config) Umask() string {
return c.Containers.Umask
}

View File

@ -88,6 +88,9 @@ pids_limit = 2048
# Unit is optional and can be b (bytes), k (kilobytes), m (megabytes), or g (gigabytes). If the unit is omitted, the system uses bytes.
shm_size = "65536k"
#Umask inside the container
umask="0002"
# The network table containers settings pertaining to the management of
# CNI plugins.
[network]