mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00
libpod: Factor out capabilites code from prepareProcessExec
This moves the code which sets the process capabilites for the exec to oci_conmon_exec_linux.go since this is a linux-specific feature. Adding a no-op stub for FreeBSD enables 'podman exec' when using the ocijail runtime. [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
@ -12,7 +12,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/capabilities"
|
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
"github.com/containers/common/pkg/resize"
|
"github.com/containers/common/pkg/resize"
|
||||||
cutil "github.com/containers/common/pkg/util"
|
cutil "github.com/containers/common/pkg/util"
|
||||||
@ -386,7 +385,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
|
|||||||
finalEnv = append(finalEnv, fmt.Sprintf("%s=%s", k, v))
|
finalEnv = append(finalEnv, fmt.Sprintf("%s=%s", k, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
processFile, err := prepareProcessExec(c, options, finalEnv, sessionID)
|
processFile, err := c.prepareProcessExec(options, finalEnv, sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -665,7 +664,7 @@ func attachExecHTTP(c *Container, sessionID string, r *http.Request, w http.Resp
|
|||||||
|
|
||||||
// prepareProcessExec returns the path of the process.json used in runc exec -p
|
// prepareProcessExec returns the path of the process.json used in runc exec -p
|
||||||
// caller is responsible to close the returned *os.File if needed.
|
// caller is responsible to close the returned *os.File if needed.
|
||||||
func prepareProcessExec(c *Container, options *ExecOptions, env []string, sessionID string) (*os.File, error) {
|
func (c *Container) prepareProcessExec(options *ExecOptions, env []string, sessionID string) (*os.File, error) {
|
||||||
f, err := ioutil.TempFile(c.execBundlePath(sessionID), "exec-process-")
|
f, err := ioutil.TempFile(c.execBundlePath(sessionID), "exec-process-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -745,35 +744,10 @@ func prepareProcessExec(c *Container, options *ExecOptions, env []string, sessio
|
|||||||
pspec.User = processUser
|
pspec.User = processUser
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrSpec, err := c.specFromState()
|
if err := c.setProcessCapabilitiesExec(options, user, execUser, pspec); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
allCaps, err := capabilities.BoundingSet()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if options.Privileged {
|
|
||||||
pspec.Capabilities.Bounding = allCaps
|
|
||||||
} else {
|
|
||||||
pspec.Capabilities.Bounding = ctrSpec.Process.Capabilities.Bounding
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always unset the inheritable capabilities similarly to what the Linux kernel does
|
|
||||||
// They are used only when using capabilities with uid != 0.
|
|
||||||
pspec.Capabilities.Inheritable = []string{}
|
|
||||||
|
|
||||||
if execUser.Uid == 0 {
|
|
||||||
pspec.Capabilities.Effective = pspec.Capabilities.Bounding
|
|
||||||
pspec.Capabilities.Permitted = pspec.Capabilities.Bounding
|
|
||||||
} else if user == c.config.User {
|
|
||||||
pspec.Capabilities.Effective = ctrSpec.Process.Capabilities.Effective
|
|
||||||
pspec.Capabilities.Inheritable = ctrSpec.Process.Capabilities.Effective
|
|
||||||
pspec.Capabilities.Permitted = ctrSpec.Process.Capabilities.Effective
|
|
||||||
pspec.Capabilities.Ambient = ctrSpec.Process.Capabilities.Effective
|
|
||||||
}
|
|
||||||
|
|
||||||
hasHomeSet := false
|
hasHomeSet := false
|
||||||
for _, s := range pspec.Env {
|
for _, s := range pspec.Env {
|
||||||
if strings.HasPrefix(s, "HOME=") {
|
if strings.HasPrefix(s, "HOME=") {
|
||||||
|
10
libpod/oci_conmon_exec_freebsd.go
Normal file
10
libpod/oci_conmon_exec_freebsd.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package libpod
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/opencontainers/runc/libcontainer/user"
|
||||||
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Container) setProcessCapabilitiesExec(options *ExecOptions, user string, execUser *user.ExecUser, pspec *spec.Process) error {
|
||||||
|
return nil
|
||||||
|
}
|
39
libpod/oci_conmon_exec_linux.go
Normal file
39
libpod/oci_conmon_exec_linux.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package libpod
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containers/common/pkg/capabilities"
|
||||||
|
"github.com/opencontainers/runc/libcontainer/user"
|
||||||
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Container) setProcessCapabilitiesExec(options *ExecOptions, user string, execUser *user.ExecUser, pspec *spec.Process) error {
|
||||||
|
ctrSpec, err := c.specFromState()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
allCaps, err := capabilities.BoundingSet()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if options.Privileged {
|
||||||
|
pspec.Capabilities.Bounding = allCaps
|
||||||
|
} else {
|
||||||
|
pspec.Capabilities.Bounding = ctrSpec.Process.Capabilities.Bounding
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always unset the inheritable capabilities similarly to what the Linux kernel does
|
||||||
|
// They are used only when using capabilities with uid != 0.
|
||||||
|
pspec.Capabilities.Inheritable = []string{}
|
||||||
|
|
||||||
|
if execUser.Uid == 0 {
|
||||||
|
pspec.Capabilities.Effective = pspec.Capabilities.Bounding
|
||||||
|
pspec.Capabilities.Permitted = pspec.Capabilities.Bounding
|
||||||
|
} else if user == c.config.User {
|
||||||
|
pspec.Capabilities.Effective = ctrSpec.Process.Capabilities.Effective
|
||||||
|
pspec.Capabilities.Inheritable = ctrSpec.Process.Capabilities.Effective
|
||||||
|
pspec.Capabilities.Permitted = ctrSpec.Process.Capabilities.Effective
|
||||||
|
pspec.Capabilities.Ambient = ctrSpec.Process.Capabilities.Effective
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Reference in New Issue
Block a user