]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - usr.sbin/jail/jail.8
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.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 July 25, 2009
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
256 Control the availablity of IPv4 addresses.
257 Possible values are
258 .Dq inherit
259 to allow unrestricted access to all system addresses,
260 .Dq new
261 to restrict addresses via
262 .Va ip4.addr
263 above, and
264 .Dq disable
265 to stop the jail from using IPv4 entirely.
266 Setting the
267 .Va ip4.addr
268 parameter implies a value of
269 .Dq new .
270 .It Va ip6.addr , Va ip6
271 A list of IPv6 addresses assigned to the prison, the counterpart to
272 .Va ip4.addr
273 and
274 .Va ip4
275 above.
276 .It Va host.hostname
277 Hostname of the prison.
278 Other similar parameters are
279 .Va host.domainname ,
280 .Va host.hostuuid
281 and
282 .Va host.hostid .
283 .It Va host
284 Set the origin of hostname and related information.
285 Possible values are
286 .Dq inherit
287 to use the system information and
288 .Dq new
289 for the jail to use the information from the above fields.
290 Setting any of the above fields implies a value of
291 .Dq new .
292 .It Va securelevel
293 The value of the jail's
294 .Va kern.securelevel
295 sysctl.
296 A jail never has a lower securelevel than the default system, but by
297 setting this parameter it may have a higher one.
298 If the system securelevel is changed, any jail securelevels will be at
299 least as secure.
300 .It Va children.max
301 The number of child jails allowed to be created by this jail (or by
302 other jails under this jail).
303 This limit is zero by default, indicating the jail is not allowed to
304 create child jails.
305 See the
306 .Va "Hierarchical Jails"
307 section for more information.
308 .It Va children.cur
309 The number of descendents of this jail, including its own child jails
310 and any jails created under them.
311 .It Va enforce_statfs
312 This determines which information processes in a jail are able to get
313 about mount points.
314 It affects the behaviour of the following syscalls:
315 .Xr statfs 2 ,
316 .Xr fstatfs 2 ,
317 .Xr getfsstat 2
318 and
319 .Xr fhstatfs 2
320 (as well as similar compatibility syscalls).
321 When set to 0, all mount points are available without any restrictions.
322 When set to 1, only mount points below the jail's chroot directory are
323 visible.
324 In addition to that, the path to the jail's chroot directory is removed
325 from the front of their pathnames.
326 When set to 2 (default), above syscalls can operate only on a mount-point
327 where the jail's chroot directory is located.
328 .It Va persist
329 Setting this boolean parameter allows a jail to exist without any
330 processes.
331 Normally, a jail is destroyed as its last process exits.
332 A new jail must have either the
333 .Va persist
334 parameter or
335 .Va command
336 pseudo-parameter set.
337 .It Va cpuset.id
338 The ID of the cpuset associated with this jail (read-only).
339 .It Va dying
340 This is true if the jail is in the process of shutting down (read-only).
341 .It Va parent
342 The
343 .Va jid
344 of the parent of this jail, or zero if this is a top-level jail
345 (read-only).
346 .It Va allow.*
347 Some restrictions of the jail environment may be set on a per-jail
348 basis.
349 With the exception of
350 .Va allow.set_hostname ,
351 these boolean parameters are off by default.
352 .Bl -tag -width indent
353 .It Va allow.set_hostname
354 The jail's hostname may be changed via
355 .Xr hostname 1
356 or
357 .Xr sethostname 3 .
358 .It Va allow.sysvipc
359 A process within the jail has access to System V IPC primitives.
360 In the current jail implementation, System V primitives share a single
361 namespace across the host and jail environments, meaning that processes
362 within a jail would be able to communicate with (and potentially interfere
363 with) processes outside of the jail, and in other jails.
364 .It Va allow.raw_sockets
365 The prison root is allowed to create raw sockets.
366 Setting this parameter allows utilities like
367 .Xr ping 8
368 and
369 .Xr traceroute 8
370 to operate inside the prison.
371 If this is set, the source IP addresses are enforced to comply
372 with the IP address bound to the jail, regardless of whether or not
373 the
374 .Dv IP_HDRINCL
375 flag has been set on the socket.
376 Since raw sockets can be used to configure and interact with various
377 network subsystems, extra caution should be used where privileged access
378 to jails is given out to untrusted parties.
379 .It Va allow.chflags
380 Normally, priveleged users inside a jail are treated as unprivileged by
381 .Xr chflags 2 .
382 When this parameter is set, such users are treated as privileged, and
383 may manipulate system file flags subject to the usual constraints on
384 .Va kern.securelevel .
385 .It Va allow.mount
386 privileged users inside the jail will be able to mount and unmount file
387 system types marked as jail-friendly.
388 The
389 .Xr lsvfs 1
390 command can be used to find file system types available for mount from
391 within a jail.
392 .It Va allow.quotas
393 The prison root may administer quotas on the jail's filesystem(s).
394 This includes filesystems that the jail may share with other jails or
395 with non-jailed parts of the system.
396 .It Va allow.socket_af
397 Sockets within a jail are normally restricted to IPv4, IPv6, local
398 (UNIX), and route.  This allows access to other protocol stacks that
399 have not had jail functionality added to them.
400 .El
401 .El
402 .Pp
403 Jails are typically set up using one of two philosophies: either to
404 constrain a specific application (possibly running with privilege), or
405 to create a
406 .Dq "virtual system image"
407 running a variety of daemons and services.
408 In both cases, a fairly complete file system install of
409 .Fx
410 is
411 required, so as to provide the necessary command line tools, daemons,
412 libraries, application configuration files, etc.
413 However, for a virtual server configuration, a fair amount of
414 additional work is required so as to configure the
415 .Dq boot
416 process.
417 This manual page documents the configuration steps necessary to support
418 either of these steps, although the configuration steps may be
419 refined based on local requirements.
420 .Sh EXAMPLES
421 .Ss "Setting up a Jail Directory Tree"
422 To set up a jail directory tree containing an entire
423 .Fx
424 distribution, the following
425 .Xr sh 1
426 command script can be used:
427 .Bd -literal
428 D=/here/is/the/jail
429 cd /usr/src
430 mkdir -p $D
431 make world DESTDIR=$D
432 make distribution DESTDIR=$D
433 mount -t devfs devfs $D/dev
434 .Ed
435 .Pp
436 NOTE: It is important that only appropriate device nodes in devfs be
437 exposed to a jail; access to disk devices in the jail may permit processes
438 in the jail to bypass the jail sandboxing by modifying files outside of
439 the jail.
440 See
441 .Xr devfs 8
442 for information on how to use devfs rules to limit access to entries
443 in the per-jail devfs.
444 A simple devfs ruleset for jails is available as ruleset #4 in
445 .Pa /etc/defaults/devfs.rules .
446 .Pp
447 In many cases this example would put far more in the jail than needed.
448 In the other extreme case a jail might contain only one file:
449 the executable to be run in the jail.
450 .Pp
451 We recommend experimentation and caution that it is a lot easier to
452 start with a
453 .Dq fat
454 jail and remove things until it stops working,
455 than it is to start with a
456 .Dq thin
457 jail and add things until it works.
458 .Ss "Setting Up a Jail"
459 Do what was described in
460 .Sx "Setting Up a Jail Directory Tree"
461 to build the jail directory tree.
462 For the sake of this example, we will
463 assume you built it in
464 .Pa /data/jail/192.0.2.100 ,
465 named for the jailed IP address.
466 Substitute below as needed with your
467 own directory, IP address, and hostname.
468 .Ss "Setting up the Host Environment"
469 First, you will want to set up your real system's environment to be
470 .Dq jail-friendly .
471 For consistency, we will refer to the parent box as the
472 .Dq "host environment" ,
473 and to the jailed virtual machine as the
474 .Dq "jail environment" .
475 Since jail is implemented using IP aliases, one of the first things to do
476 is to disable IP services on the host system that listen on all local
477 IP addresses for a service.
478 If a network service is present in the host environment that binds all
479 available IP addresses rather than specific IP addresses, it may service
480 requests sent to jail IP addresses if the jail did not bind the port.
481 This means changing
482 .Xr inetd 8
483 to only listen on the
484 appropriate IP address, and so forth.
485 Add the following to
486 .Pa /etc/rc.conf
487 in the host environment:
488 .Bd -literal -offset indent
489 sendmail_enable="NO"
490 inetd_flags="-wW -a 192.0.2.23"
491 rpcbind_enable="NO"
492 .Ed
493 .Pp
494 .Li 192.0.2.23
495 is the native IP address for the host system, in this example.
496 Daemons that run out of
497 .Xr inetd 8
498 can be easily set to use only the specified host IP address.
499 Other daemons
500 will need to be manually configured\(emfor some this is possible through
501 the
502 .Xr rc.conf 5
503 flags entries; for others it is necessary to modify per-application
504 configuration files, or to recompile the applications.
505 The following frequently deployed services must have their individual
506 configuration files modified to limit the application to listening
507 to a specific IP address:
508 .Pp
509 To configure
510 .Xr sshd 8 ,
511 it is necessary to modify
512 .Pa /etc/ssh/sshd_config .
513 .Pp
514 To configure
515 .Xr sendmail 8 ,
516 it is necessary to modify
517 .Pa /etc/mail/sendmail.cf .
518 .Pp
519 For
520 .Xr named 8 ,
521 it is necessary to modify
522 .Pa /etc/namedb/named.conf .
523 .Pp
524 In addition, a number of services must be recompiled in order to run
525 them in the host environment.
526 This includes most applications providing services using
527 .Xr rpc 3 ,
528 such as
529 .Xr rpcbind 8 ,
530 .Xr nfsd 8 ,
531 and
532 .Xr mountd 8 .
533 In general, applications for which it is not possible to specify which
534 IP address to bind should not be run in the host environment unless they
535 should also service requests sent to jail IP addresses.
536 Attempting to serve
537 NFS from the host environment may also cause confusion, and cannot be
538 easily reconfigured to use only specific IPs, as some NFS services are
539 hosted directly from the kernel.
540 Any third-party network software running
541 in the host environment should also be checked and configured so that it
542 does not bind all IP addresses, which would result in those services' also
543 appearing to be offered by the jail environments.
544 .Pp
545 Once
546 these daemons have been disabled or fixed in the host environment, it is
547 best to reboot so that all daemons are in a known state, to reduce the
548 potential for confusion later (such as finding that when you send mail
549 to a jail, and its sendmail is down, the mail is delivered to the host,
550 etc.).
551 .Ss "Configuring the Jail"
552 Start any jail for the first time without configuring the network
553 interface so that you can clean it up a little and set up accounts.
554 As
555 with any machine (virtual or not) you will need to set a root password, time
556 zone, etc.
557 Some of these steps apply only if you intend to run a full virtual server
558 inside the jail; others apply both for constraining a particular application
559 or for running a virtual server.
560 .Pp
561 Start a shell in the jail:
562 .Pp
563 .Bd -literal -offset indent
564 jail path=/data/jail/192.0.2.100 host.hostname=testhostname \\
565         ip4.addr=192.0.2.100 command=/bin/sh
566 .Ed
567 .Pp
568 Assuming no errors, you will end up with a shell prompt within the jail.
569 You can now run
570 .Pa /usr/sbin/sysinstall
571 and do the post-install configuration to set various configuration options,
572 or perform these actions manually by editing
573 .Pa /etc/rc.conf ,
574 etc.
575 .Pp
576 .Bl -bullet -offset indent -compact
577 .It
578 Create an empty
579 .Pa /etc/fstab
580 to quell startup warnings about missing fstab (virtual server only)
581 .It
582 Disable the port mapper
583 .Pa ( /etc/rc.conf :
584 .Li rpcbind_enable="NO" )
585 (virtual server only)
586 .It
587 Configure
588 .Pa /etc/resolv.conf
589 so that name resolution within the jail will work correctly
590 .It
591 Run
592 .Xr newaliases 1
593 to quell
594 .Xr sendmail 8
595 warnings.
596 .It
597 Disable interface configuration to quell startup warnings about
598 .Xr ifconfig 8
599 .Pq Li network_interfaces=""
600 (virtual server only)
601 .It
602 Set a root password, probably different from the real host system
603 .It
604 Set the timezone
605 .It
606 Add accounts for users in the jail environment
607 .It
608 Install any packages the environment requires
609 .El
610 .Pp
611 You may also want to perform any package-specific configuration (web servers,
612 SSH servers, etc), patch up
613 .Pa /etc/syslog.conf
614 so it logs as you would like, etc.
615 If you are not using a virtual server, you may wish to modify
616 .Xr syslogd 8
617 in the host environment to listen on the syslog socket in the jail
618 environment; in this example, the syslog socket would be stored in
619 .Pa /data/jail/192.0.2.100/var/run/log .
620 .Pp
621 Exit from the shell, and the jail will be shut down.
622 .Ss "Starting the Jail"
623 You are now ready to restart the jail and bring up the environment with
624 all of its daemons and other programs.
625 If you are running a single application in the jail, substitute the
626 command used to start the application for
627 .Pa /etc/rc
628 in the examples below.
629 To start a virtual server environment,
630 .Pa /etc/rc
631 is run to launch various daemons and services.
632 To do this, first bring up the
633 virtual host interface, and then start the jail's
634 .Pa /etc/rc
635 script from within the jail.
636 .Bd -literal -offset indent
637 ifconfig ed0 inet alias 192.0.2.100/32
638 mount -t procfs proc /data/jail/192.0.2.100/proc
639 jail path=/data/jail/192.0.2.100 host.hostname=testhostname \\
640         ip4.addr=192.0.2.100 command=/bin/sh /etc/rc
641 .Ed
642 .Pp
643 A few warnings will be produced, because most
644 .Xr sysctl 8
645 configuration variables cannot be set from within the jail, as they are
646 global across all jails and the host environment.
647 However, it should all
648 work properly.
649 You should be able to see
650 .Xr inetd 8 ,
651 .Xr syslogd 8 ,
652 and other processes running within the jail using
653 .Xr ps 1 ,
654 with the
655 .Ql J
656 flag appearing beside jailed processes.
657 To see an active list of jails, use the
658 .Xr jls 8
659 utility.
660 You should also be able to
661 .Xr telnet 1
662 to the hostname or IP address of the jailed environment, and log
663 in using the accounts you created previously.
664 .Pp
665 It is possible to have jails started at boot time.
666 Please refer to the
667 .Dq jail_*
668 variables in
669 .Xr rc.conf 5
670 for more information.
671 The
672 .Xr rc 8
673 jail script provides a flexible system to start/stop jails:
674 .Bd -literal
675 /etc/rc.d/jail start
676 /etc/rc.d/jail stop
677 /etc/rc.d/jail start myjail
678 /etc/rc.d/jail stop myjail
679 .Ed
680 .Ss "Managing the Jail"
681 Normal machine shutdown commands, such as
682 .Xr halt 8 ,
683 .Xr reboot 8 ,
684 and
685 .Xr shutdown 8 ,
686 cannot be used successfully within the jail.
687 To kill all processes in a
688 jail, you may log into the jail and, as root, use one of the following
689 commands, depending on what you want to accomplish:
690 .Pp
691 .Bd -literal -offset indent
692 kill -TERM -1
693 kill -KILL -1
694 .Ed
695 .Pp
696 This will send the
697 .Dv SIGTERM
698 or
699 .Dv SIGKILL
700 signals to all processes in the jail from within the jail.
701 Depending on
702 the intended use of the jail, you may also want to run
703 .Pa /etc/rc.shutdown
704 from within the jail.
705 To kill processes from outside the jail, use the
706 .Xr jexec 8
707 utility in conjunction with the one of the
708 .Xr kill 1
709 commands above.
710 You may also remove the jail with
711 .Nm
712 .Ar -r ,
713 which will killall the jail's processes with
714 .Dv SIGKILL .
715 .Pp
716 The
717 .Pa /proc/ Ns Ar pid Ns Pa /status
718 file contains, as its last field, the name of the jail in which the
719 process runs, or
720 .Dq Li -
721 to indicate that the process is not running within a jail.
722 The
723 .Xr ps 1
724 command also shows a
725 .Ql J
726 flag for processes in a jail.
727 .Pp
728 You can also list/kill processes based on their jail ID.
729 To show processes and their jail ID, use the following command:
730 .Pp
731 .Dl "ps ax -o pid,jid,args"
732 .Pp
733 To show and then kill processes in jail number 3 use the following commands:
734 .Bd -literal -offset indent
735 pgrep -lfj 3
736 pkill -j 3
737 .Ed
738 or:
739 .Pp
740 .Dl "killall -j 3"
741 .Ss "Jails and File Systems"
742 It is not possible to
743 .Xr mount 8
744 or
745 .Xr umount 8
746 any file system inside a jail unless the file system is marked
747 jail-friendly and the jail's
748 .Va allow.mount
749 parameter is set.
750 .Pp
751 Multiple jails sharing the same file system can influence each other.
752 For example a user in one jail can fill the file system also
753 leaving no space for processes in the other jail.
754 Trying to use
755 .Xr quota 1
756 to prevent this will not work either as the file system quotas
757 are not aware of jails but only look at the user and group IDs.
758 This means the same user ID in two jails share the same file
759 system quota.
760 One would need to use one file system per jail to make this work.
761 .Ss "Sysctl MIB Entries"
762 The read-only entry
763 .Va security.jail.jailed
764 can be used to determine if a process is running inside a jail (value
765 is one) or not (value is zero).
766 .Pp
767 The variable
768 .Va security.jail.max_af_ips
769 determines how may address per address family a prison may have.
770 The default is 255.
771 .Pp
772 Some MIB variables have per-jail settings.
773 Changes to these variables by a jailed process do not effect the host
774 environment, only the jail environment.
775 These variables are
776 .Va kern.securelevel ,
777 .Va kern.hostname ,
778 .Va kern.domainname ,
779 .Va kern.hostid ,
780 and
781 .Va kern.hostuuid .
782 .Ss "Hierarchical Jails"
783 By setting a jail's
784 .Va children.max
785 parameter, processes within a jail may be able to create jails of their own.
786 These child jails are kept in a hierarchy, with jails only able to see and/or
787 modify the jails they created (or those jails' children).
788 Each jail has a read-only
789 .Va parent
790 parameter, containing the
791 .Va jid
792 of the jail that created it; a
793 .Va jid
794 of 0 indicates the jail is a child of the current jail (or is a top-level
795 jail if the current process isn't jailed).
796 .Pp
797 Jailed processes are not allowed to confer greater permissions than they
798 themselves are given, e.g. if a jail is created with
799 .Va allow.nomount ,
800 it is not able to create a jail with
801 .Va allow.mount
802 set.
803 Similarly, such restrictions as
804 .Va ip4.addr
805 and
806 .Va securelevel
807 may not be bypassed in child jails.
808 .Pp
809 A child jail may in turn create its own child jails if its own
810 .Va children.max
811 parameter is set (remember it is zero by default).
812 These jails are visible to and can be modified by their parent and all
813 ancestors.
814 .Pp
815 Jail names reflect this hierarchy, with a full name being an MIB-type string
816 separated by dots.
817 For example, if a base system process creates a jail
818 .Dq foo ,
819 and a process under that jail creates another jail
820 .Dq bar ,
821 then the second jail will be seen as
822 .Dq foo.bar
823 in the base system (though it is only seen as
824 .Dq bar
825 to any processes inside jail
826 .Dq foo ) .
827 Jids on the other hand exist in a single space, and each jail must have a
828 unique jid.
829 .Pp
830 Like the names, a child jail's
831 .Va path
832 is relative to its creator's own
833 .Va path .
834 This is by virtue of the child jail being created in the chrooted
835 environment of the first jail.
836 .Sh SEE ALSO
837 .Xr killall 1 ,
838 .Xr lsvfs 1 ,
839 .Xr newaliases 1 ,
840 .Xr pgrep 1 ,
841 .Xr pkill 1 ,
842 .Xr ps 1 ,
843 .Xr quota 1 ,
844 .Xr chroot 2 ,
845 .Xr jail_set 2 ,
846 .Xr jail_attach 2 ,
847 .Xr procfs 5 ,
848 .Xr rc.conf 5 ,
849 .Xr sysctl.conf 5 ,
850 .Xr devfs 8 ,
851 .Xr halt 8 ,
852 .Xr inetd 8 ,
853 .Xr jexec 8 ,
854 .Xr jls 8 ,
855 .Xr mount 8 ,
856 .Xr named 8 ,
857 .Xr reboot 8 ,
858 .Xr rpcbind 8 ,
859 .Xr sendmail 8 ,
860 .Xr shutdown 8 ,
861 .Xr sysctl 8 ,
862 .Xr syslogd 8 ,
863 .Xr umount 8
864 .Sh HISTORY
865 The
866 .Nm
867 utility appeared in
868 .Fx 4.0 .
869 Hierarchical/extensible jails were introduced in
870 .Fx 8.0 .
871 .Sh AUTHORS
872 .An -nosplit
873 The jail feature was written by
874 .An Poul-Henning Kamp
875 for R&D Associates
876 .Pa http://www.rndassociates.com/
877 who contributed it to
878 .Fx .
879 .Pp
880 .An Robert Watson
881 wrote the extended documentation, found a few bugs, added
882 a few new features, and cleaned up the userland jail environment.
883 .Pp
884 .An Bjoern A. Zeeb
885 added multi-IP jail support for IPv4 and IPv6 based on a patch
886 originally done by
887 .An Pawel Jakub Dawidek
888 for IPv4.
889 .Pp
890 .An James Gritton
891 added the extensible jail parameters and hierchical jails.
892 .Sh BUGS
893 Jail currently lacks the ability to allow access to
894 specific jail information via
895 .Xr ps 1
896 as opposed to
897 .Xr procfs 5 .
898 Similarly, it might be a good idea to add an
899 address alias flag such that daemons listening on all IPs
900 .Pq Dv INADDR_ANY
901 will not bind on that address, which would facilitate building a safe
902 host environment such that host daemons do not impose on services offered
903 from within jails.
904 Currently, the simplest answer is to minimize services
905 offered on the host, possibly limiting it to services offered from
906 .Xr inetd 8
907 which is easily configurable.