mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Always relabel supported volumes when SELinux is enabled
This commit is contained in:
parent
a2d3da52be
commit
21116a7dbe
@ -65,6 +65,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/oom"
|
"k8s.io/kubernetes/pkg/util/oom"
|
||||||
"k8s.io/kubernetes/pkg/util/procfs"
|
"k8s.io/kubernetes/pkg/util/procfs"
|
||||||
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
|
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
|
||||||
|
"k8s.io/kubernetes/pkg/util/selinux"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
utilstrings "k8s.io/kubernetes/pkg/util/strings"
|
utilstrings "k8s.io/kubernetes/pkg/util/strings"
|
||||||
"k8s.io/kubernetes/pkg/util/term"
|
"k8s.io/kubernetes/pkg/util/term"
|
||||||
@ -507,20 +508,14 @@ func makeEnvList(envs []kubecontainer.EnvVar) (result []string) {
|
|||||||
// '<HostPath>:<ContainerPath>', or
|
// '<HostPath>:<ContainerPath>', or
|
||||||
// '<HostPath>:<ContainerPath>:ro', if the path is read only, or
|
// '<HostPath>:<ContainerPath>:ro', if the path is read only, or
|
||||||
// '<HostPath>:<ContainerPath>:Z', if the volume requires SELinux
|
// '<HostPath>:<ContainerPath>:Z', if the volume requires SELinux
|
||||||
// relabeling and the pod provides an SELinux label
|
// relabeling
|
||||||
func makeMountBindings(mounts []kubecontainer.Mount, podHasSELinuxLabel bool) (result []string) {
|
func makeMountBindings(mounts []kubecontainer.Mount) (result []string) {
|
||||||
for _, m := range mounts {
|
for _, m := range mounts {
|
||||||
bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath)
|
bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath)
|
||||||
if m.ReadOnly {
|
if m.ReadOnly {
|
||||||
bind += ":ro"
|
bind += ":ro"
|
||||||
}
|
}
|
||||||
// Only request relabeling if the pod provides an
|
if m.SELinuxRelabel && selinux.SELinuxEnabled() {
|
||||||
// SELinux context. If the pod does not provide an
|
|
||||||
// SELinux context relabeling will label the volume
|
|
||||||
// with the container's randomly allocated MCS label.
|
|
||||||
// This would restrict access to the volume to the
|
|
||||||
// container which mounts it first.
|
|
||||||
if m.SELinuxRelabel && podHasSELinuxLabel {
|
|
||||||
if m.ReadOnly {
|
if m.ReadOnly {
|
||||||
bind += ",Z"
|
bind += ",Z"
|
||||||
} else {
|
} else {
|
||||||
@ -646,8 +641,7 @@ func (dm *DockerManager) runContainer(
|
|||||||
{PathOnHost: "/dev/nvidia-uvm", PathInContainer: "/dev/nvidia-uvm", CgroupPermissions: "mrw"},
|
{PathOnHost: "/dev/nvidia-uvm", PathInContainer: "/dev/nvidia-uvm", CgroupPermissions: "mrw"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
podHasSELinuxLabel := pod.Spec.SecurityContext != nil && pod.Spec.SecurityContext.SELinuxOptions != nil
|
binds := makeMountBindings(opts.Mounts)
|
||||||
binds := makeMountBindings(opts.Mounts, podHasSELinuxLabel)
|
|
||||||
// The reason we create and mount the log file in here (not in kubelet) is because
|
// The reason we create and mount the log file in here (not in kubelet) is because
|
||||||
// the file's location depends on the ID of the container, and we need to create and
|
// the file's location depends on the ID of the container, and we need to create and
|
||||||
// mount the file before actually starting the container.
|
// mount the file before actually starting the container.
|
||||||
|
Loading…
Reference in New Issue
Block a user