Skip to content

Commit bbed341

Browse files
committed
add bindexec
1 parent 36012ef commit bbed341

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
- Add a bindexec command.
2+
- Stop using $TMPDIR as a temporary variable name in cvmfsexec because it
3+
might be already set and exported.
4+
15
cvmfsexec-4.46 - 2 April 2025
26
- Go back to selecting the cvmfs version from the egi and osg distribution.
37
- Properly sort the cvmfs version number from the downloaded list of packages.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ do this in 4 different ways:
4242
unprivileged user namespaces enabled,
4343
this can also be used with unprivileged singularity or apptainer.
4444

45+
In addition, this package contains a related tool called
46+
[bindexec](#bindexec) which starts a new user namespace with given
47+
bind mounts added.
48+
4549
# Supported operating systems
4650

4751
Operating systems currently supported by this package are Red Hat
@@ -370,3 +374,40 @@ $ mkfs.ext3 -F -O ^has_journal -d tmp scratch.img
370374
By default the cvmfs logs are written to a top-level `log` directory, alongside
371375
the top-level `dist` directory. The variable `SINGCVMFS_LOGDIR` can be used to
372376
write them to a different directory, which will be created if it doesn't exist.
377+
378+
# bindexec
379+
380+
As a bonus, this package also includes a separate tool called `bindexec`
381+
that accepts any set of bind mounts to add into a new unprivileged user
382+
mount namespace. The usage is much like `cvmfsexec` except that instead
383+
of cvmfs repository names you give it `src:dest` pairs where `src` is a
384+
source directory or file and `dest` is a destination path. For example:
385+
386+
```
387+
$ bindexec /etc/motd:/var/lib/mydir/motd -- ls /var/lib/mydir
388+
motd
389+
```
390+
391+
Like `cvmfsexec`, if no command is supplied after `--` it runs an
392+
interactive shell.
393+
394+
Bind mounts require target destinations to exist, but if they are
395+
missing `bindexec` will automatically create them. This requires the
396+
fuse-overlayfs command to be in the PATH, although if there is demand
397+
for it a script for making that easily distributable as well will be
398+
supplied (probably through a `makedist` option).
399+
400+
Some system directories (`/proc`, `/sys`, `/dev`, and `/run`) are
401+
included as-is on top of the overlay so anything bound into those
402+
directories will not appear. In addition, any `nfs` filesystem types
403+
are automatically added on top of the overlay because they don't work
404+
properly through overlay, so no bind mounts will appear in those paths
405+
either.
406+
407+
`bindexec` always creates a new process namespace because that's the
408+
easiest way to make sure that the fuse-overlayfs process will exit when
409+
the command exits. This means that processes start over at pid 1 and no
410+
process can be seen outside of the namespace. Also because it is using
411+
an unprivileged user namespace, any files owned by anyone other than the
412+
current user will show up as being owned by `nobody` (just as it does in
413+
`cvmfsexec`).

cvmfsexec

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ elif [ "$MAJORKERN" -eq 3 -a "$MINORKERN" -eq 10 -a "$REVKERN" -ge 1127 ]; then
3939
USERFUSE=true
4040
fi
4141

42-
TMPDIR=$(mktemp -d)
43-
trap "rm -rf $TMPDIR" 0 # note that trap does not carry past exec
44-
CMDFIFO1=$TMPDIR/cmd1
45-
WAITFIFO1=$TMPDIR/wait1
46-
CMDFIFO2=$TMPDIR/cmd2
47-
WAITFIFO2=$TMPDIR/wait2
48-
FUNCS=$TMPDIR/funcs
42+
TMPD=$(mktemp -d)
43+
trap "rm -rf $TMPD" 0 # note that trap does not carry past exec
44+
CMDFIFO1=$TMPD/cmd1
45+
WAITFIFO1=$TMPD/wait1
46+
CMDFIFO2=$TMPD/cmd2
47+
WAITFIFO2=$TMPD/wait2
48+
FUNCS=$TMPD/funcs
4949

5050
# create the fifos used for interprocess communication
5151
mkfifo $CMDFIFO1 $WAITFIFO1 $CMDFIFO2 $WAITFIFO2
@@ -238,7 +238,7 @@ else
238238
fi
239239
./umountrepo $REPO >/dev/null
240240
done
241-
rm -rf $TMPDIR
241+
rm -rf $TMPD
242242
) &
243243
fi
244244

@@ -252,7 +252,7 @@ unshare -rm $UNSHAREOPTS /bin/bash /dev/stdin "${@:-$SHELL}" <<!EOF-1!
252252
#set -x
253253
#PS4='c\$$+ '
254254
# now in the "fakeroot" namespace
255-
trap "rm -rf $TMPDIR" 0 # note that this does not carry through "exec"
255+
trap "rm -rf $TMPD" 0 # note that this does not carry through "exec"
256256
257257
mkdir -p $HERE/mnt
258258
mount --rbind $HERE/mnt $HERE/mnt # pivot_root requires this mountpoint
@@ -411,7 +411,7 @@ unshare -rm $UNSHAREOPTS /bin/bash /dev/stdin "${@:-$SHELL}" <<!EOF-1!
411411
# processes in the namespaces will get a SIGKILL when
412412
# PID 1 exits.
413413
EXEC=""
414-
trap "rm -rf $TMPDIR" 0
414+
trap "rm -rf $TMPD" 0
415415
trap "" 1 2 3 15 # ignore all ordinary signals
416416
else
417417
EXEC=exec

0 commit comments

Comments
 (0)