Snap not seeing serial port passthrough in LXD container

Hi there,

I have a problem with a snap running within an LXD container, the home-assistant-snap to be precise. The host system is Ubuntu 20.04, as is the container (`lxc launch ubuntu:20.04).

I am trying to pass through a SkyConnect USB dongle to the container. The dongle is actually a USB-UART device, and on the host machine appears as /dev/ttyUSB0. Accordingly, I pass through the device using

$ lxc config device add homeassistant ttyUSB0 unix-char source=/dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_9ccaf1470741ed11acce7ea7ccf2b06c-if00-port0 path=/dev/ttyUSB0 mode=666 gid=20

On the host machine, if I install the home-assistant-snap and follow the instructions to enable hotplug, I can see the serial device pop up as a slot

$ snap interface serial-port 
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - home-assistant-snap
slots:
  - snapd:skyconnectv10 (allows accessing a specific serial port)

However, within the LXD container although the /dev/ttyUSB0 device is present, there are no slots shown

# snap interface serial-port 
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - home-assistant-snap

thus any attempt to connect the Home Assistant to a serial-port slot fails. The result is that I cannot get Home Assistant to talk to the SkyConnect dongle.

Is this is restriction of the LXD container, or might I be missing a permissions thing?

Many thanks!

Most likely snapd relies on udevd to list the devices and udevd doesn’t know how to find those devices passed to containers.

There’s a good chance that using unix-hotplug would work as that will cause udev to be notified, but the annoying part is that for it to work, a hotplug event must be triggered, which means that you need to unplug and replug your USB device after starting the container.

Thanks Stéphane, your comments jogged my mind. It turns out that connecting the home-assistant-snap to raw-usb and hardware-observe does the trick – presumably as you say because of the udevd thing.

For others with the same issue, I found this very helpful post by the maintainer of the home-assistant-snap about a similar (though not identical!) problem.

Thanks again, Stéphane for the wonderful work on LXD!

Glad that did the trick!