mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
lcow: Allow the client to add or remove capabilities
Signed-off-by: John Starks <jostarks@microsoft.com>
This commit is contained in:
parent
3f405c48ff
commit
349aeeab7c
4 changed files with 39 additions and 29 deletions
|
@ -1,5 +1,3 @@
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package caps // import "github.com/docker/docker/daemon/caps"
|
package caps // import "github.com/docker/docker/daemon/caps"
|
||||||
|
|
||||||
import (
|
import (
|
31
daemon/oci.go
Normal file
31
daemon/oci.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package daemon // import "github.com/docker/docker/daemon"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/docker/docker/container"
|
||||||
|
"github.com/docker/docker/daemon/caps"
|
||||||
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setCapabilities(s *specs.Spec, c *container.Container) error {
|
||||||
|
var caplist []string
|
||||||
|
var err error
|
||||||
|
if c.HostConfig.Privileged {
|
||||||
|
caplist = caps.GetAllCapabilities()
|
||||||
|
} else {
|
||||||
|
caplist, err = caps.TweakCapabilities(s.Process.Capabilities.Bounding, c.HostConfig.CapAdd, c.HostConfig.CapDrop)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Process.Capabilities.Effective = caplist
|
||||||
|
s.Process.Capabilities.Bounding = caplist
|
||||||
|
s.Process.Capabilities.Permitted = caplist
|
||||||
|
s.Process.Capabilities.Inheritable = caplist
|
||||||
|
// setUser has already been executed here
|
||||||
|
// if non root drop capabilities in the way execve does
|
||||||
|
if s.Process.User.UID != 0 {
|
||||||
|
s.Process.Capabilities.Effective = []string{}
|
||||||
|
s.Process.Capabilities.Permitted = []string{}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -13,7 +13,6 @@ import (
|
||||||
|
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/caps"
|
|
||||||
daemonconfig "github.com/docker/docker/daemon/config"
|
daemonconfig "github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/oci"
|
"github.com/docker/docker/oci"
|
||||||
"github.com/docker/docker/pkg/idtools"
|
"github.com/docker/docker/pkg/idtools"
|
||||||
|
@ -249,30 +248,6 @@ func setNamespace(s *specs.Spec, ns specs.LinuxNamespace) {
|
||||||
s.Linux.Namespaces = append(s.Linux.Namespaces, ns)
|
s.Linux.Namespaces = append(s.Linux.Namespaces, ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCapabilities(s *specs.Spec, c *container.Container) error {
|
|
||||||
var caplist []string
|
|
||||||
var err error
|
|
||||||
if c.HostConfig.Privileged {
|
|
||||||
caplist = caps.GetAllCapabilities()
|
|
||||||
} else {
|
|
||||||
caplist, err = caps.TweakCapabilities(s.Process.Capabilities.Bounding, c.HostConfig.CapAdd, c.HostConfig.CapDrop)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.Process.Capabilities.Effective = caplist
|
|
||||||
s.Process.Capabilities.Bounding = caplist
|
|
||||||
s.Process.Capabilities.Permitted = caplist
|
|
||||||
s.Process.Capabilities.Inheritable = caplist
|
|
||||||
// setUser has already been executed here
|
|
||||||
// if non root drop capabilities in the way execve does
|
|
||||||
if s.Process.User.UID != 0 {
|
|
||||||
s.Process.Capabilities.Effective = []string{}
|
|
||||||
s.Process.Capabilities.Permitted = []string{}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setNamespaces(daemon *Daemon, s *specs.Spec, c *container.Container) error {
|
func setNamespaces(daemon *Daemon, s *specs.Spec, c *container.Container) error {
|
||||||
userNS := false
|
userNS := false
|
||||||
// user
|
// user
|
||||||
|
|
|
@ -211,7 +211,9 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
|
||||||
if !system.LCOWSupported() {
|
if !system.LCOWSupported() {
|
||||||
return nil, fmt.Errorf("Linux containers on Windows are not supported")
|
return nil, fmt.Errorf("Linux containers on Windows are not supported")
|
||||||
}
|
}
|
||||||
daemon.createSpecLinuxFields(c, &s)
|
if err := daemon.createSpecLinuxFields(c, &s); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported platform %q", img.OS)
|
return nil, fmt.Errorf("Unsupported platform %q", img.OS)
|
||||||
}
|
}
|
||||||
|
@ -336,12 +338,16 @@ func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.S
|
||||||
// Sets the Linux-specific fields of the OCI spec
|
// Sets the Linux-specific fields of the OCI spec
|
||||||
// TODO: @jhowardmsft LCOW Support. We need to do a lot more pulling in what can
|
// TODO: @jhowardmsft LCOW Support. We need to do a lot more pulling in what can
|
||||||
// be pulled in from oci_linux.go.
|
// be pulled in from oci_linux.go.
|
||||||
func (daemon *Daemon) createSpecLinuxFields(c *container.Container, s *specs.Spec) {
|
func (daemon *Daemon) createSpecLinuxFields(c *container.Container, s *specs.Spec) error {
|
||||||
if len(s.Process.Cwd) == 0 {
|
if len(s.Process.Cwd) == 0 {
|
||||||
s.Process.Cwd = `/`
|
s.Process.Cwd = `/`
|
||||||
}
|
}
|
||||||
s.Root.Path = "rootfs"
|
s.Root.Path = "rootfs"
|
||||||
s.Root.Readonly = c.HostConfig.ReadonlyRootfs
|
s.Root.Readonly = c.HostConfig.ReadonlyRootfs
|
||||||
|
if err := setCapabilities(s, c); err != nil {
|
||||||
|
return fmt.Errorf("linux spec capabilities: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func escapeArgs(args []string) []string {
|
func escapeArgs(args []string) []string {
|
||||||
|
|
Loading…
Reference in a new issue