Skip to content

Commit

Permalink
Merge pull request #6381 from fidencio/wip/backport-seutil-fix-contai…
Browse files Browse the repository at this point in the history
…ner_kvm_t-type-detection-to-release-1.5

[release/1.5] seutil: Fix setting the "container_kvm_t" label
  • Loading branch information
crosbymichael committed Dec 15, 2021
2 parents 63c9773 + da5749b commit 167c3e0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
9 changes: 1 addition & 8 deletions pkg/cri/server/helpers_linux.go
Expand Up @@ -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)
}
30 changes: 0 additions & 30 deletions pkg/seutil/seutil.go
Expand Up @@ -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() {
Expand Down

0 comments on commit 167c3e0

Please sign in to comment.