|
@@ -1,27 +1,28 @@
|
|
-package daemon // import "github.com/docker/docker/daemon"
|
|
|
|
|
|
+package oci // import "github.com/docker/docker/oci"
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
"regexp"
|
|
"regexp"
|
|
"strconv"
|
|
"strconv"
|
|
|
|
|
|
- "github.com/docker/docker/container"
|
|
|
|
- "github.com/docker/docker/daemon/caps"
|
|
|
|
|
|
+ "github.com/docker/docker/oci/caps"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
)
|
|
)
|
|
|
|
|
|
// nolint: gosimple
|
|
// nolint: gosimple
|
|
-var (
|
|
|
|
- deviceCgroupRuleRegex = regexp.MustCompile("^([acb]) ([0-9]+|\\*):([0-9]+|\\*) ([rwm]{1,3})$")
|
|
|
|
-)
|
|
|
|
|
|
+var deviceCgroupRuleRegex = regexp.MustCompile("^([acb]) ([0-9]+|\\*):([0-9]+|\\*) ([rwm]{1,3})$")
|
|
|
|
|
|
-func setCapabilities(s *specs.Spec, c *container.Container) error {
|
|
|
|
- var caplist []string
|
|
|
|
- var err error
|
|
|
|
- if c.HostConfig.Privileged {
|
|
|
|
|
|
+// SetCapabilities sets the provided capabilities on the spec
|
|
|
|
+// All capabilities are added if privileged is true
|
|
|
|
+func SetCapabilities(s *specs.Spec, add, drop []string, privileged bool) error {
|
|
|
|
+ var (
|
|
|
|
+ caplist []string
|
|
|
|
+ err error
|
|
|
|
+ )
|
|
|
|
+ if privileged {
|
|
caplist = caps.GetAllCapabilities()
|
|
caplist = caps.GetAllCapabilities()
|
|
} else {
|
|
} else {
|
|
- caplist, err = caps.TweakCapabilities(s.Process.Capabilities.Bounding, c.HostConfig.CapAdd, c.HostConfig.CapDrop)
|
|
|
|
|
|
+ caplist, err = caps.TweakCapabilities(s.Process.Capabilities.Bounding, add, drop)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -39,7 +40,8 @@ func setCapabilities(s *specs.Spec, c *container.Container) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func appendDevicePermissionsFromCgroupRules(devPermissions []specs.LinuxDeviceCgroup, rules []string) ([]specs.LinuxDeviceCgroup, error) {
|
|
|
|
|
|
+// AppendDevicePermissionsFromCgroupRules takes rules for the devices cgroup to append to the default set
|
|
|
|
+func AppendDevicePermissionsFromCgroupRules(devPermissions []specs.LinuxDeviceCgroup, rules []string) ([]specs.LinuxDeviceCgroup, error) {
|
|
for _, deviceCgroupRule := range rules {
|
|
for _, deviceCgroupRule := range rules {
|
|
ss := deviceCgroupRuleRegex.FindAllStringSubmatch(deviceCgroupRule, -1)
|
|
ss := deviceCgroupRuleRegex.FindAllStringSubmatch(deviceCgroupRule, -1)
|
|
if len(ss[0]) != 5 {
|
|
if len(ss[0]) != 5 {
|