|
@@ -15,13 +15,14 @@ import (
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"syscall"
|
|
"syscall"
|
|
-
|
|
|
|
- "github.com/opencontainers/runc/libcontainer/system"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
- Enforcing = 1
|
|
|
|
- Permissive = 0
|
|
|
|
|
|
+ // Enforcing constant indicate SELinux is in enforcing mode
|
|
|
|
+ Enforcing = 1
|
|
|
|
+ // Permissive constant to indicate SELinux is in permissive mode
|
|
|
|
+ Permissive = 0
|
|
|
|
+ // Disabled constant to indicate SELinux is disabled
|
|
Disabled = -1
|
|
Disabled = -1
|
|
selinuxDir = "/etc/selinux/"
|
|
selinuxDir = "/etc/selinux/"
|
|
selinuxConfig = selinuxDir + "config"
|
|
selinuxConfig = selinuxDir + "config"
|
|
@@ -32,33 +33,74 @@ const (
|
|
stRdOnly = 0x01
|
|
stRdOnly = 0x01
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+type selinuxState struct {
|
|
|
|
+ enabledSet bool
|
|
|
|
+ enabled bool
|
|
|
|
+ selinuxfsSet bool
|
|
|
|
+ selinuxfs string
|
|
|
|
+ mcsList map[string]bool
|
|
|
|
+ sync.Mutex
|
|
|
|
+}
|
|
|
|
+
|
|
var (
|
|
var (
|
|
- assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`)
|
|
|
|
- mcsList = make(map[string]bool)
|
|
|
|
- mcsLock sync.Mutex
|
|
|
|
- selinuxfs = "unknown"
|
|
|
|
- selinuxEnabled = false // Stores whether selinux is currently enabled
|
|
|
|
- selinuxEnabledChecked = false // Stores whether selinux enablement has been checked or established yet
|
|
|
|
|
|
+ assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`)
|
|
|
|
+ state = selinuxState{
|
|
|
|
+ mcsList: make(map[string]bool),
|
|
|
|
+ }
|
|
)
|
|
)
|
|
|
|
|
|
-type SELinuxContext map[string]string
|
|
|
|
|
|
+// Context is a representation of the SELinux label broken into 4 parts
|
|
|
|
+type Context map[string]string
|
|
|
|
+
|
|
|
|
+func (s *selinuxState) setEnable(enabled bool) bool {
|
|
|
|
+ s.Lock()
|
|
|
|
+ defer s.Unlock()
|
|
|
|
+ s.enabledSet = true
|
|
|
|
+ s.enabled = enabled
|
|
|
|
+ return s.enabled
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *selinuxState) getEnabled() bool {
|
|
|
|
+ s.Lock()
|
|
|
|
+ enabled := s.enabled
|
|
|
|
+ enabledSet := s.enabledSet
|
|
|
|
+ s.Unlock()
|
|
|
|
+ if enabledSet {
|
|
|
|
+ return enabled
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ enabled = false
|
|
|
|
+ if fs := getSelinuxMountPoint(); fs != "" {
|
|
|
|
+ if con, _ := CurrentLabel(); con != "kernel" {
|
|
|
|
+ enabled = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return s.setEnable(enabled)
|
|
|
|
+}
|
|
|
|
|
|
// SetDisabled disables selinux support for the package
|
|
// SetDisabled disables selinux support for the package
|
|
func SetDisabled() {
|
|
func SetDisabled() {
|
|
- selinuxEnabled, selinuxEnabledChecked = false, true
|
|
|
|
|
|
+ state.setEnable(false)
|
|
}
|
|
}
|
|
|
|
|
|
-// getSelinuxMountPoint returns the path to the mountpoint of an selinuxfs
|
|
|
|
-// filesystem or an empty string if no mountpoint is found. Selinuxfs is
|
|
|
|
-// a proc-like pseudo-filesystem that exposes the selinux policy API to
|
|
|
|
-// processes. The existence of an selinuxfs mount is used to determine
|
|
|
|
-// whether selinux is currently enabled or not.
|
|
|
|
-func getSelinuxMountPoint() string {
|
|
|
|
- if selinuxfs != "unknown" {
|
|
|
|
|
|
+func (s *selinuxState) setSELinuxfs(selinuxfs string) string {
|
|
|
|
+ s.Lock()
|
|
|
|
+ defer s.Unlock()
|
|
|
|
+ s.selinuxfsSet = true
|
|
|
|
+ s.selinuxfs = selinuxfs
|
|
|
|
+ return s.selinuxfs
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *selinuxState) getSELinuxfs() string {
|
|
|
|
+ s.Lock()
|
|
|
|
+ selinuxfs := s.selinuxfs
|
|
|
|
+ selinuxfsSet := s.selinuxfsSet
|
|
|
|
+ s.Unlock()
|
|
|
|
+ if selinuxfsSet {
|
|
return selinuxfs
|
|
return selinuxfs
|
|
}
|
|
}
|
|
- selinuxfs = ""
|
|
|
|
|
|
|
|
|
|
+ selinuxfs = ""
|
|
f, err := os.Open("/proc/self/mountinfo")
|
|
f, err := os.Open("/proc/self/mountinfo")
|
|
if err != nil {
|
|
if err != nil {
|
|
return selinuxfs
|
|
return selinuxfs
|
|
@@ -91,21 +133,21 @@ func getSelinuxMountPoint() string {
|
|
selinuxfs = ""
|
|
selinuxfs = ""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return selinuxfs
|
|
|
|
|
|
+ return s.setSELinuxfs(selinuxfs)
|
|
}
|
|
}
|
|
|
|
|
|
-// SelinuxEnabled returns whether selinux is currently enabled.
|
|
|
|
-func SelinuxEnabled() bool {
|
|
|
|
- if selinuxEnabledChecked {
|
|
|
|
- return selinuxEnabled
|
|
|
|
- }
|
|
|
|
- selinuxEnabledChecked = true
|
|
|
|
- if fs := getSelinuxMountPoint(); fs != "" {
|
|
|
|
- if con, _ := Getcon(); con != "kernel" {
|
|
|
|
- selinuxEnabled = true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return selinuxEnabled
|
|
|
|
|
|
+// getSelinuxMountPoint returns the path to the mountpoint of an selinuxfs
|
|
|
|
+// filesystem or an empty string if no mountpoint is found. Selinuxfs is
|
|
|
|
+// a proc-like pseudo-filesystem that exposes the selinux policy API to
|
|
|
|
+// processes. The existence of an selinuxfs mount is used to determine
|
|
|
|
+// whether selinux is currently enabled or not.
|
|
|
|
+func getSelinuxMountPoint() string {
|
|
|
|
+ return state.getSELinuxfs()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// GetEnabled returns whether selinux is currently enabled.
|
|
|
|
+func GetEnabled() bool {
|
|
|
|
+ return state.getEnabled()
|
|
}
|
|
}
|
|
|
|
|
|
func readConfig(target string) (value string) {
|
|
func readConfig(target string) (value string) {
|
|
@@ -166,43 +208,55 @@ func readCon(name string) (string, error) {
|
|
return val, err
|
|
return val, err
|
|
}
|
|
}
|
|
|
|
|
|
-// Setfilecon sets the SELinux label for this path or returns an error.
|
|
|
|
-func Setfilecon(path string, scon string) error {
|
|
|
|
- return system.Lsetxattr(path, xattrNameSelinux, []byte(scon), 0)
|
|
|
|
|
|
+// SetFileLabel sets the SELinux label for this path or returns an error.
|
|
|
|
+func SetFileLabel(path string, label string) error {
|
|
|
|
+ return lsetxattr(path, xattrNameSelinux, []byte(label), 0)
|
|
}
|
|
}
|
|
|
|
|
|
-// Getfilecon returns the SELinux label for this path or returns an error.
|
|
|
|
-func Getfilecon(path string) (string, error) {
|
|
|
|
- con, err := system.Lgetxattr(path, xattrNameSelinux)
|
|
|
|
|
|
+// Filecon returns the SELinux label for this path or returns an error.
|
|
|
|
+func FileLabel(path string) (string, error) {
|
|
|
|
+ label, err := lgetxattr(path, xattrNameSelinux)
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
// Trim the NUL byte at the end of the byte buffer, if present.
|
|
// Trim the NUL byte at the end of the byte buffer, if present.
|
|
- if len(con) > 0 && con[len(con)-1] == '\x00' {
|
|
|
|
- con = con[:len(con)-1]
|
|
|
|
|
|
+ if len(label) > 0 && label[len(label)-1] == '\x00' {
|
|
|
|
+ label = label[:len(label)-1]
|
|
}
|
|
}
|
|
- return string(con), nil
|
|
|
|
|
|
+ return string(label), nil
|
|
}
|
|
}
|
|
|
|
|
|
-func Setfscreatecon(scon string) error {
|
|
|
|
- return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()), scon)
|
|
|
|
|
|
+/*
|
|
|
|
+SetFSCreateLabel tells kernel the label to create all file system objects
|
|
|
|
+created by this task. Setting label="" to return to default.
|
|
|
|
+*/
|
|
|
|
+func SetFSCreateLabel(label string) error {
|
|
|
|
+ return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()), label)
|
|
}
|
|
}
|
|
|
|
|
|
-func Getfscreatecon() (string, error) {
|
|
|
|
|
|
+/*
|
|
|
|
+FSCreateLabel returns the default label the kernel which the kernel is using
|
|
|
|
+for file system objects created by this task. "" indicates default.
|
|
|
|
+*/
|
|
|
|
+func FSCreateLabel() (string, error) {
|
|
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()))
|
|
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()))
|
|
}
|
|
}
|
|
|
|
|
|
-// Getcon returns the SELinux label of the current process thread, or an error.
|
|
|
|
-func Getcon() (string, error) {
|
|
|
|
|
|
+// CurrentLabel returns the SELinux label of the current process thread, or an error.
|
|
|
|
+func CurrentLabel() (string, error) {
|
|
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/current", syscall.Gettid()))
|
|
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/current", syscall.Gettid()))
|
|
}
|
|
}
|
|
|
|
|
|
-// Getpidcon returns the SELinux label of the given pid, or an error.
|
|
|
|
-func Getpidcon(pid int) (string, error) {
|
|
|
|
|
|
+// PidLabel returns the SELinux label of the given pid, or an error.
|
|
|
|
+func PidLabel(pid int) (string, error) {
|
|
return readCon(fmt.Sprintf("/proc/%d/attr/current", pid))
|
|
return readCon(fmt.Sprintf("/proc/%d/attr/current", pid))
|
|
}
|
|
}
|
|
|
|
|
|
-func Getexeccon() (string, error) {
|
|
|
|
|
|
+/*
|
|
|
|
+ExecLabel returns the SELinux label that the kernel will use for any programs
|
|
|
|
+that are executed by the current process thread, or an error.
|
|
|
|
+*/
|
|
|
|
+func ExecLabel() (string, error) {
|
|
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()))
|
|
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -221,19 +275,25 @@ func writeCon(name string, val string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
-func Setexeccon(scon string) error {
|
|
|
|
- return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()), scon)
|
|
|
|
|
|
+/*
|
|
|
|
+SetExecLabel sets the SELinux label that the kernel will use for any programs
|
|
|
|
+that are executed by the current process thread, or an error.
|
|
|
|
+*/
|
|
|
|
+func SetExecLabel(label string) error {
|
|
|
|
+ return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()), label)
|
|
}
|
|
}
|
|
|
|
|
|
-func (c SELinuxContext) Get() string {
|
|
|
|
|
|
+// Get returns the Context as a string
|
|
|
|
+func (c Context) Get() string {
|
|
return fmt.Sprintf("%s:%s:%s:%s", c["user"], c["role"], c["type"], c["level"])
|
|
return fmt.Sprintf("%s:%s:%s:%s", c["user"], c["role"], c["type"], c["level"])
|
|
}
|
|
}
|
|
|
|
|
|
-func NewContext(scon string) SELinuxContext {
|
|
|
|
- c := make(SELinuxContext)
|
|
|
|
|
|
+// NewContext creates a new Context struct from the specified label
|
|
|
|
+func NewContext(label string) Context {
|
|
|
|
+ c := make(Context)
|
|
|
|
|
|
- if len(scon) != 0 {
|
|
|
|
- con := strings.SplitN(scon, ":", 4)
|
|
|
|
|
|
+ if len(label) != 0 {
|
|
|
|
+ con := strings.SplitN(label, ":", 4)
|
|
c["user"] = con[0]
|
|
c["user"] = con[0]
|
|
c["role"] = con[1]
|
|
c["role"] = con[1]
|
|
c["type"] = con[2]
|
|
c["type"] = con[2]
|
|
@@ -242,9 +302,10 @@ func NewContext(scon string) SELinuxContext {
|
|
return c
|
|
return c
|
|
}
|
|
}
|
|
|
|
|
|
-func ReserveLabel(scon string) {
|
|
|
|
- if len(scon) != 0 {
|
|
|
|
- con := strings.SplitN(scon, ":", 4)
|
|
|
|
|
|
+// ReserveLabel reserves the MLS/MCS level component of the specified label
|
|
|
|
+func ReserveLabel(label string) {
|
|
|
|
+ if len(label) != 0 {
|
|
|
|
+ con := strings.SplitN(label, ":", 4)
|
|
mcsAdd(con[3])
|
|
mcsAdd(con[3])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -253,7 +314,8 @@ func selinuxEnforcePath() string {
|
|
return fmt.Sprintf("%s/enforce", selinuxPath)
|
|
return fmt.Sprintf("%s/enforce", selinuxPath)
|
|
}
|
|
}
|
|
|
|
|
|
-func SelinuxGetEnforce() int {
|
|
|
|
|
|
+// EnforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
|
|
|
|
+func EnforceMode() int {
|
|
var enforce int
|
|
var enforce int
|
|
|
|
|
|
enforceS, err := readCon(selinuxEnforcePath())
|
|
enforceS, err := readCon(selinuxEnforcePath())
|
|
@@ -268,11 +330,20 @@ func SelinuxGetEnforce() int {
|
|
return enforce
|
|
return enforce
|
|
}
|
|
}
|
|
|
|
|
|
-func SelinuxSetEnforce(mode int) error {
|
|
|
|
|
|
+/*
|
|
|
|
+SetEnforce sets the current SELinux mode Enforcing, Permissive.
|
|
|
|
+Disabled is not valid, since this needs to be set at boot time.
|
|
|
|
+*/
|
|
|
|
+func SetEnforceMode(mode int) error {
|
|
return writeCon(selinuxEnforcePath(), fmt.Sprintf("%d", mode))
|
|
return writeCon(selinuxEnforcePath(), fmt.Sprintf("%d", mode))
|
|
}
|
|
}
|
|
|
|
|
|
-func SelinuxGetEnforceMode() int {
|
|
|
|
|
|
+/*
|
|
|
|
+DefaultEnforceMode returns the systems default SELinux mode Enforcing,
|
|
|
|
+Permissive or Disabled. Note this is is just the default at boot time.
|
|
|
|
+EnforceMode tells you the systems current mode.
|
|
|
|
+*/
|
|
|
|
+func DefaultEnforceMode() int {
|
|
switch readConfig(selinuxTag) {
|
|
switch readConfig(selinuxTag) {
|
|
case "enforcing":
|
|
case "enforcing":
|
|
return Enforcing
|
|
return Enforcing
|
|
@@ -283,22 +354,22 @@ func SelinuxGetEnforceMode() int {
|
|
}
|
|
}
|
|
|
|
|
|
func mcsAdd(mcs string) error {
|
|
func mcsAdd(mcs string) error {
|
|
- mcsLock.Lock()
|
|
|
|
- defer mcsLock.Unlock()
|
|
|
|
- if mcsList[mcs] {
|
|
|
|
|
|
+ state.Lock()
|
|
|
|
+ defer state.Unlock()
|
|
|
|
+ if state.mcsList[mcs] {
|
|
return fmt.Errorf("MCS Label already exists")
|
|
return fmt.Errorf("MCS Label already exists")
|
|
}
|
|
}
|
|
- mcsList[mcs] = true
|
|
|
|
|
|
+ state.mcsList[mcs] = true
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
func mcsDelete(mcs string) {
|
|
func mcsDelete(mcs string) {
|
|
- mcsLock.Lock()
|
|
|
|
- mcsList[mcs] = false
|
|
|
|
- mcsLock.Unlock()
|
|
|
|
|
|
+ state.Lock()
|
|
|
|
+ defer state.Unlock()
|
|
|
|
+ state.mcsList[mcs] = false
|
|
}
|
|
}
|
|
|
|
|
|
-func IntToMcs(id int, catRange uint32) string {
|
|
|
|
|
|
+func intToMcs(id int, catRange uint32) string {
|
|
var (
|
|
var (
|
|
SETSIZE = int(catRange)
|
|
SETSIZE = int(catRange)
|
|
TIER = SETSIZE
|
|
TIER = SETSIZE
|
|
@@ -334,9 +405,7 @@ func uniqMcs(catRange uint32) string {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
if c1 > c2 {
|
|
if c1 > c2 {
|
|
- t := c1
|
|
|
|
- c1 = c2
|
|
|
|
- c2 = t
|
|
|
|
|
|
+ c1, c2 = c2, c1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
mcs = fmt.Sprintf("s0:c%d,c%d", c1, c2)
|
|
mcs = fmt.Sprintf("s0:c%d,c%d", c1, c2)
|
|
@@ -348,26 +417,35 @@ func uniqMcs(catRange uint32) string {
|
|
return mcs
|
|
return mcs
|
|
}
|
|
}
|
|
|
|
|
|
-func FreeLxcContexts(scon string) {
|
|
|
|
- if len(scon) != 0 {
|
|
|
|
- con := strings.SplitN(scon, ":", 4)
|
|
|
|
|
|
+/*
|
|
|
|
+ReleaseLabel will unreserve the MLS/MCS Level field of the specified label.
|
|
|
|
+Allowing it to be used by another process.
|
|
|
|
+*/
|
|
|
|
+func ReleaseLabel(label string) {
|
|
|
|
+ if len(label) != 0 {
|
|
|
|
+ con := strings.SplitN(label, ":", 4)
|
|
mcsDelete(con[3])
|
|
mcsDelete(con[3])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
var roFileLabel string
|
|
var roFileLabel string
|
|
|
|
|
|
-func GetROFileLabel() (fileLabel string) {
|
|
|
|
|
|
+// ROFileLabel returns the specified SELinux readonly file label
|
|
|
|
+func ROFileLabel() (fileLabel string) {
|
|
return roFileLabel
|
|
return roFileLabel
|
|
}
|
|
}
|
|
|
|
|
|
-func GetLxcContexts() (processLabel string, fileLabel string) {
|
|
|
|
|
|
+/*
|
|
|
|
+ContainerLabels returns an allocated processLabel and fileLabel to be used for
|
|
|
|
+container labeling by the calling process.
|
|
|
|
+*/
|
|
|
|
+func ContainerLabels() (processLabel string, fileLabel string) {
|
|
var (
|
|
var (
|
|
val, key string
|
|
val, key string
|
|
bufin *bufio.Reader
|
|
bufin *bufio.Reader
|
|
)
|
|
)
|
|
|
|
|
|
- if !SelinuxEnabled() {
|
|
|
|
|
|
+ if !GetEnabled() {
|
|
return "", ""
|
|
return "", ""
|
|
}
|
|
}
|
|
lxcPath := fmt.Sprintf("%s/contexts/lxc_contexts", getSELinuxPolicyRoot())
|
|
lxcPath := fmt.Sprintf("%s/contexts/lxc_contexts", getSELinuxPolicyRoot())
|
|
@@ -419,7 +497,6 @@ func GetLxcContexts() (processLabel string, fileLabel string) {
|
|
roFileLabel = fileLabel
|
|
roFileLabel = fileLabel
|
|
}
|
|
}
|
|
exit:
|
|
exit:
|
|
- // mcs := IntToMcs(os.Getpid(), 1024)
|
|
|
|
mcs := uniqMcs(1024)
|
|
mcs := uniqMcs(1024)
|
|
scon := NewContext(processLabel)
|
|
scon := NewContext(processLabel)
|
|
scon["level"] = mcs
|
|
scon["level"] = mcs
|
|
@@ -430,10 +507,15 @@ exit:
|
|
return processLabel, fileLabel
|
|
return processLabel, fileLabel
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// SecurityCheckContext validates that the SELinux label is understood by the kernel
|
|
func SecurityCheckContext(val string) error {
|
|
func SecurityCheckContext(val string) error {
|
|
return writeCon(fmt.Sprintf("%s.context", selinuxPath), val)
|
|
return writeCon(fmt.Sprintf("%s.context", selinuxPath), val)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+CopyLevel returns a label with the MLS/MCS level from src label replaces on
|
|
|
|
+the dest label.
|
|
|
|
+*/
|
|
func CopyLevel(src, dest string) (string, error) {
|
|
func CopyLevel(src, dest string) (string, error) {
|
|
if src == "" {
|
|
if src == "" {
|
|
return "", nil
|
|
return "", nil
|
|
@@ -458,31 +540,31 @@ func badPrefix(fpath string) error {
|
|
|
|
|
|
for _, prefix := range badprefixes {
|
|
for _, prefix := range badprefixes {
|
|
if fpath == prefix || strings.HasPrefix(fpath, fmt.Sprintf("%s/", prefix)) {
|
|
if fpath == prefix || strings.HasPrefix(fpath, fmt.Sprintf("%s/", prefix)) {
|
|
- return fmt.Errorf("Relabeling content in %s is not allowed.", prefix)
|
|
|
|
|
|
+ return fmt.Errorf("relabeling content in %s is not allowed", prefix)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-// Chcon changes the fpath file object to the SELinux label scon.
|
|
|
|
|
|
+// Chcon changes the fpath file object to the SELinux label label.
|
|
// If the fpath is a directory and recurse is true Chcon will walk the
|
|
// If the fpath is a directory and recurse is true Chcon will walk the
|
|
// directory tree setting the label
|
|
// directory tree setting the label
|
|
-func Chcon(fpath string, scon string, recurse bool) error {
|
|
|
|
- if scon == "" {
|
|
|
|
|
|
+func Chcon(fpath string, label string, recurse bool) error {
|
|
|
|
+ if label == "" {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
if err := badPrefix(fpath); err != nil {
|
|
if err := badPrefix(fpath); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
callback := func(p string, info os.FileInfo, err error) error {
|
|
callback := func(p string, info os.FileInfo, err error) error {
|
|
- return Setfilecon(p, scon)
|
|
|
|
|
|
+ return SetFileLabel(p, label)
|
|
}
|
|
}
|
|
|
|
|
|
if recurse {
|
|
if recurse {
|
|
return filepath.Walk(fpath, callback)
|
|
return filepath.Walk(fpath, callback)
|
|
}
|
|
}
|
|
|
|
|
|
- return Setfilecon(fpath, scon)
|
|
|
|
|
|
+ return SetFileLabel(fpath, label)
|
|
}
|
|
}
|
|
|
|
|
|
// DupSecOpt takes an SELinux process label and returns security options that
|
|
// DupSecOpt takes an SELinux process label and returns security options that
|
|
@@ -498,14 +580,14 @@ func DupSecOpt(src string) []string {
|
|
con["level"] == "" {
|
|
con["level"] == "" {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- return []string{"label=user:" + con["user"],
|
|
|
|
- "label=role:" + con["role"],
|
|
|
|
- "label=type:" + con["type"],
|
|
|
|
- "label=level:" + con["level"]}
|
|
|
|
|
|
+ return []string{"user:" + con["user"],
|
|
|
|
+ "role:" + con["role"],
|
|
|
|
+ "type:" + con["type"],
|
|
|
|
+ "level:" + con["level"]}
|
|
}
|
|
}
|
|
|
|
|
|
// DisableSecOpt returns a security opt that can be used to disabling SELinux
|
|
// DisableSecOpt returns a security opt that can be used to disabling SELinux
|
|
// labeling support for future container processes
|
|
// labeling support for future container processes
|
|
func DisableSecOpt() []string {
|
|
func DisableSecOpt() []string {
|
|
- return []string{"label=disable"}
|
|
|
|
|
|
+ return []string{"disable"}
|
|
}
|
|
}
|