File: userbindmount.1

package info (click to toggle)
userbindmount 0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: ansic: 242; makefile: 19
file content (132 lines) | stat: -rw-r--r-- 3,910 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
.TH USERBINDMOUNT 1 "August 22, 2017" "VirtualSquare Labs"
.SH NAME
userbindmount \- bind-mount utility for user-namespaces
.SH SYNOPSIS
.B userbindmount
.RI "[options] [" source " " target " [" source " " target " [...]]] [ " -- " [" cmd " [" args "]]]"

.SH DESCRIPTION

userbindmount is a utility command based on libuserbindmount.

It can be used to perform one or more bind-mount operation and to create a user-namespace where
bind-mount is allowed.

This command does not need root access or specific capabilities to run (provided user-namespaces are supported,
see NOTES).

The command line arguments are a list of \fIsource\fR-\fItarget\fR pairs (one for each
bind-mount operation). 
A new namespace is created if requested by the specific option (-n or
--newns) or if there is -- as an option in the command line.
If \fIsource\fR is a double quoted string, the value of the string will be the content
of the file mounted on \fItarget\fR.
The trailing -- followed by a command and its argument define the command
to run in the new namespace. ($SHELL is launched if the command is omitted)

The contents of the file to be mounted on \fItarget\fR is read from
the standard input if the correspondent \fIsource\fR is the tag "-".

.SH OPTIONS
.I userbindmount
accepts the following options.

.TP
\fB\-n 
.TQ
\fB\-\-newns
create a new user-namespace

.TP
\fB\-s 
.TQ
\fB\-\-sysadm 
add the CAP_SYS_ADMIN ambient capability to the current of newly created userspace

.TP
\fB\-v 
.TQ
\fB\-\-verbose 
verbose mode: print debugging information on the actions taken by the program.

.SH NOTES
User namespaces require a kernel that is configured with the CONFIG_USER_NS option.
In some distributions (e.g. Debian) user namespaces must be enabled by writing 1 to
/proc/sys/kernel/unprivileged_userns_clone.
.SH EXAMPLES
The following example mounts the file /tmp/resolv.conf instead of /etc/resolv.conf: the purpose of 
this example is to redefine the name servers for the name resolution.
.RS
.nf
$ cat /etc/resolv.conf
nameserver 127.0.0.1
$ echo "nameserver 9.9.9.9" > /tmp/resolv.conf
$ userbindmount -v /tmp/resolv.conf /etc/resolv.conf -- bash
creating a user_namespace
mounting /tmp/resolv.conf on /etc/resolv.conf
starting bash
$ cat /etc/resolv.conf 
nameserver 9.9.9.9
$ exit
$
.fi
.RE

.sp
The following example creates a namespace where bind-mount is allowed and then mounts /tmp/resolv.conf on
/etc/resolv.conf. (It uses busybox instead of mount(8) as the latter does not support the capabilities, yet).
.RS
.nf 
$ userbindmount -s -- bash
$ cat /etc/resolv.conf 
nameserver 127.0.0.1
$ echo "nameserver 9.9.9.9" > /tmp/resolv.conf
$ busybox mount --bind /tmp/resolv.conf /etc/resolv.conf 
$ cat /etc/resolv.conf
nameserver 9.9.9.9
$ exit
$
.fi
.RE
Alternative equivalent commands for "userbindmount -s -- bash" are "userbindmount -sn" or "userbindmount -s --\fR".

.sp
Several bind-mounts can be done in a user-namespace started with the -s option. 
No more namespaces are needed in this case.
The contents of the file to mount can be taken from stdin if source is "-".
.RS
.nf
$ userbindmount -sn
$ echo "nameserver 9.9.9.9" | userbindmount - /etc/resolv.conf
$ cat /etc/resolv.conf
nameserver 9.9.9.9
$ exit
.fi
.RE

.sp
It is possible to set the contents of a mounted file directly in the command line:
.RS
.nf
$ userbindmount $'"nameserver 9.9.9.9\\n"' /etc/resolv.conf -- bash
$ cat /etc/resolv.conf
nameserver 9.9.9.9
$ exit
.fi
.RE


Please note that the following command:
.RS
.nf
$ echo "nameserver 9.9.9.9" | userbindmount - /etc/resolv.conf -- bash
.fi
.RE
works but the bash running in the new namespace terminates immediately as it reads the end-of-file on its
standard input.
.SH SEE ALSO
.BR "libuserbindmount"(3), " mount"(8), " user_namespaces"(7), " capabilities"(7)
.SH BUGS
Bug reports should be addressed to <info@virtualsquare.org>
.SH AUTHORS
Renzo Davoli <renzo@cs.unibo.it>