-
Notifications
You must be signed in to change notification settings - Fork 85
Include linux device cgroups in adjustment logic #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…on logic Signed-off-by: Karl Baumgartner <[email protected]>
For some context/background... Those device permission rules in That's why we don't have any corresponding Set/Add/Remove functions defined for manipulating them in
Yes, in current HEAD the claims are only used for conflict detection. That is however changing with the pending introduction of pluggable validation (#163) , where the claims, which are also used to record which plugins made what changes, are passed on to any registered validating plugins, which then decide whether such changes are accepted or rejected and this decision can be based on which plugins made the changes.
Can you tell a bit more about what you are trying to do (basically your 'use case') ? Things like
If we extend NRI to allow direct manipulation of cgroup device access rules, keeping the general patterns of NRI and #163 in mind, I think we'd need at least
|
Sure. I'm running a program that creates new devices when it starts whose minor can't be known beforehand, hence we pass in
Using ioctl on binderfs. |
|
Hey @klihub ! Is there a chance this will be merged? We've been using it via our fork in production and it's been working OK. |
Sure, let's review it properly first, to see if there is anything to improve. I'll tag a few others to help in that. |
|
Code generally LGTM. I agree that plugins should have claims, but how we would define it is unclear to me. Are we claiming ownership of the rule, or of the device inside the rule? For example, if we were saying claims were tied to the devices inside the rules, I think it would be unreasonable for a plugin to claim a rule with "wildcard" devices (e.g. no other plugins can then add or remove rules for any devices). |
mikebrow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thank you all! |
|
@karlbaumg I'm now a bit late with this comment/question (which is related to something I notice I had already commented earlier, about ). So in your above mentioned NRI plugin, do you do something like func (p *plugin) CreateContainer(ctx context.Context, pod *api.PodSandbox, ctr *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error) {
...
a := &api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Resources: &api.LinuxResources{
Devices: []*api.LinuxDeviceCgroup{
{
Allow: true,
Type: "c",
Major: api.OptionalInt64(238),
Access: "rwm",
},
},
},
},
}
....
return a, nil, nil
}IOW, you add a new cgroup device rule like this (directly as data, without using a function for it) aand then return that among the adjustments for the container ? If you do (I apologize for me being hasty with my approval in the review and) I think we should add a function for doing this, mostly for attempted consistency with the rest of the code. Also I think it probably would make sense to hook this in for conflict detection via the existing Claim/Clear* mechanism, probably using the type+major+minor as the key for the claim. So then in the above example, that would amount to claiming the "c-238-*" "DeviceCgroupRule". I can roll an implementation for this to better illustrate what I mean... |
|
Yes, here is exactly what I'm returning as a single element in the array: {
Allow: true,
Access: "rwm",
Major: api.Int64(-1),
Minor: api.Int64(-1),
Type: "c",
}Which was already available on the response object btw, it was just not processed at all. I'm not really up to speed with claim/clear mechanism but from the sound of it, generic entries like this one, may not fit perfectly well but I agree it'd be consistent with the rest. |
@karlbaumg I can take a look at adding the missing claim bits and then tag you for review, if that helps... |
|
@klihub Sounds good, thanks! |
This is a very useful feature for cases where we'd like to give wildcard device permissions to the cgroup, e.g.
--device-cgroup-rule 'c *:* rwm'which is possible in both Podman and Docker.Found out the hard way that
Linux.Resources.Devicesare not processed at all.If I understood the claim logic correctly, it is to prevent multiple plugins from overriding each other. But the cgroup rules array is a layered permission list, e.g. it starts with a deny all rule and allow rules are appended so different plugins may append different rules. That's why I didn't add a
claimDeviceCgroupbut happy to change.I've validated this change with containerd
1.7.27that has this patch on top of NRI0.8.0.