Classic snap not able to access host binary

TLDR; How can I add an app to my snap that runs a binary on the host?

I have created a snap with some parts and apps. I was able to build it and install it using classic confinement because the snap needs to access sos from the host. Since it is classically confined, I assumed I could add to my snapcraft.yaml

apps:
  sos-report:
    command: /usr/local/bin/sos report

Where /usr/local/bin/sos is the binary location on my host. When I try to build with snapcraft I get the error:

2024-09-24 16:30:50.791 :: 2024-09-24 16:30:49.964 Detailed information: 2024/09/24 16:30:49.954002 container.go:393: in snap "cos-doctor": path "usr/local" does not exist
2024-09-24 16:30:50.791 :: 2024/09/24 16:30:49.955874 container.go:393: in snap "cos-doctor": path "usr" does not exist
2024-09-24 16:30:50.791 :: 2024/09/24 16:30:49.956047 container.go:393: in snap "cos-doctor": path "usr/local/bin/sos" does not exist
2024-09-24 16:30:50.791 :: 2024/09/24 16:30:49.956090 container.go:393: in snap "cos-doctor": path "usr/local/bin" does not exist

How can I add an app to my snap that runs a binary on the host?

I got it to work like this:

parts:
  sos-report-passthrough:
    plugin: dump
    source: .
    organize:
      sos-wrapper.sh: bin/
apps:  
  sos-report:
    command: bin/sos-wrapper.sh report --only-plugins juju

Where sos-wrapper.sh is:

#!/bin/sh
exec /usr/local/bin/sos "$@"

That is to be expected since what goes in the Snap’s command: is expected to be a binary within the .snap file.

1 Like