Skip to content

Commit a63f99f

Browse files
giuseppeashley-cui
authored andcommitted
Add support for umask
Signed-off-by: Ashley Cui <[email protected]>
1 parent e949339 commit a63f99f

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

libcontainer/configs/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ type Config struct {
9292
// Path to a directory containing the container's root filesystem.
9393
Rootfs string `json:"rootfs"`
9494

95+
// Umask is the umask to use inside of the container.
96+
Umask *uint32 `json:"umask"`
97+
9598
// Readonlyfs will remount the container's rootfs as readonly where only externally mounted
9699
// bind mounts are writtable.
97100
Readonlyfs bool `json:"readonlyfs"`

libcontainer/rootfs_linux.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ func finalizeRootfs(config *configs.Config) (err error) {
157157
}
158158
}
159159

160-
unix.Umask(0022)
160+
if config.Umask != nil {
161+
unix.Umask(int(*config.Umask))
162+
} else {
163+
unix.Umask(0022)
164+
}
161165
return nil
162166
}
163167

libcontainer/specconv/spec_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
308308
if spec.Process != nil {
309309
config.OomScoreAdj = spec.Process.OOMScoreAdj
310310
config.NoNewPrivileges = spec.Process.NoNewPrivileges
311+
config.Umask = spec.Process.User.Umask
311312
if spec.Process.SelinuxLabel != "" {
312313
config.ProcessLabel = spec.Process.SelinuxLabel
313314
}

tests/integration/umask.bats

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
teardown_busybox
7+
setup_busybox
8+
}
9+
10+
function teardown() {
11+
teardown_busybox
12+
}
13+
14+
@test "umask" {
15+
update_config '.process.user += {"umask":63}'
16+
17+
# run busybox detached
18+
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
19+
[ "$status" -eq 0 ]
20+
21+
runc exec test_busybox grep '^Umask:' "/proc/1/status"
22+
[ "$status" -eq 0 ]
23+
# umask 63 decimal = umask 77 octal
24+
[[ "${output}" == *"77"* ]]
25+
}

0 commit comments

Comments
 (0)