@@ -26,6 +26,7 @@ import (
2626 "github.com/containers/libpod/utils"
2727 pmount "github.com/containers/storage/pkg/mount"
2828 "github.com/coreos/go-systemd/activation"
29+ "github.com/docker/docker/oci/caps"
2930 spec "github.com/opencontainers/runtime-spec/specs-go"
3031 "github.com/opencontainers/selinux/go-selinux"
3132 "github.com/opencontainers/selinux/go-selinux/label"
@@ -523,7 +524,7 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
523524 finalEnv = append (finalEnv , fmt .Sprintf ("%s=%s" , k , v ))
524525 }
525526
526- processFile , err := prepareProcessExec (c , options .Cmd , finalEnv , options .Terminal , options .Cwd , options .User , sessionID )
527+ processFile , err := prepareProcessExec (c , options .Cmd , finalEnv , options .Terminal , options .Cwd , options .User , sessionID , options . Privileged )
527528 if err != nil {
528529 return - 1 , nil , err
529530 }
@@ -538,10 +539,6 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
538539 args = append (args , formatRuntimeOpts ("--preserve-fds" , fmt .Sprintf ("%d" , options .PreserveFDs ))... )
539540 }
540541
541- for _ , capability := range options .CapAdd {
542- args = append (args , formatRuntimeOpts ("--cap" , capability )... )
543- }
544-
545542 if options .Terminal {
546543 args = append (args , "-t" )
547544 }
@@ -1041,12 +1038,15 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
10411038
10421039// prepareProcessExec returns the path of the process.json used in runc exec -p
10431040// caller is responsible to close the returned *os.File if needed.
1044- func prepareProcessExec (c * Container , cmd , env []string , tty bool , cwd , user , sessionID string ) (* os.File , error ) {
1041+ func prepareProcessExec (c * Container , cmd , env []string , tty bool , cwd , user , sessionID string , privileged bool ) (* os.File , error ) {
10451042 f , err := ioutil .TempFile (c .execBundlePath (sessionID ), "exec-process-" )
10461043 if err != nil {
10471044 return nil , err
10481045 }
1049- pspec := c .config .Spec .Process
1046+ pspec := new (spec.Process )
1047+ if err := JSONDeepCopy (c .config .Spec .Process , pspec ); err != nil {
1048+ return nil , err
1049+ }
10501050 pspec .SelinuxLabel = c .config .ProcessLabel
10511051 pspec .Args = cmd
10521052 // We need to default this to false else it will inherit terminal as true
@@ -1103,6 +1103,23 @@ func prepareProcessExec(c *Container, cmd, env []string, tty bool, cwd, user, se
11031103 pspec .User = processUser
11041104 }
11051105
1106+ allCaps := caps .GetAllCapabilities ()
1107+ pspec .Capabilities .Effective = []string {}
1108+ if privileged {
1109+ pspec .Capabilities .Bounding = allCaps
1110+ } else {
1111+ pspec .Capabilities .Bounding = []string {}
1112+ }
1113+ pspec .Capabilities .Inheritable = pspec .Capabilities .Bounding
1114+ if execUser .Uid == 0 {
1115+ pspec .Capabilities .Effective = pspec .Capabilities .Bounding
1116+ pspec .Capabilities .Permitted = pspec .Capabilities .Bounding
1117+ pspec .Capabilities .Ambient = pspec .Capabilities .Bounding
1118+ } else {
1119+ pspec .Capabilities .Permitted = pspec .Capabilities .Effective
1120+ pspec .Capabilities .Ambient = pspec .Capabilities .Effective
1121+ }
1122+
11061123 hasHomeSet := false
11071124 for _ , s := range pspec .Env {
11081125 if strings .HasPrefix (s , "HOME=" ) {
0 commit comments