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