rkt: Fix incomplete selinux context string when the option is partial.
Add Getfilecon() into the selinux interface.
This commit is contained in:
@@ -16,12 +16,14 @@ limitations under the License.
|
||||
|
||||
package selinux
|
||||
|
||||
// chconRunner knows how to chcon a directory.
|
||||
type ChconRunner interface {
|
||||
// SelinuxContextRunner knows how to chcon of a directory and
|
||||
// how to get the selinux context of a file.
|
||||
type SelinuxContextRunner interface {
|
||||
SetContext(dir, context string) error
|
||||
Getfilecon(path string) (string, error)
|
||||
}
|
||||
|
||||
// newChconRunner returns a new chconRunner.
|
||||
func NewChconRunner() ChconRunner {
|
||||
return &realChconRunner{}
|
||||
// NewSelinuxContextRunner returns a new chconRunner.
|
||||
func NewSelinuxContextRunner() SelinuxContextRunner {
|
||||
return &realSelinuxContextRunner{}
|
||||
}
|
||||
|
@@ -19,12 +19,14 @@ limitations under the License.
|
||||
package selinux
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/selinux"
|
||||
)
|
||||
|
||||
type realChconRunner struct{}
|
||||
type realSelinuxContextRunner struct{}
|
||||
|
||||
func (_ *realChconRunner) SetContext(dir, context string) error {
|
||||
func (_ *realSelinuxContextRunner) SetContext(dir, context string) error {
|
||||
// If SELinux is not enabled, return an empty string
|
||||
if !selinux.SelinuxEnabled() {
|
||||
return nil
|
||||
@@ -32,3 +34,10 @@ func (_ *realChconRunner) SetContext(dir, context string) error {
|
||||
|
||||
return selinux.Setfilecon(dir, context)
|
||||
}
|
||||
|
||||
func (_ *realSelinuxContextRunner) Getfilecon(path string) (string, error) {
|
||||
if !selinux.SelinuxEnabled() {
|
||||
return "", fmt.Errorf("SELinux is not enabled")
|
||||
}
|
||||
return selinux.Getfilecon(path)
|
||||
}
|
||||
|
@@ -18,9 +18,14 @@ limitations under the License.
|
||||
|
||||
package selinux
|
||||
|
||||
type realChconRunner struct{}
|
||||
type realSelinuxContextRunner struct{}
|
||||
|
||||
func (_ *realChconRunner) SetContext(dir, context string) error {
|
||||
func (_ *realSelinuxContextRunner) SetContext(dir, context string) error {
|
||||
// NOP
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *realSelinuxContextRunner) Getfilecon(path string) (string, error) {
|
||||
// NOP
|
||||
return "", nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user