1
0
mirror of https://github.com/moby/moby.git synced 2025-07-29 07:21:35 +03:00

Capabilities refactor

- Add support for exact list of capabilities, support only OCI model
- Support OCI model on CapAdd and CapDrop but remain backward compatibility
- Create variable locally instead of declaring it at the top
- Use const for magic "ALL" value
- Rename `cap` variable as it overlaps with `cap()` built-in
- Normalize and validate capabilities before use
- Move validation for conflicting options to validateHostConfig()
- TweakCapabilities: simplify logic to calculate capabilities

Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Olli Janatuinen
2018-12-16 17:11:37 +02:00
parent 5ec31380a5
commit 80d7bfd54d
12 changed files with 281 additions and 84 deletions

View File

@ -1377,6 +1377,8 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
}
// regression #14318
// for backward compatibility testing with and without CAP_ prefix
// and with upper and lowercase
func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *check.C) {
// Windows doesn't support CapAdd/CapDrop
testRequires(c, DaemonIsLinux)
@ -1384,7 +1386,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che
Image string
CapAdd string
CapDrop string
}{"busybox", "NET_ADMIN", "SYS_ADMIN"}
}{"busybox", "NET_ADMIN", "cap_sys_admin"}
res, _, err := request.Post("/containers/create?name=capaddtest0", request.JSONBody(config))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
@ -1393,8 +1395,8 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che
Image: "busybox",
}
hostConfig := containertypes.HostConfig{
CapAdd: []string{"NET_ADMIN", "SYS_ADMIN"},
CapDrop: []string{"SETGID"},
CapAdd: []string{"net_admin", "SYS_ADMIN"},
CapDrop: []string{"SETGID", "CAP_SETPCAP"},
}
cli, err := client.NewClientWithOpts(client.FromEnv)