Merge from vendor branch OPENSSH:
[dragonfly.git] / usr.sbin / jail / jail.8
1 .\"
2 .\" Copyright (c) 2000 Robert N. M. Watson
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\"
27 .\" ----------------------------------------------------------------------------
28 .\" "THE BEER-WARE LICENSE" (Revision 42):
29 .\" <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
30 .\" can do whatever you want with this stuff. If we meet some day, and you think
31 .\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
32 .\" ----------------------------------------------------------------------------
33 .\"
34 .\" $FreeBSD: src/usr.sbin/jail/jail.8,v 1.13.2.15 2003/05/08 13:04:24 maxim Exp $
35 .\" $DragonFly: src/usr.sbin/jail/jail.8,v 1.5 2006/09/09 16:22:52 corecode Exp $
36 .\"
37 .Dd December 12, 2001
38 .Dt JAIL 8
39 .Os
40 .Sh NAME
41 .Nm jail
42 .Nd "imprison process and its descendants"
43 .Sh SYNOPSIS
44 .Nm
45 .Op Fl u Ar username
46 .Ar path hostname ip-number command ...
47 .Sh DESCRIPTION
48 The
49 .Nm
50 command imprisons a process and all future descendants.
51 .Pp
52 The options are as follows:
53 .Bl -tag -width ".Fl u Ar username"
54 .It Fl u Ar username
55 The user name as whom the
56 .Ar command
57 should run.
58 .It Ar path
59 Directory which is to be the root of the prison.
60 .It Ar hostname
61 Hostname of the prison.
62 .It Ar ip-number
63 IP number assigned to the prison.
64 .It Ar command
65 Pathname of the program which is to be executed.
66 .El
67 .Pp
68 Please see the
69 .Xr jail 2
70 man page for further details.
71 .Sh EXAMPLES
72 .Ss "Setting up a Jail Directory Tree"
73 This example shows how to setup a jail directory tree
74 containing an entire
75 .Dx
76 distribution, provided that you built world before already:
77 .Bd -literal
78 D=/here/is/the/jail
79 cd /usr/src
80 mkdir -p $D
81 make installworld DESTDIR=$D
82 cd etc
83 make distribution DESTDIR=$D -DNO_MAKEDEV_RUN
84 cd $D/dev
85 sh MAKEDEV jail
86 cd $D
87 ln -sf dev/null kernel
88 .Ed
89 .Pp
90 In many cases this example would put far more stuff in the jail than is needed.
91 In the other extreme case a jail might contain only one single file:
92 the executable to be run in the jail.
93 .Pp
94 We recommend experimentation and caution that it is a lot easier to
95 start with a
96 .Dq fat
97 jail and remove things until it stops working,
98 than it is to start with a
99 .Dq thin
100 jail and add things until it works.
101 .Ss "Setting Up a Jail"
102 Do what was described in
103 .Sx "Setting Up a Jail Directory Tree"
104 to build the jail directory tree.
105 For the sake of this example, we will
106 assume you built it in
107 .Pa /data/jail/192.168.11.100 ,
108 named for the jailed IP address.
109 Substitute below as needed with your
110 own directory, IP address, and hostname.
111 .Pp
112 First, you will want to set up your real system's environment to be
113 .Dq jail-friendly .
114 For consistency, we will refer to the parent box as the
115 .Dq "host environment" ,
116 and to the jailed virtual machine as the
117 .Dq "jail environment" .
118 Because jail is implemented using IP aliases, one of the first things to do
119 is to disable IP services on the host system that listen on all local
120 IP addresses for a service.
121 This means changing
122 .Xr inetd 8
123 to only listen on the
124 appropriate IP address, and so forth.
125 Add the following to
126 .Pa /etc/rc.conf
127 in the host environment:
128 .Bd -literal -offset indent
129 sendmail_enable="NO"
130 inetd_flags="-wW -a 192.168.11.23"
131 portmap_enable="NO"
132 .Ed
133 .Pp
134 .Li 192.168.11.23
135 is the native IP address for the host system, in this example.
136 Daemons that run out of
137 .Xr inetd 8
138 can be easily set to use only the specified host IP address.
139 Other daemons
140 will need to be manually configured\(emfor some this is possible through
141 the
142 .Xr rc.conf 5
143 flags entries, for others it is not possible without munging
144 the per-application configuration files, or even recompiling.
145 For those
146 applications that cannot specify the IP they run on, it is better to disable
147 them, if possible.
148 .Pp
149 A number of daemons ship with the base system that may have problems when
150 run from outside of a jail in a jail-centric environment.
151 This includes
152 .Xr sendmail 8 ,
153 .Xr named 8 ,
154 and
155 .Xr portmap 8 .
156 While
157 .Xr sendmail 8
158 and
159 .Xr named 8
160 can be configured to listen only on a specific
161 IP using their configuration files, in most cases it is easier to simply
162 run the daemons in jails only, and not in the host environment.
163 Attempting to serve
164 NFS from the host environment may also cause confusion, and cannot be
165 easily reconfigured to use only specific IPs, as some NFS services are
166 hosted directly from the kernel.
167 Any third party network software running
168 in the host environment should also be checked and configured so that it
169 does not bind all IP addresses, which would result in those services also
170 appearing to be offered by the jail environments.
171 .Pp
172 Once
173 these daemons have been disabled or fixed in the host environment, it is
174 best to reboot so that all daemons are in a known state, to reduce the
175 potential for confusion later (such as finding that when you send mail
176 to a jail, and its sendmail is down, the mail is delivered to the host,
177 etc.)
178 .Pp
179 Start any jails for the first time without configuring the network
180 interface so that you can clean it up a little and set up accounts.
181 As
182 with any machine (virtual or not) you will need to set a root password, time
183 zone, etc.
184 .Pp
185 Now start the jail:
186 .Pp
187 .Dl "jail /data/jail/192.168.11.100 testhostname 192.168.11.100 /bin/sh"
188 .Pp
189 You will end up with a shell prompt, assuming no errors, within the jail.
190 You can now do the post-install configuration to set various configuration
191 options by editing
192 .Pa /etc/rc.conf ,
193 etc.
194 .Pp
195 .Bl -bullet -offset indent -compact
196 .It
197 Create an empty
198 .Pa /etc/fstab
199 to quell startup warnings about missing fstab
200 .It
201 Disable the port mapper
202 .Pa ( /etc/rc.conf :
203 .Li portmap_enable="NO" )
204 .It
205 Run
206 .Xr newaliases 1
207 to quell
208 .Xr sendmail 8
209 warnings.
210 .It
211 Disable interface configuration to quell startup warnings about
212 .Xr ifconfig 8
213 .Pq Li network_interfaces=""
214 .It
215 Configure
216 .Pa /etc/resolv.conf
217 so that name resolution within the jail will work correctly
218 .It
219 Set a root password, probably different from the real host system
220 .It
221 Set the timezone with
222 .Xr tzsetup 8
223 .It
224 Add accounts for users in the jail environment
225 .It
226 Install any packages that you think the environment requires
227 .El
228 .Pp
229 You may also want to perform any package-specific configuration (web servers,
230 SSH servers, etc), patch up
231 .Pa /etc/syslog.conf
232 so it logs as you would like, etc.
233 .Pp
234 Exit from the shell, and the jail will be shut down.
235 .Ss "Starting the Jail"
236 You are now ready to restart the jail and bring up the environment with
237 all of its daemons and other programs.
238 To do this, first bring up the
239 virtual host interface, and then start the jail's
240 .Pa /etc/rc
241 script from within the jail.
242 .Pp
243 NOTE: If you plan to allow untrusted users to have root access inside the
244 jail, you may wish to consider setting the
245 .Va jail.set_hostname_allowed
246 to 0.
247 Please see the management reasons why this is a good idea.
248 If you do decide to set this variable,
249 it must be set before starting any jails, and once each boot.
250 .Bd -literal -offset indent
251 ifconfig ed0 inet alias 192.168.11.100/32
252 mount -t procfs proc /data/jail/192.168.11.100/proc
253 jail /data/jail/192.168.11.100 testhostname 192.168.11.100 \\
254         /bin/sh /etc/rc
255 .Ed
256 .Pp
257 A few warnings will be produced, because most
258 .Xr sysctl 8
259 configuration variables cannot be set from within the jail, as they are
260 global across all jails and the host environment.
261 However, it should all
262 work properly.
263 You should be able to see
264 .Xr inetd 8 ,
265 .Xr syslogd 8 ,
266 and other processes running within the jail using
267 .Xr ps 1 ,
268 with the
269 .Ql J
270 flag appearing beside jailed processes.
271 You should also be able to
272 .Xr telnet 1
273 to the hostname or IP address of the jailed environment, and log
274 in using the accounts you created previously.
275 .Ss "Managing the Jail"
276 Normal machine shutdown commands, such as
277 .Xr halt 8 ,
278 .Xr reboot 8 ,
279 and
280 .Xr shutdown 8 ,
281 cannot be used successfully within the jail.
282 To kill all processes in a
283 jail, you may log into the jail and, as root, use one of the following
284 commands, depending on what you want to accomplish:
285 .Pp
286 .Bd -literal -offset indent
287 kill -TERM -1
288 kill -KILL -1
289 .Ed
290 .Pp
291 This will send the
292 .Dv SIGTERM
293 or
294 .Dv SIGKILL
295 signals to all processes in the jail from within the jail.
296 Depending on
297 the intended use of the jail, you may also want to run
298 .Pa /etc/rc.shutdown
299 from within the jail.
300 Currently there is no way to insert new processes
301 into a jail, so you must first log into the jail before performing these
302 actions.
303 .Pp
304 To kill processes from outside the jail, you must individually identify the
305 PID of each process to be killed.
306 The
307 .Pa /proc/ Ns Ar pid Ns Pa /status
308 file contains, as its last field, the hostname of the jail in which the
309 process runs, or
310 .Dq Li -
311 to indicate that the process is not running within a jail.
312 The
313 .Xr ps 1
314 command also shows a
315 .Ql J
316 flag for processes in a jail.
317 However, the hostname for a jail may be, by
318 default, modified from within the jail, so the
319 .Pa /proc
320 status entry is unreliable by default.
321 To disable the setting of the hostname
322 from within a jail, set the
323 .Va jail.set_hostname_allowed
324 sysctl variable in the host environment to 0, which will affect all jails.
325 You can have this sysctl set on each boot using
326 .Xr sysctl.conf 5 .
327 Just add the following line to
328 .Pa /etc/sysctl.conf :
329 .Pp
330 .Dl jail.set_hostname_allowed=0
331 .Pp
332 In a future version of
333 .Dx ,
334 the mechanisms for managing jails may be
335 more refined.
336 .Ss "Sysctl MIB Entries"
337 Certain aspects of the jail containments environment may be modified from
338 the host environment using
339 .Xr sysctl 8
340 MIB variables.
341 Currently, these variables affect all jails on the system, although in
342 the future this functionality may be finer grained.
343 .Bl -tag -width XXX
344 .It Va jail.set_hostname_allowed
345 This MIB entry determines whether or not processes within a jail are
346 allowed to change their hostname via
347 .Xr hostname 1
348 or
349 .Xr sethostname 3 .
350 In the current jail implementation, the ability to set the hostname from
351 within the jail can impact management tools relying on the accuracy of jail
352 information in
353 .Pa /proc .
354 As such, this should be disabled in environments where privileged access to
355 jails is given out to untrusted parties.
356 .It Va jail.socket_unixiproute_only
357 The jail functionality binds an IPv4 address to each jail, and limits
358 access to other network addresses in the IPv4 space that may be available
359 in the host environment.
360 However, jail is not currently able to limit access to other network
361 protocol stacks that have not had jail functionality added to them.
362 As such, by default, processes within jails may only access protocols
363 in the following domains:
364 .Dv PF_LOCAL , PF_INET ,
365 and
366 .Dv PF_ROUTE ,
367 permitting them access to
368 .Ux
369 domain sockets,
370 IPv4 addresses, and routing sockets.
371 To enable access to other domains, this MIB variable may be set to
372 0.
373 .It Va jail.sysvipc_allowed
374 This MIB entry determines whether or not processes within a jail have access
375 to System V IPC primitives.
376 In the current jail implementation, System V primitives share a single
377 namespace across the host and jail environments, meaning that processes
378 within a jail would be able to communicate with (and potentially interfere
379 with) processes outside of the jail, and in other jails.
380 As such, this functionality is disabled by default, but can be enabled
381 by setting this MIB entry to 1.
382 .El
383 .Sh SEE ALSO
384 .Xr newaliases 1 ,
385 .Xr ps 1 ,
386 .Xr chroot 2 ,
387 .Xr jail 2 ,
388 .Xr procfs 5 ,
389 .Xr rc.conf 5 ,
390 .Xr sysctl.conf 5 ,
391 .Xr halt 8 ,
392 .Xr inetd 8 ,
393 .Xr named 8 ,
394 .Xr portmap 8 ,
395 .Xr pw 8 ,
396 .Xr reboot 8 ,
397 .Xr sendmail 8 ,
398 .Xr shutdown 8 ,
399 .Xr sysctl 8 ,
400 .Xr syslogd 8 ,
401 .Xr tzsetup 8
402 .Sh HISTORY
403 The
404 .Nm
405 command appeared in
406 .Fx 4.0 .
407 .Sh AUTHORS
408 .An -nosplit
409 The jail feature was written by
410 .An Poul-Henning Kamp
411 for R&D Associates
412 .Pa http://www.rndassociates.com/
413 who contributed it to
414 .Fx .
415 .Pp
416 .An Robert Watson
417 wrote the extended documentation, found a few bugs, added
418 a few new features, and cleaned up the userland jail environment.
419 .Sh BUGS
420 Jail currently lacks strong management functionality, such as the ability
421 to deliver signals to all processes in a jail, and to allow access to
422 specific jail information via
423 .Xr ps 1
424 as opposed to
425 .Xr procfs 5 .
426 Similarly, it might be a good idea to add an
427 address alias flag such that daemons listening on all IPs
428 .Pq Dv INADDR_ANY
429 will not bind on that address, which would facilitate building a safe
430 host environment such that host daemons do not impose on services offered
431 from within jails.
432 Currently, the simplist answer is to minimize services
433 offered on the host, possibly limiting it to services offered from
434 .Xr inetd 8
435 which is easily configurable.