Merge pull request #6372 from fidencio/wip/seutil-fix-container_kvm_t-type-detection
seutil: Fix setting the "container_kvm_t" label
This commit is contained in:
		| @@ -269,17 +269,10 @@ func modifyProcessLabel(runtimeType string, spec *specs.Spec) error { | ||||
| 	if !isVMBasedRuntime(runtimeType) { | ||||
| 		return nil | ||||
| 	} | ||||
| 	l, err := getKVMLabel(spec.Process.SelinuxLabel) | ||||
| 	l, err := seutil.ChangeToKVM(spec.Process.SelinuxLabel) | ||||
| 	if err != nil { | ||||
| 		return errors.Wrap(err, "failed to get selinux kvm label") | ||||
| 	} | ||||
| 	spec.Process.SelinuxLabel = l | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func getKVMLabel(l string) (string, error) { | ||||
| 	if !seutil.HasType("container_kvm_t") { | ||||
| 		return "", nil | ||||
| 	} | ||||
| 	return seutil.ChangeToKVM(l) | ||||
| } | ||||
|   | ||||
| @@ -17,39 +17,9 @@ | ||||
| package seutil | ||||
|  | ||||
| import ( | ||||
| 	"bufio" | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/opencontainers/selinux/go-selinux" | ||||
| ) | ||||
|  | ||||
| var seTypes map[string]struct{} | ||||
|  | ||||
| const typePath = "/etc/selinux/targeted/contexts/customizable_types" | ||||
|  | ||||
| func init() { | ||||
| 	seTypes = make(map[string]struct{}) | ||||
| 	if !selinux.GetEnabled() { | ||||
| 		return | ||||
| 	} | ||||
| 	f, err := os.Open(typePath) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	defer f.Close() | ||||
| 	s := bufio.NewScanner(f) | ||||
| 	for s.Scan() { | ||||
| 		seTypes[s.Text()] = struct{}{} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // HasType returns true if the underlying system has the | ||||
| // provided selinux type enabled. | ||||
| func HasType(name string) bool { | ||||
| 	_, ok := seTypes[name] | ||||
| 	return ok | ||||
| } | ||||
|  | ||||
| // ChangeToKVM process label | ||||
| func ChangeToKVM(l string) (string, error) { | ||||
| 	if l == "" || !selinux.GetEnabled() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Derek McGowan
					Derek McGowan