Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Conversation

@heartlock
Copy link
Contributor

When privileged is true:

  • Enable all capabilities
  • Add all host devices
  • Clear readonly on some volumes, e.g. cgroups and /sys volumes

ref: #29 @Random-Liu Ready for review.

@Random-Liu
Copy link
Member

Will take a look tomorrow, and let's try to get it merged this week.

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Random-Liu Random-Liu added this to the v0.1.0-rc2 milestone May 30, 2017
@Random-Liu Random-Liu self-assigned this May 31, 2017
@Random-Liu Random-Liu mentioned this pull request Jun 2, 2017
42 tasks
Copy link
Member

@Random-Liu Random-Liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing. Will finish today.

"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/runtime-tools/validate"
"github.com/syndtr/gocapability/capability"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary empty line.


// TODO(random-liu): [P1] Set device mapping.
// Ref https://github.com/moby/moby/blob/master/oci/devices_linux.go.
if err := addDevices(&g, config.GetDevices(), securityContext.GetPrivileged()); err != nil {
Copy link
Member

@Random-Liu Random-Liu Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: addOCIDevices? Follow the convention.

for _, device := range devs {
dev, err := devices.DeviceFromPath(device.HostPath, device.Permissions)
if err != nil {
return fmt.Errorf("failed to add device: %v", err)
Copy link
Member

@Random-Liu Random-Liu Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Directly return error here, or add description for the other error.

}
}
return nil

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary empty line.

}

addOCIBindMounts(&g, config.GetMounts())
securityContext := config.GetLinux().GetSecurityContext()
Copy link
Member

@Random-Liu Random-Liu Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel like it would be better to add a function setOCIPrivileged, use setOCIPrivileged if privileged is set, and use other functions if not.

This groups all privileged logic together, which makes it more clear what privilege a privileged container has.

Maybe add a TODO for now.

@heartlock heartlock closed this Jun 7, 2017
@heartlock heartlock reopened this Jun 7, 2017
GID: &dev.Gid,
}
g.AddDevice(rd)
spec.Linux.Resources.Devices = append(spec.Linux.Resources.Devices, runtimespec.LinuxDeviceCgroup{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR. Don't know why runtime-tools doesn't support this, maybe we could fix it in the future. :)

}
func setOCICapabilities(g *generate.Generator, capabilities *runtime.Capability, privileged bool) error {
if privileged {
// Add all capabilities in privileged mode.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my original thought. It is strange why runtime-tools support only cap.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if privileged {
  g.SetupPrivileged(true)
  return
}
/*
Other code
*/

if err := g.AddProcessCapability(c); err != nil {
return err
for _, c := range capabilities.GetAddCapabilities() {
if err := g.AddProcessCapability(c); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String())) for the CAP passed via CRI.
We don't have the CAP_ prefix in Kubernetes/CRI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CAP_ prefix.

if err := g.DropProcessCapability(c); err != nil {
return err
for _, c := range capabilities.GetDropCapabilities() {
if err := g.DropProcessCapability(c); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with above.

@Random-Liu
Copy link
Member

Random-Liu commented Jun 7, 2017

@heartlock We need test for privileged mode and device mapping. However, HostDevices and DeviceFromPath all access the host directly, which should not happen in unit test.

We may want to add DeviceFromPath and HostDevices into os interface so that we could unit test this. Let me think about this a little bit more.

Other than this, please see the comments above.

spec.Process.Capabilities.Effective = finalCapList
spec.Process.Capabilities.Inheritable = finalCapList
spec.Process.Capabilities.Permitted = finalCapList
spec.Process.Capabilities.Ambient = finalCapList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return here, so we don't need the else. Reducing indent is always prefered.

// TODO(random-liu): [P1] Apply selinux label
g.AddBindMount(src, dst, options)
}
if privileged {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !privileged{
return
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why !privileged ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean:

if !privileged {
  return
}
// or else
/*
clearReadyOnly...
*/

This reduces indent of the "clear read only code", which is a preferred coding style.

Access: "rwm",
},
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, reduce indent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if privileged {
 /* set privileged */
 return
}
/* other code */

}
if privileged {
spec := g.Spec()
// clear readonly for /sys and cgroup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's at least add unit test for this behavior, and leave out the others. But please add TODO for adding test for device mapping code.

@Random-Liu
Copy link
Member

@heartlock Please address comments and rebase your PR. Thanks.

@heartlock
Copy link
Contributor Author

@Random-Liu will do today.

@heartlock heartlock force-pushed the support-privileged branch 2 times, most recently from 6a35bf5 to 1227911 Compare June 9, 2017 06:48

// Add extra mounts first so that CRI specified mounts can override.
addOCIBindMounts(&g, append(extraMounts, config.GetMounts()...))
addOCIBindMounts(&g, append(extraMounts, config.GetMounts()...), securityContext.GetPrivileged())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add bind mounts twice? Seems to be error caused by rebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault! Forgot to delete previous one.

// TODO(random-liu): [P1] Apply selinux label
g.AddBindMount(src, dst, options)
}
if privileged {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean:

if !privileged {
  return
}
// or else
/*
clearReadyOnly...
*/

This reduces indent of the "clear read only code", which is a preferred coding style.

}
func setOCICapabilities(g *generate.Generator, capabilities *runtime.Capability, privileged bool) error {
if privileged {
// Add all capabilities in privileged mode.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if privileged {
  g.SetupPrivileged(true)
  return
}
/*
Other code
*/

if err := g.AddProcessCapability(c); err != nil {
return err
for _, c := range capabilities.GetAddCapabilities() {
if err := g.AddProcessCapability(c); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CAP_ prefix.

Access: "rwm",
},
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if privileged {
 /* set privileged */
 return
}
/* other code */

heartlock added 2 commits June 9, 2017 15:42
Signed-off-by: heartlock <[email protected]>
Signed-off-by: heartlock <[email protected]>
@heartlock heartlock force-pushed the support-privileged branch from 1227911 to 73fbe90 Compare June 9, 2017 07:55
@Random-Liu
Copy link
Member

LGTM except #51 (comment) and #51 (comment).

Will merge this one first and send another PR to address those 2.

@Random-Liu Random-Liu merged commit e9a930b into containerd:master Jun 11, 2017
lanchongyizu pushed a commit to lanchongyizu/cri-containerd that referenced this pull request Sep 3, 2017
adelina-t pushed a commit to adelina-t/cri that referenced this pull request Nov 1, 2019
add support for container stats on windows
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants