Mapping of /tmp/ to /tmp/snap.*


I regularly get the error:

lxc init sdk-base
Creating the container
Error: open /tmp/lxd_config_408598002: no such file or directory

and the fellows on linuxcontainers told me that this has to do with the directory called /tmp/snap.0_lxd_XXXXXXX which is mapped to /tmp in the snap’s mount namespace.

Where do I have to look to understand how this mapping takes place within snap?
Which technique and tools are used to map the temporary directory?



Here is what is going on:

  • You execute “lxc”, which $PATH maps to /snap/bin/lxc.
  • That path is a symlink to /usr/bin/snap, which ends up running the equivalent of snap run lxd.lxc.
  • snap run uses the privileged snap-confine utility to configure the sandbox for running apps from the lxd package. Among other things, this involves setting up a mount namespace distinct from that used by unconfined applications on the host system.
  • This mount namespace includes a private /tmp directory (as you’ve discovered).

The intent of the private tmp directory is to give the confined app the freedom to write any temporary files it wants without risk of colliding with other apps or opening a side channel for communication with other apps.

It also means that you can’t easily use /tmp as a way to communicate with a strict confined snap application.

1 Like