mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon/&container/: enable --security-opt writable-cgroups=true as an option
Fixes #42040 Closes #42043 Rather than making cgroups read-write by default, instead have a flag for making it possible. Since these security options are passed through the cli to daemon API, no changes are needed to docker-cli. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
committed by
Tianon Gravi
parent
033f97519c
commit
e3cdd59a82
@@ -127,6 +127,7 @@ type SecurityOptions struct {
|
||||
AppArmorProfile string
|
||||
SeccompProfile string
|
||||
NoNewPrivileges bool
|
||||
WritableCgroups bool
|
||||
}
|
||||
|
||||
type localLogCacheMeta struct {
|
||||
|
||||
@@ -251,6 +251,12 @@ func parseSecurityOpt(securityOptions *container.SecurityOptions, config *contai
|
||||
return fmt.Errorf("invalid --security-opt 2: %q", opt)
|
||||
}
|
||||
securityOptions.NoNewPrivileges = nnp
|
||||
case "writable-cgroups":
|
||||
writableCgroups, err := strconv.ParseBool(v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid --security-opt 2: %q", opt)
|
||||
}
|
||||
securityOptions.WritableCgroups = writableCgroups
|
||||
default:
|
||||
return fmt.Errorf("invalid --security-opt 2: %q", opt)
|
||||
}
|
||||
|
||||
@@ -161,6 +161,13 @@ func TestParseSecurityOpt(t *testing.T) {
|
||||
})
|
||||
assert.Error(t, err, `invalid --security-opt 2: "unknown=something"`)
|
||||
})
|
||||
t.Run("invalid cgroup option", func(t *testing.T) {
|
||||
secOpts := &container.SecurityOptions{}
|
||||
err := parseSecurityOpt(secOpts, &containertypes.HostConfig{
|
||||
SecurityOpt: []string{"writable-cgroups=dang"},
|
||||
})
|
||||
assert.Error(t, err, `invalid --security-opt 2: "writable-cgroups=dang"`)
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseNNPSecurityOptions(t *testing.T) {
|
||||
|
||||
@@ -666,7 +666,7 @@ func withMounts(daemon *Daemon, daemonCfg *configStore, c *container.Container,
|
||||
|
||||
// TODO: until a kernel/mount solution exists for handling remount in a user namespace,
|
||||
// we must clear the readonly flag for the cgroups mount (@mrunalp concurs)
|
||||
if uidMap := daemon.idMapping.UIDMaps; uidMap != nil || c.HostConfig.Privileged {
|
||||
if uidMap := daemon.idMapping.UIDMaps; uidMap != nil || c.HostConfig.Privileged || c.WritableCgroups {
|
||||
for i, m := range s.Mounts {
|
||||
if m.Type == "cgroup" {
|
||||
clearReadOnly(&s.Mounts[i])
|
||||
|
||||
Reference in New Issue
Block a user