Request for classic confinement: Tegh


#1

I’m trying to publish Tegh Beta. Tegh is a new 3D printer networking software for USB Serial 3D Printers which we aim to launch with the Snap Store.

A design goal of Tegh is ease of setup for the user and so a straightforward installation is integral to that vision.

Tegh needs classic confinement so that the user can list and choose the serial device of their 3D printer from a drop down list in the web UI. To do that we need access to a list of all USB serial devices.

The relevant source for listing USB serial ports and watching for changes to that list can be found here:

Tegh also requires classic confinement to enable control of the Raspberry Pi GPIOs. Raspberry Pi GPIOs allows users to configure and control non-realtime 3D printer accessories such as lights, fans or motors without having to modify their 3D printer firmware.

The relevant source for configuring and controlling the Raspberry Pi GPIO can be found here:


#2

@jdstrand re: your review feedback I’ve outlined why I’ve requested classic confinement here.


#3

Have you tried the hardware-observe, gpio, and gpio-memory-control interfaces?


#4

@d1plo1d - I’d like to hear the answer to this to better understand why classic is required.


#5

@d1plo1d - your response is required to proceed with this request. Thanks


#6

Thanks @jdstrand and @daniel. I’ve had to prioritise other work on Tegh for the moment but if we can leave this open I will get back to you as soon as I have a chance to look into @daniel’s suggestions.


#7

I’ve added hardware-observe , gpio , and gpio-memory-control but there appears to be a problem opening the serial port:

= AppArmor =
Time: Apr 04 08:11:29
Log: apparmor="DENIED" operation="open" profile="snap.tegh.tegh" name="/dev/ttyUSB0" pid=390 comm="tegh" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
File: /dev/ttyUSB0 (write)
Suggestions:
* add 'raw-usb' to 'plugs'
* add 'serial-port (with gadget or core support)' to 'plugs'

The serial port Tegh uses is chosen by the user in Tegh’s web UI so as I understand it Tegh does not fit a serialport gadget snap since serialport gadget snaps require the serial port to be specified ahead of time in the snap’s configuration.

If you want to take a look my snapfile is here: https://github.com/tegh/tegh/blob/7f488b18b7ffb8047d7e65803b7e4b0ec49ca28d/snap/snapcraft.yaml

I’m not sure what else to try. Any advice is very much appreciated. Thanks!


#8

There is a serial-port interface but it is currently not connectable on classic distributions. Once the serial-port interface is updated for dynamic hotplugging, you will be able to use the serial-port interface in your snap.

In the meantime, you can also plug raw-usb. Please try that and respond back with your findings (once that is done, the requirements should be understood and we can proceed with the request or consider auto-connections for your snap.


#9

raw-usb is already in my snapcraft.yml. I’m not sure why the error suggests to add raw-usb given that I already have it. Here’s my list of plugs for Tegh:

apps:
  tegh:
    plugs:
      - network
      - network-bind
      - process-control
      - hardware-observe
      - raw-usb
      - gpio
      - gpio-memory-control

That sounds ideal. +1 to that.

Since raw-usb did not appear to resolve the issue is there anything else we can try or should we move forward with classic confinement?


#10

is your user in the dialout group ? (despite interfaces, normal linux filesystem permissions still apply (i’m not sure if the review tools make a difference between simple file access denials or interface induced access restrictions))


#11

Possibly not. How do I configure the user/groups that the snap’d daemon gets run with?


#12

you dont …

if your snap runs as a daemon it is run as root inside strict confinement …

if your snap is a user-executable app it runs under the credentials of the user who started it (with all filesystem permissions/denials such a user has).

if your snap falls into the latter category, you can check with the groups command if you are in the dialout group … if you are, my comment is moot since your user should have access to the device …

some other side-thought here:

did you consider that people will probably want to run your software inside a headless/user-less Ubuntu Core appliance ? for my 3D printer i run an Ubuntu Core image with octoprint on a Pi to control the printer and i think this is a very typical use-case for software like tegh (your description sounds actually pretty similar to octoprint)… classic confined snaps are not installable on Ubuntu Core for obvious security reasons, so going for classic means you are killing this opportunity for your software.


#13

That’s a great point. I have not tried Ubuntu Core yet myself but I would love for Tegh to be able to run on Ubuntu Core.

The only reason I would want classic confinement would be if all other options were exhausted.

Regarding Octoprint: that’s it exactly. Octoprint has been a major inspiration for Tegh.

But getting back to snapcraft:

if your snap runs as a daemon it is run as root inside strict confinement

Tegh is run as a daemon so it would be the root user inside confinement. So I’m guessing I could do that with something like:

usermod -a -G dialout root

in a install hook but that does not appear to be adding the user to the group for some reason. Any idea why it wouldn’t work?


#14

I imagine this failed because snap confinement doesn’t allow snaps to modify or create users. You could try looking in the logs with journalctl -ef and see if there’s anything in there about your snap being denied permission to edit /etc/group or /etc/passwd.

In general, if your snap needs to modify users and groups you may need to wait for the implementation discussed at Multiple users and groups in snaps


#15

I am not seeing any issues with assigning the group. But this is weird: after I install my snap locally my root user (outside confinement) is in the dialout group and my confinement root still does not have the dialout group. So it’s being added to the wrong user.


#16

Wait, I was installing the snap with --devmode. Removing devmode is giving me different results.


#17

Now I’m getting:

- Run install hook of "tegh" snap if present (run hook "install": /snap/tegh/x1/meta/hooks/install: line 13: /usr/sbin/usermod: Permission denied)

and:

Log: apparmor="DENIED" operation="exec" profile="snap.tegh.hook.install" name="/usr/sbin/usermod" pid=24096 comm="install" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
Log: apparmor="DENIED" operation="open" profile="snap.tegh.hook.install" name="/usr/sbin/usermod" pid=24096 comm="install" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

It would work if I could run it as sudo but trying to use sudo gets me:

Log: apparmor="DENIED" operation="exec" profile="snap.tegh.hook.install" name="/usr/bin/sudo" pid=21996 comm="install" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
Log: apparmor="DENIED" operation="open" profile="snap.tegh.hook.install" name="/usr/bin/sudo" pid=21996 comm="install" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

@ogra how does the octoprint snap solve this? Wouldn’t they also need to add the confinement root user to dialout?


#18

Unfortunately sudo will not help you there. The snap is confined using AppArmor, as you can see in the log messages you pasted, and the AppArmor policy doesn’t allow adding or modifying users from inside a snap.


#19

First off, root does not need to be in the dialout group since traditional permissions allow root access to the device. Non-root users need to be in this group (or ACLs used) to access to the device. The snap is not in a position to grant this access either, except with the account-control interface and then only on Ubuntu Core. Also, strict mode snaps intentionally do not have the access for using sudo.

Today, the only way is for an admin user to grant the access manually, eg: sudo adduser <user> dialout, but again, the snap cannot do this. It is technically possible for snapd to provide a mechanism for snaps to request permission changes on specific files, but that needs design and isn’t currently on the roadmap.

There is a specification that deals with some of this here: use case 2. When that is implemented, it won’t give your snap the ability to add users or modify groups, but does allow for later work to build upon it, perhaps something that would allow a gadget to assign users to groups.

As for octoprint, I reviewed its snap.yaml and see nothing in its security policy that would allow the snap to change group memberships. Perhaps it detects the error and gives the user helpful feedback on the command to run to allow access for non-root users (this is what I suggest to you as well).


#20

In terms of this request, when you plugs raw-usb, connect it and add your user to the dialout group, does your snap work? If not, are there security denials in the logs? If so, what are they?