Support volume relabling for pods which specify an SELinux label
This commit is contained in:
18
pkg/util/selinux/doc.go
Normal file
18
pkg/util/selinux/doc.go
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package selinux contains selinux utility functions.
|
||||
package selinux
|
27
pkg/util/selinux/selinux.go
Normal file
27
pkg/util/selinux/selinux.go
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package selinux
|
||||
|
||||
// chconRunner knows how to chcon a directory.
|
||||
type ChconRunner interface {
|
||||
SetContext(dir, context string) error
|
||||
}
|
||||
|
||||
// newChconRunner returns a new chconRunner.
|
||||
func NewChconRunner() ChconRunner {
|
||||
return &realChconRunner{}
|
||||
}
|
34
pkg/util/selinux/selinux_linux.go
Normal file
34
pkg/util/selinux/selinux_linux.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package selinux
|
||||
|
||||
import (
|
||||
"github.com/docker/libcontainer/selinux"
|
||||
)
|
||||
|
||||
type realChconRunner struct{}
|
||||
|
||||
func (_ *realChconRunner) SetContext(dir, context string) error {
|
||||
// If SELinux is not enabled, return an empty string
|
||||
if !selinux.SelinuxEnabled() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return selinux.Setfilecon(dir, context)
|
||||
}
|
26
pkg/util/selinux/selinux_unsupported.go
Normal file
26
pkg/util/selinux/selinux_unsupported.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package selinux
|
||||
|
||||
type realChconRunner struct{}
|
||||
|
||||
func (_ *realChconRunner) SetContext(dir, context string) error {
|
||||
// NOP
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user