Conversation
eero-t
left a comment
There was a problem hiding this comment.
An omitted major or minor is a wildcard matching all device numbers
May be safer to start by erroring in this case (and relaxing it only if somebody provides strong enough use-case for it, that cannot be handled reasonable in any other way).
Well, I think we at least must allow omitting the minor number, otherwise this can't really be used for what is stated as the primary use case in the description: "The main motivation is hotplug in device management and device monitoring scenarios, where the device numbers that appear on the host after the container was created cannot be known at container creation time." @marquiz But I was also wondering if we really need to allow such wide permissions, or if we could instead get along with only allowing the minor number to be omitted. Do we really have a use case for injecting access permissions to all block or character devices ? |
Yeah, agree. I think allowing "wildcard" on minor only is a sound choice (nobody should have the need to allow everything with one single rule). I'll change the PR |
Add a DeviceCgroupRule type and a DeviceCgroupRules field to ContainerEdits, for granting a container access to a set of devices in the devices cgroup without creating any device node in it. The main motivation is hotplug in device management and device monitoring usage scenarios. Device numbers that appear on the host after the container was created cannot be known at container creation time. An empty (null) Major or Minor is a wildcard matching all device numbers, which makes it possible to grant access to e.g. all DRM devices, present and future. Also, bump the spec version to v1.2.0. Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
3a12805 to
7a9e6f5
Compare
Done. Major is now required (and must be > 0) |
| * `deviceCgroupRules` (array of objects, OPTIONAL) describes rules to be added to the devices cgroup of the container, see [Device cgroup rules](#device-cgroup-rules). Added in v1.2.0. | ||
| * `type` (string, REQUIRED) type of the devices the rule applies to, one of: | ||
| * b - block device. | ||
| * c - character device. | ||
| * `major` (int64, REQUIRED) major number of the devices the rule applies to. Must be greater than 0. | ||
| * `minor` (int64, OPTIONAL) minor number of the devices the rule applies to. If not specified the rule applies to all minor numbers of the given major. | ||
| * `permissions` (string, OPTIONAL) Cgroups permissions to grant, with the same candidates as the `deviceNodes.permissions`. Omitted or empty default to `rwm`. |
There was a problem hiding this comment.
@marquiz @elezar @bart0sh Should we explicitly spell out here, that an actual device injection in the Spec is always an implicit corresponding device cgroup rule injection. IOW, there is absolutely no need to manually specify device cgroup rules for devices you inject by a CDI Spec. You only need to specify device cgroup rules, if you do not inject the actual devices using a CDI Spec. This might not otherwise be fully obvious after this addition to the Spec, especially not for hasty readers.
There was a problem hiding this comment.
Yes, I think making it clear that on systems where cgroups are used, a device node implies a corresponding cgroup rule.
Add support for applying the device cgroup rules to the container spec. Major and minor numbers are pointer fields so that unset values are handled as an allow all wildcard. Omitted permissions default to "rwm". Accept the block and character device types only, Note that the "a" (allow every devices, akin to "privileged mode" is not allowed by this patch. Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
7a9e6f5 to
c30f4af
Compare
|
I still need to do a proper review, but this seems to align with what I proposed in #314. My first question would be whether a separate containerEdits type is preferred over reusing "deviceNodes"? Using a specific type would help for clarity. |
| AdditionalGIDs []uint32 `json:"additionalGids,omitempty" yaml:"additionalGids,omitempty"` // Added in v0.7.0 | ||
| Env []string `json:"env,omitempty" yaml:"env,omitempty"` | ||
| DeviceNodes []*DeviceNode `json:"deviceNodes,omitempty" yaml:"deviceNodes,omitempty"` | ||
| DeviceCgroupRules []*DeviceCgroupRule `json:"deviceCgroupRules,omitempty" yaml:"deviceCgroupRules,omitempty"` // Added in v1.2.0 |
There was a problem hiding this comment.
As far as I know these are Linux only? Should we name them as such? (we do so for the LinuxNetDevices).
There was a problem hiding this comment.
Hmm, good point. "Linux" is probably is justified here. I'll change this
@elezar I think that is the major advantage of this PR's approach. It is rather explicit about what is happening so what users could expect. The wildcard approach is quite a bit more implicit. For instance, without (reading the) documentation some users might not get a clear idea whether any device nodes get injected. To some intuition might give the wrong impression that since its a globbing pattern, matching nodes will be injected. This approach does not suffer from that problem. It would also leave the door open for any future wildcard-based matching device injection if we'd ever to decide to consider adding something like that. |
| "type": "<type>", | ||
| "major": <int64>, | ||
| // An omitted or empty minor is a wildcard matching any minor number. | ||
| "minor": <int64> (optional), |
There was a problem hiding this comment.
This is a bit implicit. Would mandatory minor supporting wildcards be a safer option?
There was a problem hiding this comment.
Dunno 🤷♂️, what others think. The "wildcard" would be -1 then
There was a problem hiding this comment.
In order to collect data, how does Docker or Podman handle this?
There was a problem hiding this comment.
My rationale FWIW: If minor is unintentionally not added, all minors would be implicitly allowed and everything would work with wider permissions, allowing access to all the minors. This could cause security issues and after all this is not what user actually wanted.
There was a problem hiding this comment.
Yes, I understand. I suppose the issue is that communicating what -1 means may not be so straightforward.
Adds a
deviceCgroupRulesfield tocontainerEdits, for granting access to a set of devices in the devices cgroup without creating any device nodes with it. The main motivation is hotplug in device management and device monitoring scenarios, where the device numbers that appear on the host after the container was created cannot be known at container creation time. An omitted minor is a wildcard matching all device numbers. An example:Rules are applied as allow entries in
linux.resources.devicesof the OCI runtime spec.Also bumps the spec version to v1.2.0.