I have the following setup:
- network-manager snap from the store
- my snap which needs to create a WiFi connection through nmcli
- Ubuntu Core system
As discussed in this thread, nmcli
is bundled in my snap. Since The network-manager interface is not auto-connected, I’m running snap connect my-snap:network-manager network-manager:service
first, and if I then run my-snap.setup (which calls a nmcli command to create the connection), everything works as expected.
I would like to shave off the manual my-snap.setup call though, and found out about interface hooks. To me it sounds like connect-plug<interface name>
would allow me to run the nmcli command after the interface has been connected and all permissions granted. My code:
# snap/hooks/connect-plug-network-manager
#!/bin/sh
# set -e
$SNAP/usr/bin/nmcli c add ... # connection setup command, I also tried with just nmcli
However, running snap connect my-snap:network-manager network-manager:service
results in this AppArmor error:
error: cannot perform the following tasks:
- Run hook connect-plug-network-manager of snap "my-snap" (run hook "connect-plug-network-manager": (process:2394): nmcli-CRITICAL **: Error: Could not create NMClient object: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.1630" (uid=0 pid=2394 comm="nmcli c add type wifi ifname * con-name glancrsetu") interface="org.freedesktop.DBus.Properties" member="GetAll" error name="(unset)" requested_reply="0" destination=":1.3" (uid=0 pid=1306 comm="/snap/network-manager/379/usr/sbin/NetworkManager ").)
I tried adding the network-manager
interface to the hooks interfaces – though it should be granted by the time the hook is running:
# snapcraft.yaml
hooks:
install:
plugs: [network]
connect-plug-network-manager:
plugs: [network-manager]
I checked the AppArmor rules in like @jdstrand suggested in Access nmcli command from network-manager via interface, and while my-snap.setup shows up as a peer, the hook does not.
Questions
- Can I run commands which depend on a manually-connected interface in the
connect-plug-
interface hook for this very connection? - Do I need to specify the required interfaces for interface hooks in snapcraft.yaml?