Merge pull request #5865 from dcantah/windows-pod-runasusername
Add RunAsUserName functionality for the Windows pod sandbox container
This commit is contained in:
commit
af1a0908d0
@ -56,6 +56,25 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
|||||||
|
|
||||||
specOpts = append(specOpts, customopts.WithWindowsDefaultSandboxShares)
|
specOpts = append(specOpts, customopts.WithWindowsDefaultSandboxShares)
|
||||||
|
|
||||||
|
// Start with the image config user and override below if RunAsUsername is not "".
|
||||||
|
username := imageConfig.User
|
||||||
|
|
||||||
|
runAsUser := config.GetWindows().GetSecurityContext().GetRunAsUsername()
|
||||||
|
if runAsUser != "" {
|
||||||
|
username = runAsUser
|
||||||
|
}
|
||||||
|
|
||||||
|
cs := config.GetWindows().GetSecurityContext().GetCredentialSpec()
|
||||||
|
if cs != "" {
|
||||||
|
specOpts = append(specOpts, customopts.WithWindowsCredentialSpec(cs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// There really isn't a good Windows way to verify that the username is available in the
|
||||||
|
// image as early as here like there is for Linux. Later on in the stack hcsshim
|
||||||
|
// will handle the behavior of erroring out if the user isn't available in the image
|
||||||
|
// when trying to run the init process.
|
||||||
|
specOpts = append(specOpts, oci.WithUser(username))
|
||||||
|
|
||||||
for pKey, pValue := range getPassthroughAnnotations(config.Annotations,
|
for pKey, pValue := range getPassthroughAnnotations(config.Annotations,
|
||||||
runtimePodAnnotations) {
|
runtimePodAnnotations) {
|
||||||
specOpts = append(specOpts, customopts.WithAnnotation(pKey, pValue))
|
specOpts = append(specOpts, customopts.WithAnnotation(pKey, pValue))
|
||||||
|
@ -53,6 +53,7 @@ func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConf
|
|||||||
Entrypoint: []string{"/pause"},
|
Entrypoint: []string{"/pause"},
|
||||||
Cmd: []string{"forever"},
|
Cmd: []string{"forever"},
|
||||||
WorkingDir: "/workspace",
|
WorkingDir: "/workspace",
|
||||||
|
User: "test-image-user",
|
||||||
}
|
}
|
||||||
specCheck := func(t *testing.T, id string, spec *runtimespec.Spec) {
|
specCheck := func(t *testing.T, id string, spec *runtimespec.Spec) {
|
||||||
assert.Equal(t, "test-hostname", spec.Hostname)
|
assert.Equal(t, "test-hostname", spec.Hostname)
|
||||||
@ -62,6 +63,13 @@ func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConf
|
|||||||
assert.Equal(t, "/workspace", spec.Process.Cwd)
|
assert.Equal(t, "/workspace", spec.Process.Cwd)
|
||||||
assert.EqualValues(t, *spec.Windows.Resources.CPU.Shares, opts.DefaultSandboxCPUshares)
|
assert.EqualValues(t, *spec.Windows.Resources.CPU.Shares, opts.DefaultSandboxCPUshares)
|
||||||
|
|
||||||
|
// Also checks if override of the image configs user is behaving.
|
||||||
|
t.Logf("Check username")
|
||||||
|
assert.Contains(t, spec.Process.User.Username, "test-user")
|
||||||
|
|
||||||
|
t.Logf("Check credential spec")
|
||||||
|
assert.Contains(t, spec.Windows.CredentialSpec, "{\"test\": \"spec\"}")
|
||||||
|
|
||||||
t.Logf("Check PodSandbox annotations")
|
t.Logf("Check PodSandbox annotations")
|
||||||
assert.Contains(t, spec.Annotations, annotations.SandboxID)
|
assert.Contains(t, spec.Annotations, annotations.SandboxID)
|
||||||
assert.EqualValues(t, spec.Annotations[annotations.SandboxID], id)
|
assert.EqualValues(t, spec.Annotations[annotations.SandboxID], id)
|
||||||
|
Loading…
Reference in New Issue
Block a user