Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7fb99442
Commit
7fb99442
authored
Oct 25, 2016
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor pkg/util/selinux
parent
ea423110
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
42 deletions
+55
-42
kubelet_volumes.go
pkg/kubelet/kubelet_volumes.go
+2
-2
rkt.go
pkg/kubelet/rkt/rkt.go
+1
-1
doc.go
pkg/util/selinux/doc.go
+2
-1
selinux.go
pkg/util/selinux/selinux.go
+17
-7
selinux_linux.go
pkg/util/selinux/selinux_linux.go
+22
-13
selinux_unsupported.go
pkg/util/selinux/selinux_unsupported.go
+9
-7
empty_dir.go
pkg/volume/empty_dir/empty_dir.go
+2
-1
empty_dir_linux.go
pkg/volume/empty_dir/empty_dir_linux.go
+0
-6
empty_dir_unsupported.go
pkg/volume/empty_dir/empty_dir_unsupported.go
+0
-4
No files found.
pkg/kubelet/kubelet_volumes.go
View file @
7fb99442
...
@@ -94,7 +94,7 @@ func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap)
...
@@ -94,7 +94,7 @@ func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap)
return
err
return
err
}
}
selinuxRunner
:=
selinux
.
NewS
elinuxContext
Runner
()
selinuxRunner
:=
selinux
.
NewS
ELinux
Runner
()
// Apply the pod's Level to the rootDirContext
// Apply the pod's Level to the rootDirContext
rootDirSELinuxOptions
,
err
:=
securitycontext
.
ParseSELinuxOptions
(
rootDirContext
)
rootDirSELinuxOptions
,
err
:=
securitycontext
.
ParseSELinuxOptions
(
rootDirContext
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -115,7 +115,7 @@ func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap)
...
@@ -115,7 +115,7 @@ func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
selinuxRunner
.
Set
Context
(
path
,
volumeContext
)
return
selinuxRunner
.
Set
filecon
(
path
,
volumeContext
)
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubelet/rkt/rkt.go
View file @
7fb99442
...
@@ -1082,7 +1082,7 @@ func (r *Runtime) preparePodArgs(manifest *appcschema.PodManifest, manifestFileN
...
@@ -1082,7 +1082,7 @@ func (r *Runtime) preparePodArgs(manifest *appcschema.PodManifest, manifestFileN
}
}
func
(
r
*
Runtime
)
getSelinuxContext
(
opt
*
api
.
SELinuxOptions
)
(
string
,
error
)
{
func
(
r
*
Runtime
)
getSelinuxContext
(
opt
*
api
.
SELinuxOptions
)
(
string
,
error
)
{
selinuxRunner
:=
selinux
.
NewS
elinuxContext
Runner
()
selinuxRunner
:=
selinux
.
NewS
ELinux
Runner
()
str
,
err
:=
selinuxRunner
.
Getfilecon
(
r
.
config
.
Dir
)
str
,
err
:=
selinuxRunner
.
Getfilecon
(
r
.
config
.
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
pkg/util/selinux/doc.go
View file @
7fb99442
...
@@ -14,5 +14,6 @@ See the License for the specific language governing permissions and
...
@@ -14,5 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
// Package selinux contains selinux utility functions.
// Package selinux contains wrapper functions for the libcontainer SELinux
// package. A NOP implementation is provided for non-linux platforms.
package
selinux
// import "k8s.io/kubernetes/pkg/util/selinux"
package
selinux
// import "k8s.io/kubernetes/pkg/util/selinux"
pkg/util/selinux/selinux.go
View file @
7fb99442
...
@@ -16,14 +16,24 @@ limitations under the License.
...
@@ -16,14 +16,24 @@ limitations under the License.
package
selinux
package
selinux
// SelinuxContextRunner knows how to chcon of a directory and
// Note: the libcontainer SELinux package is only built for Linux, so it is
// how to get the selinux context of a file.
// necessary to have a NOP wrapper which is built for non-Linux platforms to
type
SelinuxContextRunner
interface
{
// allow code that links to this package not to differentiate its own methods
SetContext
(
dir
,
context
string
)
error
// for Linux and non-Linux platforms.
//
// SELinuxRunner wraps certain libcontainer SELinux calls. For more
// information, see:
//
// https://github.com/opencontainers/runc/blob/master/libcontainer/selinux/selinux.go
type
SELinuxRunner
interface
{
// Getfilecon returns the SELinux context for the given path or returns an
// error.
Getfilecon
(
path
string
)
(
string
,
error
)
Getfilecon
(
path
string
)
(
string
,
error
)
}
}
// NewSelinuxContextRunner returns a new chconRunner.
// NewSELinuxRunner returns a new SELinuxRunner appropriate for the platform.
func
NewSelinuxContextRunner
()
SelinuxContextRunner
{
// On Linux, all methods short-circuit and return NOP values if SELinux is
return
&
realSelinuxContextRunner
{}
// disabled. On non-Linux platforms, a NOP implementation is returned.
func
NewSELinuxRunner
()
SELinuxRunner
{
return
&
realSELinuxRunner
{}
}
}
pkg/util/selinux/selinux_linux.go
View file @
7fb99442
...
@@ -19,25 +19,34 @@ limitations under the License.
...
@@ -19,25 +19,34 @@ limitations under the License.
package
selinux
package
selinux
import
(
import
(
"fmt"
"github.com/opencontainers/runc/libcontainer/selinux"
"github.com/opencontainers/runc/libcontainer/selinux"
)
)
type
realSelinuxContextRunner
struct
{}
// SELinuxEnabled returns whether SELinux is enabled on the system. SELinux
// has a tri-state:
//
// 1. disabled: SELinux Kernel modules not loaded, SELinux policy is not
// checked during Kernel MAC checks
// 2. enforcing: Enabled; SELinux policy violations are denied and logged
// in the audit log
// 3. permissive: Enabled, but SELinux policy violations are permitted and
// logged in the audit log
//
// SELinuxEnabled returns true if SELinux is enforcing or permissive, and
// false if it is disabled.
func
SELinuxEnabled
()
bool
{
return
selinux
.
SelinuxEnabled
()
}
func
(
_
*
realSelinuxContextRunner
)
SetContext
(
dir
,
context
string
)
error
{
// realSELinuxRunner is the real implementation of SELinuxRunner interface for
// If SELinux is not enabled, return an empty string
// Linux.
if
!
selinux
.
SelinuxEnabled
()
{
type
realSELinuxRunner
struct
{}
return
nil
}
return
selinux
.
Setfilecon
(
dir
,
context
)
var
_
SELinuxRunner
=
&
realSELinuxRunner
{}
}
func
(
_
*
realS
elinuxContext
Runner
)
Getfilecon
(
path
string
)
(
string
,
error
)
{
func
(
_
*
realS
ELinux
Runner
)
Getfilecon
(
path
string
)
(
string
,
error
)
{
if
!
selinux
.
Sel
inuxEnabled
()
{
if
!
SEL
inuxEnabled
()
{
return
""
,
fmt
.
Errorf
(
"SELinux is not enabled"
)
return
""
,
nil
}
}
return
selinux
.
Getfilecon
(
path
)
return
selinux
.
Getfilecon
(
path
)
}
}
pkg/util/selinux/selinux_unsupported.go
View file @
7fb99442
...
@@ -18,14 +18,16 @@ limitations under the License.
...
@@ -18,14 +18,16 @@ limitations under the License.
package
selinux
package
selinux
type
realSelinuxContextRunner
struct
{}
// SELinuxEnabled always returns false on non-linux platforms.
func
SELinuxEnabled
()
bool
{
func
(
_
*
realSelinuxContextRunner
)
SetContext
(
dir
,
context
string
)
error
{
return
false
// NOP
return
nil
}
}
func
(
_
*
realSelinuxContextRunner
)
Getfilecon
(
path
string
)
(
string
,
error
)
{
// realSELinuxRunner is the NOP implementation of the SELinuxRunner interface.
// NOP
type
realSELinuxRunner
struct
{}
var
_
SELinuxRunner
=
&
realSELinuxRunner
{}
func
(
_
*
realSELinuxRunner
)
Getfilecon
(
path
string
)
(
string
,
error
)
{
return
""
,
nil
return
""
,
nil
}
}
pkg/volume/empty_dir/empty_dir.go
View file @
7fb99442
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/selinux"
"k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
...
@@ -204,7 +205,7 @@ func (ed *emptyDir) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -204,7 +205,7 @@ func (ed *emptyDir) SetUpAt(dir string, fsGroup *int64) error {
// Determine the effective SELinuxOptions to use for this volume.
// Determine the effective SELinuxOptions to use for this volume.
securityContext
:=
""
securityContext
:=
""
if
selinuxEnabled
()
{
if
selinux
.
SELinux
Enabled
()
{
securityContext
=
ed
.
rootContext
securityContext
=
ed
.
rootContext
}
}
...
...
pkg/volume/empty_dir/empty_dir_linux.go
View file @
7fb99442
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"syscall"
"syscall"
"github.com/golang/glog"
"github.com/golang/glog"
"github.com/opencontainers/runc/libcontainer/selinux"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
)
)
...
@@ -52,8 +51,3 @@ func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, er
...
@@ -52,8 +51,3 @@ func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, er
}
}
return
mediumUnknown
,
!
notMnt
,
nil
return
mediumUnknown
,
!
notMnt
,
nil
}
}
// selinuxEnabled determines whether SELinux is enabled.
func
selinuxEnabled
()
bool
{
return
selinux
.
SelinuxEnabled
()
}
pkg/volume/empty_dir/empty_dir_unsupported.go
View file @
7fb99442
...
@@ -30,7 +30,3 @@ type realMountDetector struct {
...
@@ -30,7 +30,3 @@ type realMountDetector struct {
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
storageMedium
,
bool
,
error
)
{
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
storageMedium
,
bool
,
error
)
{
return
mediumUnknown
,
false
,
nil
return
mediumUnknown
,
false
,
nil
}
}
func
selinuxEnabled
()
bool
{
return
false
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment