2022-07-06 17:14:06 +08:00
|
|
|
//go:build linux
|
2018-05-12 01:08:18 +08:00
|
|
|
|
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2022-07-06 17:14:06 +08:00
|
|
|
"fmt"
|
|
|
|
|
2018-05-12 01:08:18 +08:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
|
|
|
selinux "github.com/opencontainers/selinux/go-selinux"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// setSelinuxLabel sets the process label for child processes that we'll start.
|
|
|
|
func setSelinuxLabel(spec *specs.Spec) error {
|
|
|
|
logrus.Debugf("setting selinux label")
|
2019-04-24 03:09:01 +08:00
|
|
|
if spec.Process.SelinuxLabel != "" && selinux.GetEnabled() {
|
2025-03-24 20:32:00 +08:00
|
|
|
if err := selinux.SetExecLabel(spec.Process.SelinuxLabel); err != nil {
|
2022-09-18 18:36:08 +08:00
|
|
|
return fmt.Errorf("setting process label to %q: %w", spec.Process.SelinuxLabel, err)
|
2018-05-12 01:08:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|