Skip to content

Commit

Permalink
cri: add devices for privileged container
Browse files Browse the repository at this point in the history
Signed-off-by: scuzhanglei <greatzhanglei@gmail.com>
  • Loading branch information
scuzhanglei committed Sep 10, 2021
1 parent e00f87f commit 756f4a3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pkg/cri/server/container_create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,17 @@ func (c *criService) containerSpec(
}
}

specOpts = append(specOpts, customopts.WithDevices(c.os, config, c.config.DeviceOwnershipFromSecurityContext),
customopts.WithCapabilities(securityContext, c.allCaps))

if securityContext.GetPrivileged() {
if !sandboxConfig.GetLinux().GetSecurityContext().GetPrivileged() {
return nil, errors.New("no privileged container allowed in sandbox")
}
specOpts = append(specOpts, oci.WithPrivileged)
if !ociRuntime.PrivilegedWithoutHostDevices {
specOpts = append(specOpts, oci.WithHostDevices, oci.WithAllDevicesAllowed)
} else {
// add requested devices by the config as host devices are not automatically added
specOpts = append(specOpts, customopts.WithDevices(c.os, config, c.config.DeviceOwnershipFromSecurityContext),
customopts.WithCapabilities(securityContext, c.allCaps))
}
} else { // not privileged
specOpts = append(specOpts, customopts.WithDevices(c.os, config, c.config.DeviceOwnershipFromSecurityContext),
customopts.WithCapabilities(securityContext, c.allCaps))
}

// Clear all ambient capabilities. The implication of non-root + caps
Expand Down

0 comments on commit 756f4a3

Please sign in to comment.