Skip to content

Commit 1aa6a90

Browse files
Merge pull request #223 from ashley-cui/umask
Add support for Umask
2 parents 06f5832 + 13f6615 commit 1aa6a90

File tree

8 files changed

+61
-0
lines changed

8 files changed

+61
-0
lines changed

docs/containers.conf.5.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ the system uses `65536k`.
202202
`tz="local"`
203203
`tz="America/New_York"`
204204

205+
**umask**="0022"
206+
Sets umask inside the container.
207+
205208
**utsns**="private"
206209
Default way to to create a UTS namespace for the container.
207210
Options are:

pkg/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ type ContainersConfig struct {
168168
// TZ sets the timezone inside the container
169169
TZ string `toml:"tz,omitempty"`
170170

171+
// Umask is the umask inside the container.
172+
Umask string `toml:"umask,omitempty"`
173+
171174
// UTSNS indicates how to create a UTS namespace for the container
172175
UTSNS string `toml:"utsns,omitempty"`
173176

@@ -599,6 +602,10 @@ func (c *ContainersConfig) Validate() error {
599602
return err
600603
}
601604

605+
if err := c.validateUmask(); err != nil {
606+
return err
607+
}
608+
602609
if c.LogSizeMax >= 0 && c.LogSizeMax < OCIBufSize {
603610
return fmt.Errorf("log size max should be negative or >= %d", OCIBufSize)
604611
}

pkg/config/config_local.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"regexp"
910
"syscall"
1011

1112
units "github.com/docker/go-units"
@@ -88,6 +89,14 @@ func (c *ContainersConfig) validateTZ() error {
8889
return nil
8990
}
9091

92+
func (c *ContainersConfig) validateUmask() error {
93+
validUmask := regexp.MustCompile(`^[0-7]{1,4}$`)
94+
if !validUmask.MatchString(c.Umask) {
95+
return fmt.Errorf("Not a valid Umask %s", c.Umask)
96+
}
97+
return nil
98+
}
99+
91100
func isRemote() bool {
92101
return false
93102
}

pkg/config/config_local_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,30 @@ var _ = Describe("Config Local", func() {
277277
gomega.Expect(err).To(gomega.BeNil())
278278
defer os.Remove(tmpfile)
279279
})
280+
It("Default Umask", func() {
281+
// Given
282+
// When
283+
config, err := NewConfig("")
284+
// Then
285+
gomega.Expect(err).To(gomega.BeNil())
286+
gomega.Expect(config.Containers.Umask).To(gomega.Equal("0022"))
287+
})
288+
It("Set Umask", func() {
289+
// Given
290+
// When
291+
config, err := NewConfig("testdata/containers_default.conf")
292+
// Then
293+
gomega.Expect(err).To(gomega.BeNil())
294+
gomega.Expect(config.Containers.Umask).To(gomega.Equal("0002"))
295+
})
296+
It("Should fail on bad Umask", func() {
297+
// Given
298+
sut.Containers.Umask = "88888"
299+
300+
// When
301+
err := sut.Containers.Validate()
302+
303+
// Then
304+
gomega.Expect(err).NotTo(gomega.BeNil())
305+
})
280306
})

pkg/config/config_remote.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ func (c *ContainersConfig) validateUlimits() error {
2727
func (c *ContainersConfig) validateTZ() error {
2828
return nil
2929
}
30+
31+
func (c *ContainersConfig) validateUmask() error {
32+
return nil
33+
}

pkg/config/containers.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@
210210
#
211211
# tz = ""
212212

213+
# Set umask inside the container
214+
#
215+
# umask="0022"
216+
213217
# Default way to to create a UTS namespace for the container
214218
# Options are:
215219
# `private` Create private UTS Namespace for the container.

pkg/config/default.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func DefaultConfig() (*Config, error) {
191191
SeccompProfile: SeccompDefaultPath,
192192
ShmSize: DefaultShmSize,
193193
TZ: "",
194+
Umask: "0022",
194195
UTSNS: "private",
195196
UserNS: "host",
196197
UserNSSize: DefaultUserNSSize,
@@ -504,3 +505,7 @@ func (c *Config) DetachKeys() string {
504505
func (c *Config) TZ() string {
505506
return c.Containers.TZ
506507
}
508+
509+
func (c *Config) Umask() string {
510+
return c.Containers.Umask
511+
}

pkg/config/testdata/containers_default.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ pids_limit = 2048
8888
# Unit is optional and can be b (bytes), k (kilobytes), m (megabytes), or g (gigabytes). If the unit is omitted, the system uses bytes.
8989
shm_size = "65536k"
9090

91+
#Umask inside the container
92+
umask="0002"
93+
9194
# The network table containers settings pertaining to the management of
9295
# CNI plugins.
9396
[network]

0 commit comments

Comments
 (0)