Skip to content

Commit

Permalink
Merge pull request moby#7062 from crosbymichael/fix-lxc-caps
Browse files Browse the repository at this point in the history
Fix cap drop issues with lxc
  • Loading branch information
vieux committed Jul 28, 2014
2 parents a0dad3d + 50b580c commit ac3eecf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions daemon/execdriver/lxc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
}

if len(c.CapAdd) > 0 {
params = append(params, "-cap-add", strings.Join(c.CapAdd, " "))
params = append(params, fmt.Sprintf("-cap-add=%s", strings.Join(c.CapAdd, ":")))
}

if len(c.CapDrop) > 0 {
params = append(params, "-cap-drop", strings.Join(c.CapDrop, " "))
params = append(params, fmt.Sprintf("-cap-drop=%s", strings.Join(c.CapDrop, ":")))
}

params = append(params, "--", c.Entrypoint)
Expand Down
14 changes: 13 additions & 1 deletion daemon/execdriver/lxc/lxc_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ func finalizeNamespace(args *execdriver.InitArgs) error {
return fmt.Errorf("clear keep caps %s", err)
}

caps, err := execdriver.TweakCapabilities(container.Capabilities, strings.Split(args.CapAdd, " "), strings.Split(args.CapDrop, " "))
var (
adds []string
drops []string
)

if args.CapAdd != "" {
adds = strings.Split(args.CapAdd, ":")
}
if args.CapDrop != "" {
drops = strings.Split(args.CapDrop, ":")
}

caps, err := execdriver.TweakCapabilities(container.Capabilities, adds, drops)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/execdriver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TweakCapabilities(basics, adds, drops []string) ([]string, error) {
continue
}
if !utils.StringsContainsNoCase(allCaps, cap) {
return nil, fmt.Errorf("Unknown capability: %s", cap)
return nil, fmt.Errorf("Unknown capability drop: %q", cap)
}
}

Expand Down Expand Up @@ -49,15 +49,15 @@ func TweakCapabilities(basics, adds, drops []string) ([]string, error) {
continue
}

// look for invalid cap in the drop list
if !utils.StringsContainsNoCase(allCaps, cap) {
return nil, fmt.Errorf("Unknown capability: %s", cap)
return nil, fmt.Errorf("Unknown capability to add: %q", cap)
}

// add cap if not already in the list
if !utils.StringsContainsNoCase(newCaps, cap) {
newCaps = append(newCaps, strings.ToUpper(cap))
}
}

return newCaps, nil
}

0 comments on commit ac3eecf

Please sign in to comment.