diff options
author | Doug Rabson <dfr@rabson.org> | 2022-09-05 10:02:51 +0100 |
---|---|---|
committer | Doug Rabson <dfr@rabson.org> | 2022-09-07 07:58:37 +0100 |
commit | 6668ac93bba799441cb8eb55cc8c7f1a6a5a89a5 (patch) | |
tree | e2675ebc4969341886cbcf5135d6274ee3a7bf65 /libpod/oci_conmon_exec_linux.go | |
parent | cd09e3b6d0b0eb32f6ad6062b13194f97873c664 (diff) | |
download | podman-6668ac93bba799441cb8eb55cc8c7f1a6a5a89a5.tar.gz podman-6668ac93bba799441cb8eb55cc8c7f1a6a5a89a5.tar.bz2 podman-6668ac93bba799441cb8eb55cc8c7f1a6a5a89a5.zip |
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>
Diffstat (limited to 'libpod/oci_conmon_exec_linux.go')
-rw-r--r-- | libpod/oci_conmon_exec_linux.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libpod/oci_conmon_exec_linux.go b/libpod/oci_conmon_exec_linux.go new file mode 100644 index 000000000..617e8d601 --- /dev/null +++ b/libpod/oci_conmon_exec_linux.go @@ -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 +} |