@@ -26,6 +26,7 @@ import (
26
26
"github.com/containers/libpod/utils"
27
27
pmount "github.com/containers/storage/pkg/mount"
28
28
"github.com/coreos/go-systemd/activation"
29
+ "github.com/docker/docker/oci/caps"
29
30
spec "github.com/opencontainers/runtime-spec/specs-go"
30
31
"github.com/opencontainers/selinux/go-selinux"
31
32
"github.com/opencontainers/selinux/go-selinux/label"
@@ -523,7 +524,7 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
523
524
finalEnv = append (finalEnv , fmt .Sprintf ("%s=%s" , k , v ))
524
525
}
525
526
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 )
527
528
if err != nil {
528
529
return - 1 , nil , err
529
530
}
@@ -538,10 +539,6 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
538
539
args = append (args , formatRuntimeOpts ("--preserve-fds" , fmt .Sprintf ("%d" , options .PreserveFDs ))... )
539
540
}
540
541
541
- for _ , capability := range options .CapAdd {
542
- args = append (args , formatRuntimeOpts ("--cap" , capability )... )
543
- }
544
-
545
542
if options .Terminal {
546
543
args = append (args , "-t" )
547
544
}
@@ -1041,12 +1038,15 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
1041
1038
1042
1039
// prepareProcessExec returns the path of the process.json used in runc exec -p
1043
1040
// 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 ) {
1045
1042
f , err := ioutil .TempFile (c .execBundlePath (sessionID ), "exec-process-" )
1046
1043
if err != nil {
1047
1044
return nil , err
1048
1045
}
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
+ }
1050
1050
pspec .SelinuxLabel = c .config .ProcessLabel
1051
1051
pspec .Args = cmd
1052
1052
// 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
1103
1103
pspec .User = processUser
1104
1104
}
1105
1105
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
+
1106
1123
hasHomeSet := false
1107
1124
for _ , s := range pspec .Env {
1108
1125
if strings .HasPrefix (s , "HOME=" ) {
0 commit comments