diff --git a/pkg/kubelet/dockershim/helpers_windows.go b/pkg/kubelet/dockershim/helpers_windows.go index 6b3665e876f..63d8de0342d 100644 --- a/pkg/kubelet/dockershim/helpers_windows.go +++ b/pkg/kubelet/dockershim/helpers_windows.go @@ -76,6 +76,9 @@ func (ds *dockerService) updateCreateConfig( CPUPercent: rOpts.CpuMaximum, } } + + // Apply security context. + applyWindowsContainerSecurityContext(wc.GetSecurityContext(), createConfig.Config, createConfig.HostConfig) } applyExperimentalCreateConfig(createConfig, sandboxConfig.Annotations) @@ -83,6 +86,17 @@ func (ds *dockerService) updateCreateConfig( return nil } +// applyWindowsContainerSecurityContext updates docker container options according to security context. +func applyWindowsContainerSecurityContext(wsc *runtimeapi.WindowsContainerSecurityContext, config *dockercontainer.Config, hc *dockercontainer.HostConfig) { + if wsc == nil { + return + } + + if wsc.GetRunAsUsername() != "" { + config.User = wsc.GetRunAsUsername() + } +} + func (ds *dockerService) determinePodIPBySandboxID(sandboxID string, sandbox *dockertypes.ContainerJSON) string { // Versions and feature support // ============================