Skip to content

Commit 3f8f999

Browse files
authored
Merge pull request kubernetes#90948 from pjbgf/seccomp-least-priv-dockershim
Add seccomp least privilege for docker sandbox
2 parents c46c1c0 + 6db5b5c commit 3f8f999

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pkg/kubelet/dockershim/docker_sandbox.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,16 +659,19 @@ func (ds *dockerService) makeSandboxDockerConfig(c *runtimeapi.PodSandboxConfig,
659659
}
660660

661661
// Set security options.
662-
securityOpts, err := ds.getSecurityOpts(c.GetLinux().GetSecurityContext().GetSeccompProfilePath(), securityOptSeparator)
663-
if err != nil {
664-
return nil, fmt.Errorf("failed to generate sandbox security options for sandbox %q: %v", c.Metadata.Name, err)
665-
}
662+
securityOpts := ds.getSandBoxSecurityOpts(securityOptSeparator)
666663
hc.SecurityOpt = append(hc.SecurityOpt, securityOpts...)
667664

668665
applyExperimentalCreateConfig(createConfig, c.Annotations)
669666
return createConfig, nil
670667
}
671668

669+
func (ds *dockerService) getSandBoxSecurityOpts(separator rune) []string {
670+
// run sandbox with no-new-privileges and using runtime/default
671+
// sending no "seccomp=" means docker will use default profile
672+
return []string{"no-new-privileges"}
673+
}
674+
672675
// networkNamespaceMode returns the network runtimeapi.NamespaceMode for this container.
673676
// Supports: POD, NODE
674677
func networkNamespaceMode(container *dockertypes.ContainerJSON) runtimeapi.NamespaceMode {

pkg/kubelet/dockershim/docker_sandbox_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ func TestSandboxStatus(t *testing.T) {
156156
assert.Error(t, err, fmt.Sprintf("status of sandbox: %+v", statusResp))
157157
}
158158

159+
// TestSandboxHasLeastPrivilegesConfig tests that the sandbox is set with no-new-privileges
160+
// and it uses runtime/default seccomp profile.
161+
func TestSandboxHasLeastPrivilegesConfig(t *testing.T) {
162+
ds, _, _ := newTestDockerService()
163+
config := makeSandboxConfig("foo", "bar", "1", 0)
164+
165+
// test the default
166+
createConfig, err := ds.makeSandboxDockerConfig(config, defaultSandboxImage)
167+
assert.NoError(t, err)
168+
assert.Equal(t, len(createConfig.HostConfig.SecurityOpt), 1, "sandbox should use runtime/default")
169+
assert.Equal(t, "no-new-privileges", createConfig.HostConfig.SecurityOpt[0], "no-new-privileges not set")
170+
}
171+
159172
// TestSandboxStatusAfterRestart tests that retrieving sandbox status returns
160173
// an IP address even if RunPodSandbox() was not yet called for this pod, as
161174
// would happen on kubelet restart

0 commit comments

Comments
 (0)