From the command line I have experimented with the use of nmcli .
Now I want to my java application (running as a .snap) to be able to use the nmcli commands too.
However it seems that nmcli is not visible within my .snap.
I see there was a similar question about this before. How do I actually include the nmcli in my .snap ?
If I include the full path e.g. /snap/bin/nmcli would that work.
Basically you can’t access any binary in /snap/bin from within your snap. If you want to call the nmcli binary you have to ship it within your own snap and use the network-manager interface to allow access to NetworkManager over DBus.
If you don’t want to call any of these dbus API endpoints directly, you still can go and take the nmcli binary from the Ubuntu Archive or build one with your snap and use it. We do something similar for the wifi-ap snap. See snapcraft.yaml - ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap - [no description] for details on this.
Thanks for the reply. I think it is becoming clearer now.
Where exactly can I find the latest nmcli binary to download and include in my snap?
As far as I understand in the example from the wifi-ap snap you are also not building it but using the binary.
If I do the same then I could invoke it using my-snap-name.nmcli ?
I am not sure if I understand what you want to ask. But let me try to answer what I understand. You can’t call /snap/bin/network-manager.nmcli as this is owned by the network-manager snap. No interface will allow you to use something out of /snap/bin. The a plug of the network-manager interface will only allow you to talk to the NetworkManager service coming from the network-manager snap over dbus, nothing else.
Normally we don’t want to use explicit deny rules because deny rules are always evaluated after allow rules (ie, another allow rule can’t undo it), but in this case the rule is very specific-- the network-manager slot is not allowed to ptrace trace connected plugs.
apparmor=ALLOWED indicates that your devmode snap is doing something that is a violation of sandbox policy, but because you are in devmode it is only logged, not DENIED. Most of the time this will indicate a problem when you put your snap in strict mode (I say most of the time because software may exercise different code paths when under confinement depending on how it handles denials, etc).
This indicates you are calling systemctl and this is not supported by any interface (because of systemd’s current design it is unconfineable. Ie, the policy quickly spins out to you can interfere with the system or other snaps). Why are you using systemctl? Perhaps there is another way to achive your goal.