mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
Merge pull request #13093 from 0xC0ncord/selinux-conmon-agnostic
selinux: remove explicit range transition when starting conmon
This commit is contained in:
@ -462,7 +462,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
|
|||||||
Setpgid: true,
|
Setpgid: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = startCommandGivenSelinux(execCmd, c)
|
err = startCommand(execCmd, c)
|
||||||
|
|
||||||
// We don't need children pipes on the parent side
|
// We don't need children pipes on the parent side
|
||||||
errorhandling.CloseQuiet(childSyncPipe)
|
errorhandling.CloseQuiet(childSyncPipe)
|
||||||
|
@ -38,7 +38,6 @@ import (
|
|||||||
pmount "github.com/containers/storage/pkg/mount"
|
pmount "github.com/containers/storage/pkg/mount"
|
||||||
"github.com/coreos/go-systemd/v22/daemon"
|
"github.com/coreos/go-systemd/v22/daemon"
|
||||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -1247,7 +1246,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
|
|||||||
if restoreOptions != nil {
|
if restoreOptions != nil {
|
||||||
runtimeRestoreStarted = time.Now()
|
runtimeRestoreStarted = time.Now()
|
||||||
}
|
}
|
||||||
err = startCommandGivenSelinux(cmd, ctr)
|
err = startCommand(cmd, ctr)
|
||||||
|
|
||||||
// regardless of whether we errored or not, we no longer need the children pipes
|
// regardless of whether we errored or not, we no longer need the children pipes
|
||||||
childSyncPipe.Close()
|
childSyncPipe.Close()
|
||||||
@ -1414,9 +1413,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
// startCommandGivenSelinux starts a container ensuring to set the labels of
|
func startCommand(cmd *exec.Cmd, ctr *Container) error {
|
||||||
// the process to make sure SELinux doesn't block conmon communication, if SELinux is enabled
|
|
||||||
func startCommandGivenSelinux(cmd *exec.Cmd, ctr *Container) error {
|
|
||||||
// Make sure to unset the NOTIFY_SOCKET and reset if afterwards if needed.
|
// Make sure to unset the NOTIFY_SOCKET and reset if afterwards if needed.
|
||||||
switch ctr.config.SdNotifyMode {
|
switch ctr.config.SdNotifyMode {
|
||||||
case define.SdNotifyModeContainer, define.SdNotifyModeIgnore:
|
case define.SdNotifyModeContainer, define.SdNotifyModeIgnore:
|
||||||
@ -1433,47 +1430,7 @@ func startCommandGivenSelinux(cmd *exec.Cmd, ctr *Container) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !selinux.GetEnabled() {
|
return cmd.Start()
|
||||||
return cmd.Start()
|
|
||||||
}
|
|
||||||
// Set the label of the conmon process to be level :s0
|
|
||||||
// This will allow the container processes to talk to fifo-files
|
|
||||||
// passed into the container by conmon
|
|
||||||
var (
|
|
||||||
plabel string
|
|
||||||
con selinux.Context
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
plabel, err = selinux.CurrentLabel()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "failed to get current SELinux label")
|
|
||||||
}
|
|
||||||
|
|
||||||
con, err = selinux.NewContext(plabel)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "failed to get new context from SELinux label")
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
if con["level"] != "s0" && con["level"] != "" {
|
|
||||||
con["level"] = "s0"
|
|
||||||
if err = label.SetProcessLabel(con.Get()); err != nil {
|
|
||||||
runtime.UnlockOSThread()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = cmd.Start()
|
|
||||||
// Ignore error returned from SetProcessLabel("") call,
|
|
||||||
// can't recover.
|
|
||||||
if labelErr := label.SetProcessLabel(""); labelErr == nil {
|
|
||||||
// Unlock the thread only if the process label could be restored
|
|
||||||
// successfully. Otherwise leave the thread locked and the Go runtime
|
|
||||||
// will terminate it once it returns to the threads pool.
|
|
||||||
runtime.UnlockOSThread()
|
|
||||||
} else {
|
|
||||||
logrus.Errorf("Unable to set process label: %q", labelErr)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// moveConmonToCgroupAndSignal gets a container's cgroupParent and moves the conmon process to that cgroup
|
// moveConmonToCgroupAndSignal gets a container's cgroupParent and moves the conmon process to that cgroup
|
||||||
|
Reference in New Issue
Block a user