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