Use of content interface for sharing files (read-only)

I would like to a one snap to be able to read a file produced by another snap. The consumer snap will only read the file, never write to it.

Is ‘executables’ the correct content type to use ?

Producer snap can share whatever folder you want, with the permissions it needs. In this case, read permissions:

slots:
  myshare:
    interface: content
    content: mydirectory
    read:
      - $SNAP/myfolderweretheexecis

And then, consumer snap should plug to that slot. Define in snapcraft.yaml something like:

plugs:
  myshare:
    interface: content
    content: mydirectory
    target: $SNAP_DATA
    default-provider: myproducersnap

once connected:

snap connect myconsumersnap:myshare myproducersnap:myshare

you should have ready to use in consumer $SNAP_DATA folder whatever is available in producer $SNAP/myfolderweretheexecis path as readonly content.

You can find more details here

2 Likes

Hi again,
I am not sure how this is supposed to work.
I followed the steps.

Here is my producer snap (epizaphost)

slots:
  zaphost-logfile:
    interface: content
    content: mydirectory
    read:
      - $SNAP_DATA/log

Here is my consumer snap (epigateway)

plugs:
    zaphost-logfile:
        interface: content
        content: mydirectory
        target: $SNAP_DATA/log
        default-provider: epizaphost

They are connected
epizaphost:zaphost-logfile epigateway:zaphost-logfile

There is a file ZapHost.log in $SNAP_DATA/log of epizaphost.
I want the epigateway snap to be able to read it.
However it is not accessible in $SNAP_DATA/log now?

Hey

Which version of snapd are you observing this on? Can you add /run/snapd/ns/*.fstab files corresponding to the two snaps please?

Hi.
I am using snapd 2.23.6. This seems to be the latest version that has been made available for the specific platform I am running on.

There are no .fstab files in /run/snapd/ns/ (only .lock and .mnt)

Does snapd get updated with a snap refresh ?

Hi,
Does anyone have an update on this feature, do I need to wait for the newest snapd ?

I would like some further explanation about the content interface. I have defined a slot and a plug to use a content interface as described above.

It works by allowing the consumer snap to access files in the producer snaps directory without any denials being issued. So for epi-gateway snap can read a file in /var/snap/epi-zaphost/current/log.

Is this correct behavior/utilization of the interface? The reason I ask is because the previous comments indicated (Use of content interface for sharing files (read-only) - #2 by rmescandon) :

" you should have ready to use in consumer $SNAP_DATA folder whatever is available in producer $SNAP/myfolderweretheexecis path as readonly content."

which is not exactly what I am experiencing.

Hey

Which platform is that, what does snap version say?

$ snap version
snap 2.26.14
snapd 2.26.14
series 16
kernel 4.4.0-89-generic

I see, are you on a custom core snap? Can you please add some more information:

snap info core

Also please try to refresh, maybe that’s all you need snap refresh.

snap refresh tells me all my snaps are up to date.

snap info core
name: core
summary: “snapd runtime environment”
publisher: canonical
contact: snappy-canonical-storeaccount@canonical.com
description: |
The core runtime environment for snapd
type: core
tracking: stable
installed: 16-2.26.14 (2462) 84MB -
refreshed: 2017-07-20 12:45:34 +0000 UTC
channels:
stable: 16-2.26.14 (2462) 84MB -
candidate: 16-2.27.2 (2677) 85MB -
beta: 16-2.27.2 (2677) 85MB -
edge: 16-2.27.2 (2708) 85MB -

Can you please refresh to the core snap from the candidate channel. I believe this will give you 2.27.2 and many content interface fixes.

snap refresh core --candidate

Hi,
Thanks for that. I am not sure yet if we are going to update from the candidate channel, so I might be constrained to wait until those fixes make it to the stable channel.
However at least I know now it is not working as intended.

The stable release should be out soon. I’ll let @mvo comment when this is going to happen.

As described above in Use of content interface for sharing files (read-only) I tried to implement a directory sharing between two snaps.

Since the update of the core snaps I now can see all the files from

/var/snap/epi-gateway/current/log IN
/var/snap/epi-zaphost/current/log

So it worked out in the reverse order.
In other words the files from the snap defining the plug are available to the snap providing the slot.
Maybe this was how is was supposed to work all along but the documentation and comments here led me understand otherwise. Can anyone explain.
Thanks.

My basic problem was that it was not a good idea to have the target directory the same as a directory containing files belonging to the consumer.
So now the log files for the consumer snap are created in $SNAP_DATA/log
So now the log files for the producer snap are created in $SNAP_DATA/log

However the target directory in the content interface plug is defined as $SNAP_DATA/othersnap-log

So the consumer snap sees the log files from the producer snap in $SNAP_DATA/othersnap-log.