apptainer / apptainer

Apptainer: Application containers for Linux
https://apptainer.org
Other
1.12k stars 139 forks source link

/etc/mtab doesn't always exist #2508

Open tbugfinder opened 1 month ago

tbugfinder commented 1 month ago

Version of Apptainer

What version of Apptainer (or Singularity) are you using? Run

apptainer --version (or singularity --version). $ apptainer --version apptainer version 1.3.4

Expected behavior

Follow up to: https://github.com/apptainer/singularity/issues/4182

Execute fuse commands within ubuntu 22.04 image (e.g. mount.fuse.sshfs)

Actual behavior

What actually happened? Why was it incorrect?

There's an error about missing /etc/mtab (failed to open /etc/mtab) however that file was built as a link within the image source.

Apptainer> mount.fuse.sshfs localhost:/ ./mounts/test/
fusermount3: failed to open /etc/mtab: No such file or directory
fusermount3: mount failed: Operation not permitted

Steps to reproduce this behavior

How can others reproduce this issue/problem? Build Image:

FROM ubuntu:jammy
apt-get install -y sshfs

Run:

apptainer run my.sif /bin/bash
mount.fuse.sshfs .......

What OS/distro are you running

$ cat /etc/os-release

Apptainer> cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
Apptainer>

How did you install Apptainer

Write here how you installed Apptainer (or Singularity). Eg. RPM, source. deb/apt package

DrDaveD commented 1 month ago

That symptom is not the primary underlying problem. The problem is that fusermount3 is a setuid-root program so it is unable to run inside of apptainer which is an unprivileged only context.

However, sshfs does work inside a root-mapped user namespace. You can make it work with either using the --fusemount option or by running inside apptainer

unshare -rm
mount.fuse.sshfs ...

In the latter case the mountpoint will only be visible inside the root-mapped subshell under unshare.