Setcap for SNAP executable

Good-Day everyone,

i have an application executable which needs special cabs

setcap cap_net_bind_service,CAP_SYS_NICE,cap_ipc_lock,cap_net_raw+ep $SNAP/MyApp

to run on the snap…

when i pack myapp with snap is build with the plugin dump… an run i , get the following errors:

2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:47.013103 +0000 UTC AVC apparmor="DENIED" operation="mknod" profile="snap.appengine-snap.app-engine" name="/dev/shm/zKXWCM" pid=686879 comm="AppEngine" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:47.013534 +0000 UTC AVC apparmor="DENIED" operation="mknod" profile="snap.appengine-snap.app-engine" name="/dev/shm/T3ZhRL" pid=686879 comm="AppEngine" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:47.013753 +0000 UTC AVC apparmor="DENIED" operation="mknod" profile="snap.appengine-snap.app-engine" name="/dev/shm/yHc9vM" pid=686879 comm="AppEngine" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:47.013992 +0000 UTC AVC apparmor="DENIED" operation="mknod" profile="snap.appengine-snap.app-engine" name="/dev/shm/zAo0zN" pid=686879 comm="AppEngine" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:47.014204 +0000 UTC AVC apparmor="DENIED" operation="mknod" profile="snap.appengine-snap.app-engine" name="/dev/shm/hr9TIK" pid=686879 comm="AppEngine" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:47.014415 +0000 UTC AVC apparmor="DENIED" operation="mknod" profile="snap.appengine-snap.app-engine" name="/dev/shm/60zBQM" pid=686879 comm="AppEngine" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

...

what are the proper way to set caps for exeutable inside a snap (without root rights)

the denial is not related to caps but trying to create a file under /dev/shm … when running snappy-debug on the system alongside the snap it should have told you about this …

there is a new shared-memory interface in snapd 2.55.x (currently in the candidate channel) that is able to give you a private and fully writable /dev/shm for the snap and should solve your problem …

Thank you very much for your time and response,

but i have a furhter question to understand the “setcap” mechanims on a forigen SNAP system without root rights:

When i run the App inside my linux VM there i have root rights to execute “setcab”. and can something like this bevor i execute the app

setcap cap_net_bind_service,CAP_SYS_NICE,cap_ipc_lock,cap_net_raw+ep MyApp

inside the foreigen-hardware where i want to run my snap to i have a run.sh as command in the snap:

run.sh content:

#!/bin/sh
echo We are here: $SNAP/
echo "Set capabilities for SICK AppEngine binary and make it executable"
setcap cap_net_bind_service,CAP_SYS_NICE,cap_ipc_lock,cap_net_raw+ep $SNAP/AppEngine
chmod +x $SNAP/AppEngine
echo "Run AppEngine"
$SNAP/AppEngine -config $SNAP/userconfig.yml

an the output i get:

2022-04-13T08:28:46Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.86705 +0000 UTC We are here: /snap/appengine-snap/x1/ 2022-04-13T08:28:46Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.86705 +0000 UTC Set capabilities for SICK AppEngine binary and make it executable 2022-04-13T08:28:46Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.871206 +0000 UTC AVC apparmor=“DENIED” operation=“exec” profile=“snap.appengine-snap.app-engine” name="/usr/sbin/setcap" pid=686877 comm=“run.sh” requested_mask=“x” denied_mask=“x” fsuid=0 ouid=0 2022-04-13T08:28:46Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.872251 +0000 UTC AVC apparmor=“DENIED” operation=“exec” profile=“snap.appengine-snap.app-engine” name="/usr/sbin/setcap" pid=686877 comm=“run.sh” requested_mask=“x” denied_mask=“x” fsuid=0 ouid=0 2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.873628 +0000 UTC /snap/appengine-snap/x1/run.sh: 5: setcap: Permission denied 2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.879704 +0000 UTC chmod: changing permissions of ‘/snap/appengine-snap/x1/AppEngine’: Read-only file system 2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.880742 +0000 UTC Run AppEngine 2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.88111 +0000 UTC audit: type=1400 audit(1649838526.860:286268): apparmor=“DENIED” operation=“exec” profile=“snap.appengine-snap.app-engine” name="/usr/sbin/setcap" pid=686877 comm=“run.sh” requested_mask=“x” denied_mask=“x” fsuid=0 ouid=0 2022-04-13T08:28:47Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-13 08:28:46.881247 +0000 UTC audit: type=1400 audit(1649838526.870:286269): apparmor=“DENIED” operation=“exec” profile=“snap.appengine-snap.app-engine” name="/usr/sbin/setcap" pid=686877 comm=“run.sh” requested_mask=“x” denied_mask=“x” fsuid=0 ouid=0

unrelated to have the permission to write files, what about this, i need to set teh caps inside the foreigen hardware

you don’t even get to execute setcap here (which is probably why you don’t have any CAP related denials yet), your snap should ship the setcap command instead of trying to call it from the host …

Good Morning orga ,

Allreight, but what you mean with “your snap should ship the setcap” ? Iam completely new in SNAP and noob linux user. Can give an example, or explaniation!?:wink:

Thank you very much

add libcap2-bin to your stage-packages, it will end up in $SNAP/usr/sbin/.

God day, thank you ogra,

but after i added libcap to the stage-packaged i get the error

2022-04-19T10:55:48Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-19 10:55:48.131218 +0000 UTC unable to set CAP_SETFCAP effective capability: Operation not permitted

so is there no other option got get an workaorund?

well, now you can exec setcap at least …

i guess to gain the CAP_SETFCAP capability we’d need to extend some (or add a new) interface, perhaps @alexmurray or @emitorino have an idea or hint here how risky that is …

thats fine :slight_smile: but what the reason for?

unable to set CAP_SETFCAP effective capability: Operation not permitted

thank you for helping again

there is no interface providing you permission to set that capability … do you see more denials in your journal when setcap runs ? also, did you run snappy-debug alongside your app to see if it has any suggestions ?

i figured out, that the my app need to change the “nice level” of the own process… is a interface vor this avaiable!?

snappy-debugshould tell you which interface is suitable for that … (i’d assume it is process-control but that is just a guess, snappy-debug will know for sure)

Good moring ogra , so i could install snappy-debug. An now, how can i see the debug infos for my app!?

And, “process-control” did the job… thank you…

Slowly but surly :slight_smile:

i have 2 further question.

i get this errors: (regarding system file access)

2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.938322 +0000 UTC AVC apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/sys/devices/platform/amba/ff0d0000.ethernet/net/eth0/type" pid=3614884 comm="AppEngine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.939029 +0000 UTC AVC apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/sys/devices/platform/amba_pl@0/80040000.tsn_endpoint_ip_0/80040000.tsn_emac_0/net/eth1/type" pid=3614884 comm="AppEngine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.939372 +0000 UTC AVC apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/sys/devices/virtual/net/lo/type" pid=3614884 comm="AppEngine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.94056 +0000 UTC kauditd_printk_skb: 26 callbacks suppressed
2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.940706 +0000 UTC audit: type=1400 audit(1650426801.930:2053551): apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/sys/devices/platform/amba/ff0d0000.ethernet/net/eth0/type" pid=3614884 comm="AppEngine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.940807 +0000 UTC audit: type=1400 audit(1650426801.930:2053552): apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/sys/devices/platform/amba_pl@0/80040000.tsn_endpoint_ip_0/80040000.tsn_emac_0/net/eth1/type" pid=3614884 comm="AppEngine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
2022-04-20T03:53:22Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:21.940901 +0000 UTC audit: type=1400 audit(1650426801.930:2053553): apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/sys/devices/virtual/net/lo/type" pid=3614884 comm="AppEngine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.831714 +0000 UTC AVC apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_supplicant" pid=3614959 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.832522 +0000 UTC AVC apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_supplicant" pid=3614959 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.835616 +0000 UTC AVC apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_cli" pid=3614961 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.836238 +0000 UTC AVC apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_cli" pid=3614961 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.837912 +0000 UTC audit: type=1400 audit(1650426803.830:2053554): apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_supplicant" pid=3614959 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.838063 +0000 UTC audit: type=1400 audit(1650426803.830:2053555): apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_supplicant" pid=3614959 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.838189 +0000 UTC audit: type=1400 audit(1650426803.830:2053556): apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_cli" pid=3614961 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
2022-04-20T03:53:24Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 03:53:23.838284 +0000 UTC audit: type=1400 audit(1650426803.830:2053557): apparmor="DENIED" operation="exec" profile="snap.appengine-snap.app-engine" name="/usr/sbin/wpa_cli" pid=3614961 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0

This is my snap config, (with the system-file), to solve this, but does not work.

  1. Question, my app contains a tcp server and listen to special port 2122. When is install the snap in devmode i can connect/find to this port… but in non-devmode i cant… is there a Snap portfording or a firewall mechanims!? the interface "‘network-bind’ does not solve the issue

Looks like you need to plug network-observe and network-control.

you run snappy-debug in a second terminal while your app/daemon runs …

perfect thank you , workds

ok will try, thank you very much

So some last issues:)

1. My app (Executable) which i run in a SNAP has some further lib which are located in the “extension” sub- folder of my executable folder.

but when i install the snap, the libs are searched in the “/var/snap/myApp/x1/extensions” but the libes are in the executable folder is the “/snap/myApp/x1/extenson” folder. Why is SNAP searching in the “var” folder of snap!?

2

I have still this problem:

> 2022-04-20T08:37:53Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 08:37:53.463976 +0000 UTC AVC apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/dev/shm/sem.CME-ACC" pid=3645050 comm="AppEngine" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
> 2022-04-20T08:37:53Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 08:37:53.464203 +0000 UTC AVC apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/dev/shm/sem.CME-ACC" pid=3645050 comm="AppEngine" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
> 2022-04-20T08:37:53Z ctrlx-CORE /snap/rexroth-deviceadmin/970/bin/wasp[1575] 2022-04-20 08:37:53.464435 +0000 UTC AVC apparmor="DENIED" operation="open" profile="snap.appengine-snap.app-engine" name="/dev/shm/sem.CME-ACC" pid=3645050 comm="AppEngine" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0

i thoug i can fix this with the interface:

plugs:
  shared-folder:
     interface: system-files
       read: [ /dev/shm ]
       write: [ /dev/shm ]

but does not work

because that’s a “device folder” not a “system-file”, i don’t think you can use system-files for this … take a look at the shared-memory interface instead … (in fact snappy-debug should have suggested exactly this, did it not ??)

just trying…

my i cant to few permissions.!?

you shoud use the full command it suggests …