Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
interfaces: fix udev tagging for hooks (2.29) #4146
Conversation
zyga
added some commits
Nov 3, 2017
zyga
added this to the 2.29 milestone
Nov 3, 2017
zyga
added some commits
Nov 8, 2017
mvo5
reviewed
Nov 9, 2017
This looks good and simplifies things which is great. OTOH quite a bit of churn so I have some questions inline.
| @@ -139,8 +139,8 @@ func (s *MirInterfaceSuite) TestSecCompOnClassic(c *C) { | ||
| func (s *MirInterfaceSuite) TestUDevSpec(c *C) { | ||
| udevSpec := &udev.Specification{} | ||
| c.Assert(udevSpec.AddPermanentSlot(s.iface, s.coreSlot), IsNil) | ||
| - c.Assert(udevSpec.Snippets(), HasLen, 1) | ||
| - c.Assert(udevSpec.Snippets()[0], testutil.Contains, `KERNEL=="event[0-9]*", TAG+="snap_mir-server_mir"`) | ||
| + c.Assert(udevSpec.Snippets(), HasLen, 5) |
zyga
Nov 9, 2017
Contributor
Each snippet that tags a device is now a separate entry. Before they were one big blob.
stolowski
Nov 9, 2017
Contributor
The test is a bit relaxed now with checking length only. I think it would be nice to have a 'Contains' check, like we do for others.
| @@ -207,9 +207,9 @@ func (s *ModemManagerInterfaceSuite) TestUsedSecuritySystems(c *C) { | ||
| udevSpec := &udev.Specification{} | ||
| c.Assert(udevSpec.AddPermanentSlot(s.iface, s.slot), IsNil) | ||
| - c.Assert(udevSpec.Snippets(), HasLen, 1) | ||
| + c.Assert(udevSpec.Snippets(), HasLen, 2) |
| @@ -56,6 +70,8 @@ func (spec *Specification) AddConnectedPlug(iface interfaces.Interface, plug *in | ||
| UDevConnectedPlug(spec *Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error | ||
| } | ||
| if iface, ok := iface.(definer); ok { | ||
| + spec.securityTags = plug.SecurityTags() | ||
| + defer func() { spec.securityTags = nil }() |
mvo5
Nov 9, 2017
Collaborator
Why are we doing this? This feels strange (and dangerous), I mean, if its something that should only be valid during the iface.UDevConnectedPlug() call maybe it should be an input parameter there instead? Actually we already pass "plug" in there, so why is UdevConntecedPlug not just using plug.SecurityTags() ?
zyga
Nov 9, 2017
Contributor
We do this in all the other backends. This is just making the API changes smaller and consistent with other backends.
pedronis
Nov 9, 2017
Contributor
I agree, it merits a rethink at some point, but yes, I saw the other backends work like this as well
| + spec.TagDevice(fmt.Sprintf(`SUBSYSTEM=="hidraw", KERNEL=="%s"`, strings.TrimPrefix(path, "/dev/"))) | ||
| + } else { | ||
| + spec.TagDevice(fmt.Sprintf(`IMPORT{builtin}="usb_id" | ||
| +SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", ATTRS{idVendor}=="%04x", ATTRS{idProduct}=="%04x"`, usbVendor, usbProduct)) |
pedronis
Nov 9, 2017
Contributor
is SUBSYSTEMS="usb" correct here? I remember jdstrand changed recently SUBSYSTEMS to SUBSYSTEM in some cases
pedronis
Nov 10, 2017
Contributor
for other reasons I was reading the udev docs, it seems this means the hidraw subsystem under the usb devices, so it seems plausible
| + spec.TagDevice(fmt.Sprintf(`SUBSYSTEM=="tty", KERNEL=="%s"`, strings.TrimPrefix(path, "/dev/"))) | ||
| + } else { | ||
| + spec.TagDevice(fmt.Sprintf(`IMPORT{builtin}="usb_id" | ||
| +SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="%04x", ATTRS{idProduct}=="%04x"`, usbVendor, usbProduct)) |
pedronis
Nov 9, 2017
Contributor
is SUBSYSTEMS="usb" correct here? I remember jdstrand changed recently SUBSYSTEMS to SUBSYSTEM in some cases
| @@ -56,6 +70,8 @@ func (spec *Specification) AddConnectedPlug(iface interfaces.Interface, plug *in | ||
| UDevConnectedPlug(spec *Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error | ||
| } | ||
| if iface, ok := iface.(definer); ok { | ||
| + spec.securityTags = plug.SecurityTags() | ||
| + defer func() { spec.securityTags = nil }() |
mvo5
Nov 9, 2017
Collaborator
Why are we doing this? This feels strange (and dangerous), I mean, if its something that should only be valid during the iface.UDevConnectedPlug() call maybe it should be an input parameter there instead? Actually we already pass "plug" in there, so why is UdevConntecedPlug not just using plug.SecurityTags() ?
zyga
Nov 9, 2017
Contributor
We do this in all the other backends. This is just making the API changes smaller and consistent with other backends.
pedronis
Nov 9, 2017
Contributor
I agree, it merits a rethink at some point, but yes, I saw the other backends work like this as well
| - spec.AddSnippet(fmt.Sprintf("SUBSYSTEM==\"hidraw\", KERNEL==\"%s\", TAG+=\"%s\"", strings.TrimPrefix(path, "/dev/"), tag)) | ||
| - | ||
| - } else { | ||
| - spec.AddSnippet(udevUsbDeviceSnippet("hidraw", usbVendor, usbProduct, "TAG", tag)) |
stolowski
Nov 9, 2017
Contributor
Why keeping udevUsbDeviceSnippet in utils, can we remove it as in #4144? Did you forget about cherry-picking something from the other branch?
zyga
Nov 9, 2017
Contributor
I wanted to stay minimal in this approach. I can pull more from 4144 if necessary.
| @@ -139,8 +139,8 @@ func (s *MirInterfaceSuite) TestSecCompOnClassic(c *C) { | ||
| func (s *MirInterfaceSuite) TestUDevSpec(c *C) { | ||
| udevSpec := &udev.Specification{} | ||
| c.Assert(udevSpec.AddPermanentSlot(s.iface, s.coreSlot), IsNil) | ||
| - c.Assert(udevSpec.Snippets(), HasLen, 1) | ||
| - c.Assert(udevSpec.Snippets()[0], testutil.Contains, `KERNEL=="event[0-9]*", TAG+="snap_mir-server_mir"`) | ||
| + c.Assert(udevSpec.Snippets(), HasLen, 5) |
zyga
Nov 9, 2017
Contributor
Each snippet that tags a device is now a separate entry. Before they were one big blob.
stolowski
Nov 9, 2017
Contributor
The test is a bit relaxed now with checking length only. I think it would be nice to have a 'Contains' check, like we do for others.
codecov-io
commented
Nov 9, 2017
•
Codecov Report
@@ Coverage Diff @@
## release/2.29 #4146 +/- ##
================================================
- Coverage 75.6% 75.58% -0.03%
================================================
Files 433 433
Lines 37277 37253 -24
================================================
- Hits 28182 28156 -26
- Misses 7124 7126 +2
Partials 1971 1971
Continue to review full report at Codecov.
|
zyga commentedNov 3, 2017
This is a backport of #4144 for 2.29; Original description follows.
This branch aims to fix udev tagging to support hooks in addition to apps that were added earlier.
There are three main patches here:
The only remaining uses of spec.AddSnippet are special-cases that add large chunk of arbitrary
udev code that is not specifically aiming to tag a device.
This passes local unit testing, no testing was done on any hardware.
Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com