diff --git a/pkg/kubelet/dockershim/security_context.go b/pkg/kubelet/dockershim/security_context.go index f5ba3a39d0b..f1f3025b9a6 100644 --- a/pkg/kubelet/dockershim/security_context.go +++ b/pkg/kubelet/dockershim/security_context.go @@ -167,7 +167,6 @@ func modifyHostNetworkOptionForContainer(hostNetwork bool, sandboxID string, hc hc.NetworkMode = dockercontainer.NetworkMode(sandboxNSMode) hc.IpcMode = dockercontainer.IpcMode(sandboxNSMode) hc.UTSMode = "" - hc.PidMode = "" if hostNetwork { hc.UTSMode = namespaceModeHost diff --git a/pkg/kubelet/dockershim/security_context_test.go b/pkg/kubelet/dockershim/security_context_test.go index a0f54e95c05..9b89b46703f 100644 --- a/pkg/kubelet/dockershim/security_context_test.go +++ b/pkg/kubelet/dockershim/security_context_test.go @@ -306,6 +306,7 @@ func TestModifyContainerNamespaceOptions(t *testing.T) { expected: &dockercontainer.HostConfig{ NetworkMode: dockercontainer.NetworkMode(sandboxNSMode), IpcMode: dockercontainer.IpcMode(sandboxNSMode), + PidMode: namespaceModeHost, }, }, } diff --git a/pkg/kubelet/kuberuntime/security_context.go b/pkg/kubelet/kuberuntime/security_context.go index 4ccbe1a45b6..0cc784fc3aa 100644 --- a/pkg/kubelet/kuberuntime/security_context.go +++ b/pkg/kubelet/kuberuntime/security_context.go @@ -41,24 +41,24 @@ func (m *kubeGenericRuntimeManager) determineEffectiveSecurityContext(pod *v1.Po } // set namespace options and supplemental groups. - podSc := pod.Spec.SecurityContext - if podSc == nil { - return synthesized - } synthesized.NamespaceOptions = &runtimeapi.NamespaceOption{ HostNetwork: pod.Spec.HostNetwork, HostIpc: pod.Spec.HostIPC, HostPid: pod.Spec.HostPID, } - if podSc.FSGroup != nil { - synthesized.SupplementalGroups = append(synthesized.SupplementalGroups, *podSc.FSGroup) + podSc := pod.Spec.SecurityContext + if podSc != nil { + if podSc.FSGroup != nil { + synthesized.SupplementalGroups = append(synthesized.SupplementalGroups, *podSc.FSGroup) + } + + if podSc.SupplementalGroups != nil { + synthesized.SupplementalGroups = append(synthesized.SupplementalGroups, podSc.SupplementalGroups...) + } } if groups := m.runtimeHelper.GetExtraSupplementalGroupsForPod(pod); len(groups) > 0 { synthesized.SupplementalGroups = append(synthesized.SupplementalGroups, groups...) } - if podSc.SupplementalGroups != nil { - synthesized.SupplementalGroups = append(synthesized.SupplementalGroups, podSc.SupplementalGroups...) - } return synthesized }