]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.sbin/jail/jail.8
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.sbin / jail / jail.8
1 .\"
2 .\" Copyright (c) 2000, 2003 Robert N. M. Watson
3 .\" Copyright (c) 2008 James Gritton
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" SUCH DAMAGE.
26 .\"
27 .\"
28 .\" ----------------------------------------------------------------------------
29 .\" "THE BEER-WARE LICENSE" (Revision 42):
30 .\" <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
31 .\" can do whatever you want with this stuff. If we meet some day, and you think
32 .\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
33 .\" ----------------------------------------------------------------------------
34 .\"
35 .\" $FreeBSD$
36 .\"
37 .Dd January 17, 2010
38 .Dt JAIL 8
39 .Os
40 .Sh NAME
41 .Nm jail
42 .Nd "create or modify a system jail"
43 .Sh SYNOPSIS
44 .Nm
45 .Op Fl dhi
46 .Op Fl J Ar jid_file
47 .Op Fl l u Ar username | Fl U Ar username
48 .Op Fl c | m
49 .Op Ar parameter=value ...
50 .Br
51 .Nm
52 .Op Fl hi
53 .Op Fl n Ar jailname
54 .Op Fl J Ar jid_file
55 .Op Fl s Ar securelevel
56 .Op Fl l u Ar username | Fl U Ar username
57 .Op Ar path hostname [ip[,..]] command ...
58 .Br
59 .Nm
60 .Op Fl r Ar jail
61 .Sh DESCRIPTION
62 The
63 .Nm
64 utility creates a new jail or modifies an existing jail, optionally
65 imprisoning the current process (and future descendants) inside it.
66 .Pp
67 The options are as follows:
68 .Bl -tag -width indent
69 .It Fl d
70 Allow making changes to a
71 .Va
72 dying jail.
73 .It Fl h
74 Resolve the
75 .Va host.hostname
76 parameter (or
77 .Va hostname )
78 and add all IP addresses returned by the resolver
79 to the list of
80 .Va ip
81 addresses for this prison.
82 This may affect default address selection for outgoing IPv4 connections
83 of prisons.
84 The address first returned by the resolver for each address family
85 will be used as primary address.
86 See the
87 .Va ip4.addr
88 and
89 .Va ip6.addr
90 parameters further down for details.
91 .It Fl i
92 Output the jail identifier of the newly created jail.
93 .It Fl n Ar jailname
94 Set the jail's name.
95 This is deprecated and is equivalent to setting the
96 .Va name
97 parameter.
98 .It Fl J Ar jid_file
99 Write a
100 .Ar jid_file
101 file, containing jail identifier, path, hostname, IP and
102 command used to start the jail.
103 .It Fl l
104 Run program in the clean environment.
105 The environment is discarded except for
106 .Ev HOME , SHELL , TERM
107 and
108 .Ev USER .
109 .Ev HOME
110 and
111 .Ev SHELL
112 are set to the target login's default values.
113 .Ev USER
114 is set to the target login.
115 .Ev TERM
116 is imported from the current environment.
117 The environment variables from the login class capability database for the
118 target login are also set.
119 .It Fl s Ar securelevel
120 Set the
121 .Va kern.securelevel
122 MIB entry to the specified value inside the newly created jail.
123 This is deprecated and is equivalent to setting the
124 .Va securelevel
125 parameter.
126 .It Fl u Ar username
127 The user name from host environment as whom the
128 .Ar command
129 should run.
130 .It Fl U Ar username
131 The user name from jailed environment as whom the
132 .Ar command
133 should run.
134 .It Fl c
135 Create a new jail.
136 The
137 .Va jid
138 and
139 .Va name
140 parameters (if specified) must not refer to an existing jail.
141 .It Fl m
142 Modify an existing jail.
143 One of the
144 .Va jid
145 or
146 .Va name
147 parameters must exist and refer to an existing jail.
148 .It Fl cm
149 Create a jail if it does not exist, or modify a jail if it does exist.
150 .It Fl r
151 Remove the
152 .Ar jail
153 specified by jid or name.
154 All jailed processes are killed, and all children of this jail are also
155 removed.
156 .El
157 .Pp
158 At least one of the
159 .Fl c ,
160 .Fl m
161 or
162 .Fl r
163 options must be specified.
164 .Pp
165 .Ar Parameters
166 are listed in
167 .Dq name=value
168 form, following the options.
169 Some parameters are boolean, and do not have a value but are set by the
170 name alone with or without a
171 .Dq no
172 prefix, e.g.
173 .Va persist
174 or
175 .Va nopersist .
176 Any parameters not set will be given default values, often based on the
177 current environment.
178 .Pp
179 The pseudo-parameter
180 .Va command
181 specifies that the current process should enter the new (or modified) jail,
182 and run the specified command.
183 It must be the last parameter specified, because it includes not only
184 the value following the
185 .Sq =
186 sign, but also passes the rest of the arguments to the command.
187 .Pp
188 Instead of supplying named
189 .Ar parameters ,
190 four fixed parameters may be supplied in order on the command line:
191 .Ar path ,
192 .Ar hostname ,
193 .Ar ip ,
194 and
195 .Ar command .
196 As the
197 .Va jid
198 and
199 .Va name
200 parameters aren't in this list, this mode will always create a new jail, and
201 the
202 .Fl c
203 and
204 .Fl m
205 options don't apply (and must not exist).
206 .Pp
207 Jails have a set a core parameters, and modules can add their own jail
208 parameters.
209 The current set of available parameters can be retrieved via
210 .Dq Nm sysctl Fl d Va security.jail.param .
211 The core parameters are:
212 .Bl -tag -width indent
213 .It Va jid
214 The jail identifier.
215 This will be assigned automatically to a new jail (or can be explicitly
216 set), and can be used to identify the jail for later modification, or
217 for such commands as
218 .Xr jls 8
219 or
220 .Xr jexec 8 .
221 .It Va name
222 The jail name.
223 This is an arbitrary string that identifies a jail (except it may not
224 contain a
225 .Sq \&. ) .
226 Like the
227 .Va jid ,
228 it can be passed to later
229 .Nm
230 commands, or to
231 .Xr jls 8
232 or
233 .Xr jexec 8 .
234 If no
235 .Va name
236 is supplied, a default is assumed that is the same as the
237 .Va jid .
238 .It Va path
239 Directory which is to be the root of the prison.
240 The
241 .Va command
242 (if any) is run from this directory, as are commands from
243 .Xr jexec 8 .
244 .It Va ip4.addr
245 A comma-separated list of IPv4 addresses assigned to the prison.
246 If this is set, the jail is restricted to using only these address.
247 Any attempts to use other addresses fail, and attempts to use wildcard
248 addresses silently use the jailed address instead.
249 For IPv4 the first address given will be kept used as the source address
250 in case source address selection on unbound sockets cannot find a better
251 match.
252 It is only possible to start multiple jails with the same IP address,
253 if none of the jails has more than this single overlapping IP address
254 assigned to itself.
255 .It Va ip4.saddrsel
256 A boolean option to change the formerly mentioned behaviour and disable
257 IPv4 source address selection for the prison in favour of the primary
258 IPv4 address of the jail.
259 Source address selection is enabled by default for all jails and a
260 .Va ip4.nosaddrsel
261 setting of a parent jail is not inherited for any child jails.
262 .It Va ip4
263 Control the availablity of IPv4 addresses.
264 Possible values are
265 .Dq inherit
266 to allow unrestricted access to all system addresses,
267 .Dq new
268 to restrict addresses via
269 .Va ip4.addr
270 above, and
271 .Dq disable
272 to stop the jail from using IPv4 entirely.
273 Setting the
274 .Va ip4.addr
275 parameter implies a value of
276 .Dq new .
277 .It Va ip6.addr , Va ip6.saddrsel , Va ip6
278 A set of IPv6 options for the prison, the counterparts to
279 .Va ip4.addr ,
280 .Va ip4.saddrsel
281 and
282 .Va ip4
283 above.
284 .It Va host.hostname
285 Hostname of the prison.
286 Other similar parameters are
287 .Va host.domainname ,
288 .Va host.hostuuid
289 and
290 .Va host.hostid .
291 .It Va host
292 Set the origin of hostname and related information.
293 Possible values are
294 .Dq inherit
295 to use the system information and
296 .Dq new
297 for the jail to use the information from the above fields.
298 Setting any of the above fields implies a value of
299 .Dq new .
300 .It Va securelevel
301 The value of the jail's
302 .Va kern.securelevel
303 sysctl.
304 A jail never has a lower securelevel than the default system, but by
305 setting this parameter it may have a higher one.
306 If the system securelevel is changed, any jail securelevels will be at
307 least as secure.
308 .It Va children.max
309 The number of child jails allowed to be created by this jail (or by
310 other jails under this jail).
311 This limit is zero by default, indicating the jail is not allowed to
312 create child jails.
313 See the
314 .Va "Hierarchical Jails"
315 section for more information.
316 .It Va children.cur
317 The number of descendents of this jail, including its own child jails
318 and any jails created under them.
319 .It Va enforce_statfs
320 This determines which information processes in a jail are able to get
321 about mount points.
322 It affects the behaviour of the following syscalls:
323 .Xr statfs 2 ,
324 .Xr fstatfs 2 ,
325 .Xr getfsstat 2
326 and
327 .Xr fhstatfs 2
328 (as well as similar compatibility syscalls).
329 When set to 0, all mount points are available without any restrictions.
330 When set to 1, only mount points below the jail's chroot directory are
331 visible.
332 In addition to that, the path to the jail's chroot directory is removed
333 from the front of their pathnames.
334 When set to 2 (default), above syscalls can operate only on a mount-point
335 where the jail's chroot directory is located.
336 .It Va persist
337 Setting this boolean parameter allows a jail to exist without any
338 processes.
339 Normally, a jail is destroyed as its last process exits.
340 A new jail must have either the
341 .Va persist
342 parameter or
343 .Va command
344 pseudo-parameter set.
345 .It Va cpuset.id
346 The ID of the cpuset associated with this jail (read-only).
347 .It Va dying
348 This is true if the jail is in the process of shutting down (read-only).
349 .It Va parent
350 The
351 .Va jid
352 of the parent of this jail, or zero if this is a top-level jail
353 (read-only).
354 .It Va allow.*
355 Some restrictions of the jail environment may be set on a per-jail
356 basis.
357 With the exception of
358 .Va allow.set_hostname ,
359 these boolean parameters are off by default.
360 .Bl -tag -width indent
361 .It Va allow.set_hostname
362 The jail's hostname may be changed via
363 .Xr hostname 1
364 or
365 .Xr sethostname 3 .
366 .It Va allow.sysvipc
367 A process within the jail has access to System V IPC primitives.
368 In the current jail implementation, System V primitives share a single
369 namespace across the host and jail environments, meaning that processes
370 within a jail would be able to communicate with (and potentially interfere
371 with) processes outside of the jail, and in other jails.
372 .It Va allow.raw_sockets
373 The prison root is allowed to create raw sockets.
374 Setting this parameter allows utilities like
375 .Xr ping 8
376 and
377 .Xr traceroute 8
378 to operate inside the prison.
379 If this is set, the source IP addresses are enforced to comply
380 with the IP address bound to the jail, regardless of whether or not
381 the
382 .Dv IP_HDRINCL
383 flag has been set on the socket.
384 Since raw sockets can be used to configure and interact with various
385 network subsystems, extra caution should be used where privileged access
386 to jails is given out to untrusted parties.
387 .It Va allow.chflags
388 Normally, privileged users inside a jail are treated as unprivileged by
389 .Xr chflags 2 .
390 When this parameter is set, such users are treated as privileged, and
391 may manipulate system file flags subject to the usual constraints on
392 .Va kern.securelevel .
393 .It Va allow.mount
394 privileged users inside the jail will be able to mount and unmount file
395 system types marked as jail-friendly.
396 The
397 .Xr lsvfs 1
398 command can be used to find file system types available for mount from
399 within a jail.
400 .It Va allow.quotas
401 The prison root may administer quotas on the jail's filesystem(s).
402 This includes filesystems that the jail may share with other jails or
403 with non-jailed parts of the system.
404 .It Va allow.socket_af
405 Sockets within a jail are normally restricted to IPv4, IPv6, local
406 (UNIX), and route.  This allows access to other protocol stacks that
407 have not had jail functionality added to them.
408 .El
409 .El
410 .Pp
411 Jails are typically set up using one of two philosophies: either to
412 constrain a specific application (possibly running with privilege), or
413 to create a
414 .Dq "virtual system image"
415 running a variety of daemons and services.
416 In both cases, a fairly complete file system install of
417 .Fx
418 is
419 required, so as to provide the necessary command line tools, daemons,
420 libraries, application configuration files, etc.
421 However, for a virtual server configuration, a fair amount of
422 additional work is required so as to configure the
423 .Dq boot
424 process.
425 This manual page documents the configuration steps necessary to support
426 either of these steps, although the configuration steps may be
427 refined based on local requirements.
428 .Sh EXAMPLES
429 .Ss "Setting up a Jail Directory Tree"
430 To set up a jail directory tree containing an entire
431 .Fx
432 distribution, the following
433 .Xr sh 1
434 command script can be used:
435 .Bd -literal
436 D=/here/is/the/jail
437 cd /usr/src
438 mkdir -p $D
439 make world DESTDIR=$D
440 make distribution DESTDIR=$D
441 mount -t devfs devfs $D/dev
442 .Ed
443 .Pp
444 NOTE: It is important that only appropriate device nodes in devfs be
445 exposed to a jail; access to disk devices in the jail may permit processes
446 in the jail to bypass the jail sandboxing by modifying files outside of
447 the jail.
448 See
449 .Xr devfs 8
450 for information on how to use devfs rules to limit access to entries
451 in the per-jail devfs.
452 A simple devfs ruleset for jails is available as ruleset #4 in
453 .Pa /etc/defaults/devfs.rules .
454 .Pp
455 In many cases this example would put far more in the jail than needed.
456 In the other extreme case a jail might contain only one file:
457 the executable to be run in the jail.
458 .Pp
459 We recommend experimentation and caution that it is a lot easier to
460 start with a
461 .Dq fat
462 jail and remove things until it stops working,
463 than it is to start with a
464 .Dq thin
465 jail and add things until it works.
466 .Ss "Setting Up a Jail"
467 Do what was described in
468 .Sx "Setting Up a Jail Directory Tree"
469 to build the jail directory tree.
470 For the sake of this example, we will
471 assume you built it in
472 .Pa /data/jail/192.0.2.100 ,
473 named for the jailed IP address.
474 Substitute below as needed with your
475 own directory, IP address, and hostname.
476 .Ss "Setting up the Host Environment"
477 First, you will want to set up your real system's environment to be
478 .Dq jail-friendly .
479 For consistency, we will refer to the parent box as the
480 .Dq "host environment" ,
481 and to the jailed virtual machine as the
482 .Dq "jail environment" .
483 Since jail is implemented using IP aliases, one of the first things to do
484 is to disable IP services on the host system that listen on all local
485 IP addresses for a service.
486 If a network service is present in the host environment that binds all
487 available IP addresses rather than specific IP addresses, it may service
488 requests sent to jail IP addresses if the jail did not bind the port.
489 This means changing
490 .Xr inetd 8
491 to only listen on the
492 appropriate IP address, and so forth.
493 Add the following to
494 .Pa /etc/rc.conf
495 in the host environment:
496 .Bd -literal -offset indent
497 sendmail_enable="NO"
498 inetd_flags="-wW -a 192.0.2.23"
499 rpcbind_enable="NO"
500 .Ed
501 .Pp
502 .Li 192.0.2.23
503 is the native IP address for the host system, in this example.
504 Daemons that run out of
505 .Xr inetd 8
506 can be easily set to use only the specified host IP address.
507 Other daemons
508 will need to be manually configured\(emfor some this is possible through
509 the
510 .Xr rc.conf 5
511 flags entries; for others it is necessary to modify per-application
512 configuration files, or to recompile the applications.
513 The following frequently deployed services must have their individual
514 configuration files modified to limit the application to listening
515 to a specific IP address:
516 .Pp
517 To configure
518 .Xr sshd 8 ,
519 it is necessary to modify
520 .Pa /etc/ssh/sshd_config .
521 .Pp
522 To configure
523 .Xr sendmail 8 ,
524 it is necessary to modify
525 .Pa /etc/mail/sendmail.cf .
526 .Pp
527 For
528 .Xr named 8 ,
529 it is necessary to modify
530 .Pa /etc/namedb/named.conf .
531 .Pp
532 In addition, a number of services must be recompiled in order to run
533 them in the host environment.
534 This includes most applications providing services using
535 .Xr rpc 3 ,
536 such as
537 .Xr rpcbind 8 ,
538 .Xr nfsd 8 ,
539 and
540 .Xr mountd 8 .
541 In general, applications for which it is not possible to specify which
542 IP address to bind should not be run in the host environment unless they
543 should also service requests sent to jail IP addresses.
544 Attempting to serve
545 NFS from the host environment may also cause confusion, and cannot be
546 easily reconfigured to use only specific IPs, as some NFS services are
547 hosted directly from the kernel.
548 Any third-party network software running
549 in the host environment should also be checked and configured so that it
550 does not bind all IP addresses, which would result in those services' also
551 appearing to be offered by the jail environments.
552 .Pp
553 Once
554 these daemons have been disabled or fixed in the host environment, it is
555 best to reboot so that all daemons are in a known state, to reduce the
556 potential for confusion later (such as finding that when you send mail
557 to a jail, and its sendmail is down, the mail is delivered to the host,
558 etc.).
559 .Ss "Configuring the Jail"
560 Start any jail for the first time without configuring the network
561 interface so that you can clean it up a little and set up accounts.
562 As
563 with any machine (virtual or not) you will need to set a root password, time
564 zone, etc.
565 Some of these steps apply only if you intend to run a full virtual server
566 inside the jail; others apply both for constraining a particular application
567 or for running a virtual server.
568 .Pp
569 Start a shell in the jail:
570 .Pp
571 .Bd -literal -offset indent
572 jail -c path=/data/jail/192.0.2.100 host.hostname=testhostname \\
573         ip4.addr=192.0.2.100 command=/bin/sh
574 .Ed
575 .Pp
576 Assuming no errors, you will end up with a shell prompt within the jail.
577 You can now run
578 .Pa /usr/sbin/sysinstall
579 and do the post-install configuration to set various configuration options,
580 or perform these actions manually by editing
581 .Pa /etc/rc.conf ,
582 etc.
583 .Pp
584 .Bl -bullet -offset indent -compact
585 .It
586 Create an empty
587 .Pa /etc/fstab
588 to quell startup warnings about missing fstab (virtual server only)
589 .It
590 Disable the port mapper
591 .Pa ( /etc/rc.conf :
592 .Li rpcbind_enable="NO" )
593 (virtual server only)
594 .It
595 Configure
596 .Pa /etc/resolv.conf
597 so that name resolution within the jail will work correctly
598 .It
599 Run
600 .Xr newaliases 1
601 to quell
602 .Xr sendmail 8
603 warnings.
604 .It
605 Disable interface configuration to quell startup warnings about
606 .Xr ifconfig 8
607 .Pq Li network_interfaces=""
608 (virtual server only)
609 .It
610 Set a root password, probably different from the real host system
611 .It
612 Set the timezone
613 .It
614 Add accounts for users in the jail environment
615 .It
616 Install any packages the environment requires
617 .El
618 .Pp
619 You may also want to perform any package-specific configuration (web servers,
620 SSH servers, etc), patch up
621 .Pa /etc/syslog.conf
622 so it logs as you would like, etc.
623 If you are not using a virtual server, you may wish to modify
624 .Xr syslogd 8
625 in the host environment to listen on the syslog socket in the jail
626 environment; in this example, the syslog socket would be stored in
627 .Pa /data/jail/192.0.2.100/var/run/log .
628 .Pp
629 Exit from the shell, and the jail will be shut down.
630 .Ss "Starting the Jail"
631 You are now ready to restart the jail and bring up the environment with
632 all of its daemons and other programs.
633 If you are running a single application in the jail, substitute the
634 command used to start the application for
635 .Pa /etc/rc
636 in the examples below.
637 To start a virtual server environment,
638 .Pa /etc/rc
639 is run to launch various daemons and services.
640 To do this, first bring up the
641 virtual host interface, and then start the jail's
642 .Pa /etc/rc
643 script from within the jail.
644 .Bd -literal -offset indent
645 ifconfig ed0 inet alias 192.0.2.100/32
646 mount -t procfs proc /data/jail/192.0.2.100/proc
647 jail -c path=/data/jail/192.0.2.100 host.hostname=testhostname \\
648         ip4.addr=192.0.2.100 command=/bin/sh /etc/rc
649 .Ed
650 .Pp
651 A few warnings will be produced, because most
652 .Xr sysctl 8
653 configuration variables cannot be set from within the jail, as they are
654 global across all jails and the host environment.
655 However, it should all
656 work properly.
657 You should be able to see
658 .Xr inetd 8 ,
659 .Xr syslogd 8 ,
660 and other processes running within the jail using
661 .Xr ps 1 ,
662 with the
663 .Ql J
664 flag appearing beside jailed processes.
665 To see an active list of jails, use the
666 .Xr jls 8
667 utility.
668 You should also be able to
669 .Xr telnet 1
670 to the hostname or IP address of the jailed environment, and log
671 in using the accounts you created previously.
672 .Pp
673 It is possible to have jails started at boot time.
674 Please refer to the
675 .Dq jail_*
676 variables in
677 .Xr rc.conf 5
678 for more information.
679 The
680 .Xr rc 8
681 jail script provides a flexible system to start/stop jails:
682 .Bd -literal
683 /etc/rc.d/jail start
684 /etc/rc.d/jail stop
685 /etc/rc.d/jail start myjail
686 /etc/rc.d/jail stop myjail
687 .Ed
688 .Ss "Managing the Jail"
689 Normal machine shutdown commands, such as
690 .Xr halt 8 ,
691 .Xr reboot 8 ,
692 and
693 .Xr shutdown 8 ,
694 cannot be used successfully within the jail.
695 To kill all processes in a
696 jail, you may log into the jail and, as root, use one of the following
697 commands, depending on what you want to accomplish:
698 .Pp
699 .Bd -literal -offset indent
700 kill -TERM -1
701 kill -KILL -1
702 .Ed
703 .Pp
704 This will send the
705 .Dv SIGTERM
706 or
707 .Dv SIGKILL
708 signals to all processes in the jail from within the jail.
709 Depending on
710 the intended use of the jail, you may also want to run
711 .Pa /etc/rc.shutdown
712 from within the jail.
713 To kill processes from outside the jail, use the
714 .Xr jexec 8
715 utility in conjunction with the one of the
716 .Xr kill 1
717 commands above.
718 You may also remove the jail with
719 .Nm
720 .Ar -r ,
721 which will killall the jail's processes with
722 .Dv SIGKILL .
723 .Pp
724 The
725 .Pa /proc/ Ns Ar pid Ns Pa /status
726 file contains, as its last field, the name of the jail in which the
727 process runs, or
728 .Dq Li -
729 to indicate that the process is not running within a jail.
730 The
731 .Xr ps 1
732 command also shows a
733 .Ql J
734 flag for processes in a jail.
735 .Pp
736 You can also list/kill processes based on their jail ID.
737 To show processes and their jail ID, use the following command:
738 .Pp
739 .Dl "ps ax -o pid,jid,args"
740 .Pp
741 To show and then kill processes in jail number 3 use the following commands:
742 .Bd -literal -offset indent
743 pgrep -lfj 3
744 pkill -j 3
745 .Ed
746 or:
747 .Pp
748 .Dl "killall -j 3"
749 .Ss "Jails and File Systems"
750 It is not possible to
751 .Xr mount 8
752 or
753 .Xr umount 8
754 any file system inside a jail unless the file system is marked
755 jail-friendly and the jail's
756 .Va allow.mount
757 parameter is set.
758 .Pp
759 Multiple jails sharing the same file system can influence each other.
760 For example a user in one jail can fill the file system also
761 leaving no space for processes in the other jail.
762 Trying to use
763 .Xr quota 1
764 to prevent this will not work either as the file system quotas
765 are not aware of jails but only look at the user and group IDs.
766 This means the same user ID in two jails share the same file
767 system quota.
768 One would need to use one file system per jail to make this work.
769 .Ss "Sysctl MIB Entries"
770 The read-only entry
771 .Va security.jail.jailed
772 can be used to determine if a process is running inside a jail (value
773 is one) or not (value is zero).
774 .Pp
775 The variable
776 .Va security.jail.max_af_ips
777 determines how may address per address family a prison may have.
778 The default is 255.
779 .Pp
780 Some MIB variables have per-jail settings.
781 Changes to these variables by a jailed process do not effect the host
782 environment, only the jail environment.
783 These variables are
784 .Va kern.securelevel ,
785 .Va kern.hostname ,
786 .Va kern.domainname ,
787 .Va kern.hostid ,
788 and
789 .Va kern.hostuuid .
790 .Ss "Hierarchical Jails"
791 By setting a jail's
792 .Va children.max
793 parameter, processes within a jail may be able to create jails of their own.
794 These child jails are kept in a hierarchy, with jails only able to see and/or
795 modify the jails they created (or those jails' children).
796 Each jail has a read-only
797 .Va parent
798 parameter, containing the
799 .Va jid
800 of the jail that created it; a
801 .Va jid
802 of 0 indicates the jail is a child of the current jail (or is a top-level
803 jail if the current process isn't jailed).
804 .Pp
805 Jailed processes are not allowed to confer greater permissions than they
806 themselves are given, e.g. if a jail is created with
807 .Va allow.nomount ,
808 it is not able to create a jail with
809 .Va allow.mount
810 set.
811 Similarly, such restrictions as
812 .Va ip4.addr
813 and
814 .Va securelevel
815 may not be bypassed in child jails.
816 .Pp
817 A child jail may in turn create its own child jails if its own
818 .Va children.max
819 parameter is set (remember it is zero by default).
820 These jails are visible to and can be modified by their parent and all
821 ancestors.
822 .Pp
823 Jail names reflect this hierarchy, with a full name being an MIB-type string
824 separated by dots.
825 For example, if a base system process creates a jail
826 .Dq foo ,
827 and a process under that jail creates another jail
828 .Dq bar ,
829 then the second jail will be seen as
830 .Dq foo.bar
831 in the base system (though it is only seen as
832 .Dq bar
833 to any processes inside jail
834 .Dq foo ) .
835 Jids on the other hand exist in a single space, and each jail must have a
836 unique jid.
837 .Pp
838 Like the names, a child jail's
839 .Va path
840 is relative to its creator's own
841 .Va path .
842 This is by virtue of the child jail being created in the chrooted
843 environment of the first jail.
844 .Sh SEE ALSO
845 .Xr killall 1 ,
846 .Xr lsvfs 1 ,
847 .Xr newaliases 1 ,
848 .Xr pgrep 1 ,
849 .Xr pkill 1 ,
850 .Xr ps 1 ,
851 .Xr quota 1 ,
852 .Xr chroot 2 ,
853 .Xr jail_set 2 ,
854 .Xr jail_attach 2 ,
855 .Xr procfs 5 ,
856 .Xr rc.conf 5 ,
857 .Xr sysctl.conf 5 ,
858 .Xr devfs 8 ,
859 .Xr halt 8 ,
860 .Xr inetd 8 ,
861 .Xr jexec 8 ,
862 .Xr jls 8 ,
863 .Xr mount 8 ,
864 .Xr named 8 ,
865 .Xr reboot 8 ,
866 .Xr rpcbind 8 ,
867 .Xr sendmail 8 ,
868 .Xr shutdown 8 ,
869 .Xr sysctl 8 ,
870 .Xr syslogd 8 ,
871 .Xr umount 8
872 .Sh HISTORY
873 The
874 .Nm
875 utility appeared in
876 .Fx 4.0 .
877 Hierarchical/extensible jails were introduced in
878 .Fx 8.0 .
879 .Sh AUTHORS
880 .An -nosplit
881 The jail feature was written by
882 .An Poul-Henning Kamp
883 for R&D Associates
884 .Pa http://www.rndassociates.com/
885 who contributed it to
886 .Fx .
887 .Pp
888 .An Robert Watson
889 wrote the extended documentation, found a few bugs, added
890 a few new features, and cleaned up the userland jail environment.
891 .Pp
892 .An Bjoern A. Zeeb
893 added multi-IP jail support for IPv4 and IPv6 based on a patch
894 originally done by
895 .An Pawel Jakub Dawidek
896 for IPv4.
897 .Pp
898 .An James Gritton
899 added the extensible jail parameters and hierchical jails.
900 .Sh BUGS
901 Jail currently lacks the ability to allow access to
902 specific jail information via
903 .Xr ps 1
904 as opposed to
905 .Xr procfs 5 .
906 Similarly, it might be a good idea to add an
907 address alias flag such that daemons listening on all IPs
908 .Pq Dv INADDR_ANY
909 will not bind on that address, which would facilitate building a safe
910 host environment such that host daemons do not impose on services offered
911 from within jails.
912 Currently, the simplest answer is to minimize services
913 offered on the host, possibly limiting it to services offered from
914 .Xr inetd 8
915 which is easily configurable.