mirror of https://github.com/k3s-io/k3s
Remove volume SELinux relabeling when pod uses host IPC or PID ns
parent
ca9a455f2c
commit
a2d3da52be
|
@ -252,15 +252,6 @@ func (kl *Kubelet) GenerateRunContainerOptions(pod *api.Pod, container *api.Cont
|
|||
volumes := kl.volumeManager.GetMountedVolumesForPod(podName)
|
||||
|
||||
opts.PortMappings = makePortMappings(container)
|
||||
// Docker does not relabel volumes if the container is running
|
||||
// in the host pid or ipc namespaces so the kubelet must
|
||||
// relabel the volumes
|
||||
if pod.Spec.SecurityContext != nil && (pod.Spec.SecurityContext.HostIPC || pod.Spec.SecurityContext.HostPID) {
|
||||
err = kl.relabelVolumes(pod, volumes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opts.Mounts, err = makeMounts(pod, kl.getPodDir(pod.UID), container, hostname, hostDomainName, podIP, volumes)
|
||||
if err != nil {
|
||||
|
|
|
@ -19,16 +19,13 @@ package kubelet
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/securitycontext"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/util/selinux"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
|
||||
|
@ -81,51 +78,6 @@ func (kl *Kubelet) newVolumeMounterFromPlugins(spec *volume.Spec, pod *api.Pod,
|
|||
return physicalMounter, nil
|
||||
}
|
||||
|
||||
// relabelVolumes relabels SELinux volumes to match the pod's
|
||||
// SELinuxOptions specification. This is only needed if the pod uses
|
||||
// hostPID or hostIPC. Otherwise relabeling is delegated to docker.
|
||||
func (kl *Kubelet) relabelVolumes(pod *api.Pod, volumes kubecontainer.VolumeMap) error {
|
||||
if pod.Spec.SecurityContext.SELinuxOptions == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
rootDirContext, err := kl.getRootDirContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
selinuxRunner := selinux.NewSELinuxRunner()
|
||||
// Apply the pod's Level to the rootDirContext
|
||||
rootDirSELinuxOptions, err := securitycontext.ParseSELinuxOptions(rootDirContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rootDirSELinuxOptions.Level = pod.Spec.SecurityContext.SELinuxOptions.Level
|
||||
volumeContext := fmt.Sprintf("%s:%s:%s:%s", rootDirSELinuxOptions.User, rootDirSELinuxOptions.Role, rootDirSELinuxOptions.Type, rootDirSELinuxOptions.Level)
|
||||
|
||||
for _, vol := range volumes {
|
||||
if vol.Mounter.GetAttributes().Managed && vol.Mounter.GetAttributes().SupportsSELinux {
|
||||
// Relabel the volume and its content to match the 'Level' of the pod
|
||||
path, err := volume.GetPath(vol.Mounter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return selinuxRunner.Setfilecon(path, volumeContext)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vol.SELinuxLabeled = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// cleanupOrphanedPodDirs removes the volumes of pods that should not be
|
||||
// running and that have no containers running.
|
||||
func (kl *Kubelet) cleanupOrphanedPodDirs(
|
||||
|
|
Loading…
Reference in New Issue