Update runc to resolve selinux issues
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
		
							
								
								
									
										35
									
								
								vendor/github.com/opencontainers/selinux/go-selinux/label/label.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										35
									
								
								vendor/github.com/opencontainers/selinux/go-selinux/label/label.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -9,7 +9,7 @@ func InitLabels(options []string) (string, string, error) {
 | 
			
		||||
	return "", "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetROMountLabel() string {
 | 
			
		||||
func ROMountLabel() string {
 | 
			
		||||
	return ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -25,7 +25,27 @@ func SetProcessLabel(processLabel string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetFileLabel(path string) (string, error) {
 | 
			
		||||
func ProcessLabel() (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SetSocketLabel(processLabel string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SocketLabel() (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SetKeyLabel(processLabel string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func KeyLabel() (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func FileLabel(path string) (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -41,13 +61,18 @@ func Relabel(path string, fileLabel string, shared bool) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetPidLabel(pid int) (string, error) {
 | 
			
		||||
func PidLabel(pid int) (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClearLabels clears all reserved labels
 | 
			
		||||
func ClearLabels() {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ReserveLabel(label string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@@ -58,8 +83,8 @@ func ReleaseLabel(label string) error {
 | 
			
		||||
 | 
			
		||||
// DupSecOpt takes a process label and returns security options that
 | 
			
		||||
// can be used to set duplicate labels on future container processes
 | 
			
		||||
func DupSecOpt(src string) []string {
 | 
			
		||||
	return nil
 | 
			
		||||
func DupSecOpt(src string) ([]string, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DisableSecOpt returns a security opt that can disable labeling
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										100
									
								
								vendor/github.com/opencontainers/selinux/go-selinux/label/label_selinux.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										100
									
								
								vendor/github.com/opencontainers/selinux/go-selinux/label/label_selinux.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -4,6 +4,8 @@ package label
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/user"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/opencontainers/selinux/go-selinux"
 | 
			
		||||
@@ -24,17 +26,29 @@ var ErrIncompatibleLabel = fmt.Errorf("Bad SELinux option z and Z can not be use
 | 
			
		||||
// the container.  A list of options can be passed into this function to alter
 | 
			
		||||
// the labels.  The labels returned will include a random MCS String, that is
 | 
			
		||||
// guaranteed to be unique.
 | 
			
		||||
func InitLabels(options []string) (string, string, error) {
 | 
			
		||||
func InitLabels(options []string) (plabel string, mlabel string, Err error) {
 | 
			
		||||
	if !selinux.GetEnabled() {
 | 
			
		||||
		return "", "", nil
 | 
			
		||||
	}
 | 
			
		||||
	processLabel, mountLabel := selinux.ContainerLabels()
 | 
			
		||||
	if processLabel != "" {
 | 
			
		||||
		pcon := selinux.NewContext(processLabel)
 | 
			
		||||
		mcon := selinux.NewContext(mountLabel)
 | 
			
		||||
		defer func() {
 | 
			
		||||
			if Err != nil {
 | 
			
		||||
				ReleaseLabel(mountLabel)
 | 
			
		||||
			}
 | 
			
		||||
		}()
 | 
			
		||||
		pcon, err := selinux.NewContext(processLabel)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", "", err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		mcon, err := selinux.NewContext(mountLabel)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", "", err
 | 
			
		||||
		}
 | 
			
		||||
		for _, opt := range options {
 | 
			
		||||
			if opt == "disable" {
 | 
			
		||||
				return "", "", nil
 | 
			
		||||
				return "", mountLabel, nil
 | 
			
		||||
			}
 | 
			
		||||
			if i := strings.Index(opt, ":"); i == -1 {
 | 
			
		||||
				return "", "", fmt.Errorf("Bad label option %q, valid options 'disable' or \n'user, role, level, type' followed by ':' and a value", opt)
 | 
			
		||||
@@ -90,6 +104,28 @@ func SetProcessLabel(processLabel string) error {
 | 
			
		||||
	return selinux.SetExecLabel(processLabel)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetSocketLabel takes a process label and tells the kernel to assign the
 | 
			
		||||
// label to the next socket that gets created
 | 
			
		||||
func SetSocketLabel(processLabel string) error {
 | 
			
		||||
	return selinux.SetSocketLabel(processLabel)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SocketLabel retrieves the current default socket label setting
 | 
			
		||||
func SocketLabel() (string, error) {
 | 
			
		||||
	return selinux.SocketLabel()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetKeyLabel takes a process label and tells the kernel to assign the
 | 
			
		||||
// label to the next kernel keyring that gets created
 | 
			
		||||
func SetKeyLabel(processLabel string) error {
 | 
			
		||||
	return selinux.SetKeyLabel(processLabel)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// KeyLabel retrieves the current default kernel keyring label setting
 | 
			
		||||
func KeyLabel() (string, error) {
 | 
			
		||||
	return selinux.KeyLabel()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ProcessLabel returns the process label that the kernel will assign
 | 
			
		||||
// to the next program executed by the current process.  If "" is returned
 | 
			
		||||
// this indicates that the default labeling will happen for the process.
 | 
			
		||||
@@ -97,7 +133,7 @@ func ProcessLabel() (string, error) {
 | 
			
		||||
	return selinux.ExecLabel()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetFileLabel returns the label for specified path
 | 
			
		||||
// FileLabel returns the label for specified path
 | 
			
		||||
func FileLabel(path string) (string, error) {
 | 
			
		||||
	return selinux.FileLabel(path)
 | 
			
		||||
}
 | 
			
		||||
@@ -130,13 +166,56 @@ func Relabel(path string, fileLabel string, shared bool) error {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	exclude_paths := map[string]bool{"/": true, "/usr": true, "/etc": true, "/tmp": true, "/home": true, "/run": true, "/var": true, "/root": true}
 | 
			
		||||
	exclude_paths := map[string]bool{
 | 
			
		||||
		"/":           true,
 | 
			
		||||
		"/bin":        true,
 | 
			
		||||
		"/boot":       true,
 | 
			
		||||
		"/dev":        true,
 | 
			
		||||
		"/etc":        true,
 | 
			
		||||
		"/etc/passwd": true,
 | 
			
		||||
		"/etc/pki":    true,
 | 
			
		||||
		"/etc/shadow": true,
 | 
			
		||||
		"/home":       true,
 | 
			
		||||
		"/lib":        true,
 | 
			
		||||
		"/lib64":      true,
 | 
			
		||||
		"/media":      true,
 | 
			
		||||
		"/opt":        true,
 | 
			
		||||
		"/proc":       true,
 | 
			
		||||
		"/root":       true,
 | 
			
		||||
		"/run":        true,
 | 
			
		||||
		"/sbin":       true,
 | 
			
		||||
		"/srv":        true,
 | 
			
		||||
		"/sys":        true,
 | 
			
		||||
		"/tmp":        true,
 | 
			
		||||
		"/usr":        true,
 | 
			
		||||
		"/var":        true,
 | 
			
		||||
		"/var/lib":    true,
 | 
			
		||||
		"/var/log":    true,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if home := os.Getenv("HOME"); home != "" {
 | 
			
		||||
		exclude_paths[home] = true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if sudoUser := os.Getenv("SUDO_USER"); sudoUser != "" {
 | 
			
		||||
		if usr, err := user.Lookup(sudoUser); err == nil {
 | 
			
		||||
			exclude_paths[usr.HomeDir] = true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if path != "/" {
 | 
			
		||||
		path = strings.TrimSuffix(path, "/")
 | 
			
		||||
	}
 | 
			
		||||
	if exclude_paths[path] {
 | 
			
		||||
		return fmt.Errorf("SELinux relabeling of %s is not allowed", path)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if shared {
 | 
			
		||||
		c := selinux.NewContext(fileLabel)
 | 
			
		||||
		c, err := selinux.NewContext(fileLabel)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		c["level"] = "s0"
 | 
			
		||||
		fileLabel = c.Get()
 | 
			
		||||
	}
 | 
			
		||||
@@ -156,6 +235,11 @@ func Init() {
 | 
			
		||||
	selinux.GetEnabled()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClearLabels will clear all reserved labels
 | 
			
		||||
func ClearLabels() {
 | 
			
		||||
	selinux.ClearLabels()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReserveLabel will record the fact that the MCS label has already been used.
 | 
			
		||||
// This will prevent InitLabels from using the MCS label in a newly created
 | 
			
		||||
// container
 | 
			
		||||
@@ -174,7 +258,7 @@ func ReleaseLabel(label string) error {
 | 
			
		||||
 | 
			
		||||
// DupSecOpt takes a process label and returns security options that
 | 
			
		||||
// can be used to set duplicate labels on future container processes
 | 
			
		||||
func DupSecOpt(src string) []string {
 | 
			
		||||
func DupSecOpt(src string) ([]string, error) {
 | 
			
		||||
	return selinux.DupSecOpt(src)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user