Serial port access for private repository

Hello, We have private repository (internethandel-electron-cme) and We need serial port access to support various devices.

I am not even sure why private repositories doesn’t have more relaxed rules.

If it is not possible, We would need to move from snapcraft.io or from snap package format altogether.

Hi, whilst your snap is marked as private it is uploaded to the global snap store and so needs to be treated as a publicly accessible snap (since you could easily mark it as public in the future).

So then looking at your snap - I notice your snap declares a large number of serial-port slots - however application snaps are not allowed to declare this since they don’t actually provide the serial-port at all - instead only gadget snaps can declare a slot of this type.

Instead I suspect you want your snap to be able to interact with whatever serial-ports are connected - in that case you likely want to use serial-port via hotplug - please see Hotplug support in that case.

Otherwise, please provide more details on what your snap is trying to accomplish by slotting serial-port currently and we can try to help you achieve this in a more correct manner.

@radomirpolach ping, were you able to look into using hotplug with serial-port as suggested above?

I will be looking into this during the week. I will inform you as soon as I am done testing it.

@alexmurray I am looking at that, but I am not really sure what I need to do for devices to appear within the snap.

I enabled hotplug support and connected serial device.

There is a lot of implementation details here: Developing hotplug interfaces

But I don’t rally see any guiding how to configure my snap to allow for serial devices.

I basically need for specific device (either defined by PID/VID or name to appear within my snap).

$ sudo snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - internethandel-electron-cme

So, I have nice plug in my snap.

$ lsusb
...
Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics CH340 serial converter
...

I have a device connected to my system, but no connections:

$ snap connections system | grep serial

did you enable hotplug support on the machine ?

If you mean this:

sudo snap set system experimental.hotplug=true

Then yes. I also restart snapd (and rebooted as well).

@alexmurray Any ideas what I have to do?

@radomirpolach what device does this USB-Serial converter show up as on your host system? Also can you confirm that sudo snap get system experimental.hotplug outputs true? When testing this locally with a different USB-Serial converter:

$ lsusb | grep Keyspan
Bus 005 Device 009: ID 06cd:0121 Keyspan USA-19hs serial adapter

It works for me:

$ sudo snap get system experimental.hotplug
true
$ sudo dmesg | grep ttyUSB
[43658.826363] usb 5-2.2: Keyspan 1 port adapter converter now attached to ttyUSB0
$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
slots:
  - snapd:keyspanusa-19h (allows accessing a specific serial port)
          -                                                              :keyspanusa-19h            -

what do you see in dmesg when plugging in the USB/serial adapter … it should look similar to the stuff below:

$ sudo dmesg -w
[...]
[268760.901758] audit: type=1420 audit(1654174808.483:1290): subj_apparmor=unconfined
[268868.859996] usb 1-1: new full-speed USB device number 4 using xhci_hcd
[268869.013021] usb 1-1: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
[268869.013028] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[268869.013030] usb 1-1: Product: USB-Serial Controller
[268869.013033] usb 1-1: Manufacturer: Prolific Technology Inc.
[268869.126420] usbcore: registered new interface driver usbserial_generic
[268869.126461] usbserial: USB Serial support registered for generic
[268869.128788] usbcore: registered new interface driver pl2303
[268869.128827] usbserial: USB Serial support registered for pl2303
[268869.128866] pl2303 1-1:1.0: pl2303 converter detected
[268869.129541] usb 1-1: pl2303 converter now attached to ttyUSB0
[...]

you should then see a slot:

$ snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - arduino
  - esptool
  - pcsc-daemon
slots:
  - snapd:pl2303serialportmobi (allows accessing a specific serial port)

does the kernel actually detect the device and assign a ttyUSB* port for it in the first step above ?

$  sudo snap get system experimental.hotplug
true
$  sudo dmesg | grep ttyUSB
[  425.300597] usb 1-4: ch341-uart converter now attached to ttyUSB0
[  426.010761] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
$  snap interface serial-port
name:    serial-port
summary: allows accessing a specific serial port
plugs:
  - internethandel-electron-cme
$  snap connections system | grep serial

Complete dmesg from connecting the device:

[  581.148236] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[  581.301054] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice= 2.54
[  581.301059] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[  581.301060] usb 1-1: Product: USB2.0-Serial
[  581.302426] ch341 1-1:1.0: ch341-uart converter detected
[  581.302772] usb 1-1: ch341-uart converter now attached to ttyUSB0
[  581.843558] audit: type=1400 audit(1654176321.477:217): apparmor="DENIED" operation="open" profile="snap.keepassxc.keepassxc" name="/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/busnum" pid=5556 comm="keepassxc" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[  581.881687] audit: type=1400 audit(1654176321.517:218): apparmor="DENIED" operation="open" profile="snap.keepassxc.keepassxc" name="/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/busnum" pid=5556 comm="keepassxc" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[  582.415955] input: BRLTTY 6.4 Linux Screen Driver Keyboard as /devices/virtual/input/input30
[  582.541536] usb 1-1: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
[  582.542318] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
[  582.542380] ch341 1-1:1.0: device disconnected

that looks like:

(not actually snap related at all)

Ah good find @ogra - so it looks like you may be able to resolve this @radomirpolach by removing the brltty package.

@radomirpolach ping can you confirm if removing the brltty package is sufficient to get serial-port with hotplug working? If so, we can then look at granting the required snap declaration to allow this to occur automatically when your snap is installed. Thanks.

@radomirpolach - ping, have you had a chance to test removing the brltty package to get this working?

Sorry for late response, removing brltty package solved the connection of snap issues, but my application stil don’t see serial port:

Interface                 Plug                                         Slot                             Notes
browser-support           internethandel-electron-cme:browser-support  :browser-support                 -
content[gnome-3-28-1804]  internethandel-electron-cme:gnome-3-28-1804  gnome-3-28-1804:gnome-3-28-1804  -
content[gtk-3-themes]     internethandel-electron-cme:gtk-3-themes     gtk-common-themes:gtk-3-themes   -
content[icon-themes]      internethandel-electron-cme:icon-themes      gtk-common-themes:icon-themes    -
content[sound-themes]     internethandel-electron-cme:sound-themes     gtk-common-themes:sound-themes   -
cups-control              internethandel-electron-cme:cups-control     :cups-control                    manual
desktop                   internethandel-electron-cme:desktop          :desktop                         -
desktop-legacy            internethandel-electron-cme:desktop-legacy   :desktop-legacy                  -
gsettings                 internethandel-electron-cme:gsettings        :gsettings                       -
home                      internethandel-electron-cme:home             :home                            -
network                   internethandel-electron-cme:network          :network                         -
opengl                    internethandel-electron-cme:opengl           :opengl                          -
pulseaudio                internethandel-electron-cme:pulseaudio       -                                -
serial-port               internethandel-electron-cme:serial-port      :usb20-serial                    manual
unity7                    internethandel-electron-cme:unity7           :unity7                          -
x11                       internethandel-electron-cme:x11              :x11                             -

Plug is connected to snap.

When I run the application outside snap, it sees the serial device. When I run it inside snap with the device connected, it doesn’t.

I am looking into snap directory and I don’t see any dev directory. How exactly is the device connected to snap?

ls -la /snap/internethandel-electron-cme/62
total 179865
drwxrwxrwx 11 root root       623 čec  7 02:33 .
drwxr-xr-x  4 root root      4096 čec  7 02:35 ..
-rw-r--r--  1 root root    142605 čec  7 02:33 chrome_100_percent.pak
-rw-r--r--  1 root root    209194 čec  7 02:33 chrome_200_percent.pak
-rwxr-xr-x  1 root root   1100720 čec  7 02:33 chrome_crashpad_handler
-rwxr-xr-x  1 root root       157 čec  7 02:33 command.sh
drwxr-xr-x  5 root root        56 čec 10  2019 data-dir
-rwxr-xr-x  1 root root     16513 čec 10  2019 desktop-common.sh
-rwxr-xr-x  1 root root      1401 čec 10  2019 desktop-gnome-specific.sh
-rwxr-xr-x  1 root root      1530 čec 10  2019 desktop-init.sh
drwxr-xr-x  2 root root         3 čec 10  2019 gnome-platform
-rw-r--r--  1 root root  10217376 čec  7 02:33 icudtl.dat
-rwxr-xr-x  1 root root 148213568 čec  7 02:33 internethandel-electron-cme
drwxr-xr-x  3 root root        39 dub 18  2018 lib
-rwxr-xr-x  1 root root    236376 čec  7 02:33 libEGL.so
-rwxr-xr-x  1 root root   2890552 čec  7 02:33 libffmpeg.so
-rwxr-xr-x  1 root root   6985384 čec  7 02:33 libGLESv2.so
-rwxr-xr-x  1 root root   4034648 čec  7 02:33 libvk_swiftshader.so
-rwxr-xr-x  1 root root   4784456 čec  7 02:33 libvulkan.so.1
drwxrwxr-x  2 root root       792 čec  7 02:33 locales
drwxrwxr-x  3 root root        43 čec  7 02:33 meta
drwxrwxr-x  2 root root        31 čec  7 02:33 resources
-rw-r--r--  1 root root   5124401 čec  7 02:33 resources.pak
drwxrwxr-x  2 root root         3 čec  7 02:33 scripts
-rw-r--r--  1 root root     49495 čec  7 02:33 snapshot_blob.bin
drwxrwxr-x  2 root root        52 čec  7 02:33 swiftshader
drwxr-xr-x  3 root root        26 čec 10  2019 usr
-rw-r--r--  1 root root    164753 čec  7 02:33 v8_context_snapshot.bin
-rw-r--r--  1 root root       107 čec  7 02:33 vk_swiftshader_icd.json

Device doesn’t have SN, but otherwise seems pretty normal:

{
  manufacturer: '1a86',
  serialNumber: undefined,
  pnpId: 'usb-1a86_USB2.0-Serial-if00-port0',
  locationId: undefined,
  vendorId: '1a86',
  productId: '7523',
  path: '/dev/ttyUSB0'
}

Along with only supporting USB serial port adapters, hotplug is restricted to devices that provide a specific set of udev attributes; name, vendor identifier and/or serial number.

So this is within limitation?