mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-02 21:57:52 +00:00
The previous commit replaced setProcessCapabilitiesExec() with a simplified 3-line inline check. This only copies container capabilities when pspec.Capabilities is nil. It doesn't handle --privileged exec (which needs the full bounding set) and doesn't handle the case where a non-root exec user matches the container user (which needs ambient/inheritable caps set). The original method handles both cases properly. Also backport commit68b2450,6668ac9but set tags only to support linux builds (FreeBSD will never again be built from this branch). Signed-off-by: Chris Evich <cevich@redhat.com>
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
//go:build linux
|
|
|
|
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 {
|
|
// implementation from bare 6668ac9 assumed a non-nil, preserve pre-backport
|
|
// behavior so that there can be no nil dereference problems here.
|
|
if pspec.Capabilities == nil {
|
|
pspec.Capabilities = c.config.Spec.Process.Capabilities
|
|
}
|
|
if pspec.Capabilities == nil {
|
|
pspec.Capabilities = &spec.LinuxCapabilities{}
|
|
}
|
|
|
|
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
|
|
}
|