2 .\" Copyright (c) 2000 Robert N. M. Watson
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" ----------------------------------------------------------------------------
28 .\" "THE BEER-WARE LICENSE" (Revision 42):
29 .\" <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
30 .\" can do whatever you want with this stuff. If we meet some day, and you think
31 .\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
32 .\" ----------------------------------------------------------------------------
40 .Nd "imprison process and its descendants"
44 .Op Fl l u Ar username | Fl U Ar username
45 .Ar path hostname ip-list command ...
49 command imprisons a process and all future descendants.
51 The options are as follows:
52 .Bl -tag -width ".Fl u Ar username"
54 Output the jail identifier of the newly created jail.
56 Run program in the clean environment.
57 The environment is discarded except for
58 .Ev HOME , SHELL , TERM
64 are set to the target login's default values.
66 is set to the target login.
68 is imported from the current environment.
69 The environment variables from the login class capability database for the
70 target login are also set.
72 The user name as whom the
76 The user name from jailed environment as whom the
80 Directory which is to be the root of the prison.
82 Hostname of the prison.
84 Comma separated IP list assigned to the prison.
86 Pathname of the program which is to be executed.
91 man page for further details.
93 .Ss "Setting Up a Jail Directory Tree"
94 This example shows how to setup a jail directory tree
97 distribution, provided that you built world before already:
102 make installworld DESTDIR=$D
104 make distribution DESTDIR=$D
106 ln -sf dev/null boot/kernel
109 In many cases this example would put far more stuff in the jail than is needed.
110 In the other extreme case a jail might contain only one single file:
111 the executable to be run in the jail.
113 We recommend experimentation and caution that it is a lot easier to
116 jail and remove things until it stops working,
117 than it is to start with a
119 jail and add things until it works.
120 .Ss "Setting Up a Jail"
121 Do what was described in
122 .Sx "Setting Up a Jail Directory Tree"
123 to build the jail directory tree.
124 For the sake of this example, we will
125 assume you built it in
126 .Pa /data/jail/192.168.11.100 ,
127 named for the external jail IP address.
128 Substitute below as needed with your
129 own directory, IP addresses, and hostname.
131 First, you will want to set up your real system's environment to be
133 For consistency, we will refer to the parent box as the
134 .Dq "host environment" ,
135 and to the jailed virtual machine as the
136 .Dq "jail environment" .
137 Because jail is implemented using IP aliases, one of the first things to do
138 is to disable IP services on the host system that listen on all local
139 IP addresses for a service.
142 to only listen on the
143 appropriate IP address, and so forth.
146 in the host environment:
147 .Bd -literal -offset indent
149 inetd_flags="-wW -a 192.168.11.23"
154 is the native IP address for the host system, in this example.
155 Daemons that run out of
157 can be easily set to use only the specified host IP address.
159 will need to be manually configured\(emfor some this is possible through
162 flags entries, for others it is not possible without munging
163 the per-application configuration files, or even recompiling.
165 applications that cannot specify the IP they run on, it is better to disable
168 A number of daemons ship with the base system that may have problems when
169 run from outside of a jail in a jail-centric environment.
179 can be configured to listen only on a specific
180 IP using their configuration files, in most cases it is easier to simply
181 run the daemons in jails only, and not in the host environment.
183 NFS from the host environment may also cause confusion, and cannot be
184 easily reconfigured to use only specific IPs, as some NFS services are
185 hosted directly from the kernel.
186 Any third party network software running
187 in the host environment should also be checked and configured so that it
188 does not bind all IP addresses, which would result in those services also
189 appearing to be offered by the jail environments.
192 these daemons have been disabled or fixed in the host environment, it is
193 best to reboot so that all daemons are in a known state, to reduce the
194 potential for confusion later (such as finding that when you send mail
195 to a jail, and its sendmail is down, the mail is delivered to the host,
198 Start any jails for the first time without configuring the network
199 interface so that you can clean it up a little and set up accounts.
201 with any machine (virtual or not) you will need to set a root password, time
206 .Dl "jail /data/jail/192.168.11.100 testhostname 127.0.0.1,192.168.11.100 /bin/sh"
208 You will end up with a shell prompt, assuming no errors, within the jail.
209 You can now do the post-install configuration to set various configuration
214 .Bl -bullet -offset indent -compact
216 Disable the port mapper
218 .Li rpcbind_enable="NO" )
226 Disable interface configuration to quell startup warnings about
228 .Pq Li network_interfaces=""
232 so that name resolution within the jail will work correctly
234 Set a root password, probably different from the real host system
236 Set the timezone with
239 Add accounts for users in the jail environment
241 Install any packages that you think the environment requires
244 You may also want to perform any package-specific configuration (web servers,
245 SSH servers, etc), patch up
247 so it logs as you would like, etc.
249 Exit from the shell, and the jail will be shut down.
250 .Ss "Starting the Jail"
251 You are now ready to restart the jail and bring up the environment with
252 all of its daemons and other programs.
253 To do this, first bring up the
254 virtual host interface, and then start the jail's
256 script from within the jail.
258 NOTE: If you plan to allow untrusted users to have root access inside the
259 jail, you may wish to consider setting the
260 .Va jail.defaults.set_hostname_allowed
262 Please see the management reasons why this is a good idea.
263 If you do decide to set this variable,
264 it must be set before starting any jails, and once each boot.
265 .Bd -literal -offset indent
266 ifconfig ed0 inet alias 192.168.11.100/32
267 mount -t procfs proc /data/jail/192.168.11.100/proc
268 jail /data/jail/192.168.11.100 testhostname 127.0.0.1,192.168.11.100 \\
272 A few warnings will be produced, because most
274 configuration variables cannot be set from within the jail, as they are
275 global across all jails and the host environment.
276 However, it should all
278 You should be able to see
281 and other processes running within the jail using
285 flag appearing beside jailed processes.
286 You should also be able to
288 to the hostname or IP address of the jailed environment, and log
289 in using the accounts you created previously.
290 .Ss "Managing the Jail"
291 Normal machine shutdown commands, such as
296 cannot be used successfully within the jail.
297 To kill all processes in a
298 jail, you may log into the jail and, as root, use one of the following
299 commands, depending on what you want to accomplish:
300 .Bd -literal -offset indent
309 signals to all processes in the jail from within the jail.
311 the intended use of the jail, you may also want to run
313 from within the jail.
314 Currently there is no way to insert new processes
315 into a jail, so you must first log into the jail before performing these
318 To kill processes from outside the jail, you must individually identify the
319 PID of each process to be killed.
321 .Pa /proc/ Ns Ar pid Ns Pa /status
322 file contains, as its last field, the hostname of the jail in which the
325 to indicate that the process is not running within a jail.
330 flag for processes in a jail.
331 However, the hostname for a jail may be, by
332 default, modified from within the jail, so the
334 status entry is unreliable by default.
335 To disable the setting of the hostname
336 from within a jail, set the
337 .Va jail.set_hostname_allowed
338 sysctl variable in the host environment to 0, which will affect all jails.
339 You can have this sysctl set on each boot using
341 Just add the following line to
342 .Pa /etc/sysctl.conf :
344 .Dl jail.defaults.set_hostname_allowed=0
346 In a future version of
348 the mechanisms for managing jails may be
350 .Ss "Sysctl MIB Entries"
351 Certain aspects of the jail containments environment may be modified from
352 the host environment using
355 For each jail there will be the same set of MIB variables as shown below but
358 which allows control of every jail individually.
359 The values of the variables under
361 will be copied to the per-jail MIB variables upon creation thus serving as
362 a kind of system-wide template.
364 .It Va jail.defaults.allow_raw_sockets
365 This MIB entry determines whether or not prison root is allowed to
367 Setting this MIB to 1 allows utilities like
371 to operate inside the prison.
372 If this MIB is set, the source IP addresses are enforced to comply
373 with the IP address bound to the jail, regardless of whether or not the
375 flag has been set on the socket. Because raw sockets can be used to configure
376 and interact with various network subsystems, extra caution should be used
377 where privileged access to jails is given out to untrusted parties.
378 As such, this option is disabled by default.
379 .It Va jail.defaults.chflags_allowed
380 This MIB entry determines how a privileged user inside a jail will be
383 If zero, such users are treated as unprivileged, and are unable to set
384 or clear system file flags; if non-zero, such users are treated as
385 privileged, and may manipulate system file flags subject to the usual
387 .Va kern.securelevel .
389 This read-only MIB entry can be used to determine if a process is running
390 inside a jail (value is 1) or not (value is 0).
391 .It Va jail.defaults.set_hostname_allowed
392 This MIB entry determines whether or not processes within a jail are
393 allowed to change their hostname via
397 In the current jail implementation, the ability to set the hostname from
398 within the jail can impact management tools relying on the accuracy of jail
401 As such, this should be disabled in environments where privileged access to
402 jails is given out to untrusted parties.
403 .It Va jail.defaults.socket_unixiproute_only
404 The jail functionality binds IPv4 and IPv6 addresses to each jail, and limits
405 access to other network addresses in the IPv4 and IPv6 space that may be available
406 in the host environment.
407 However, jail is not currently able to limit access to other network
408 protocol stacks that have not had jail functionality added to them.
409 As such, by default, processes within jails may only access protocols
410 in the following domains:
411 .Dv PF_LOCAL , PF_INET , PF_INET6 ,
414 permitting them access to
417 IPv4 and IPv6 addresses, and routing sockets.
418 To enable access to other domains, this MIB variable may be set to 0.
419 .It Va jail.defaults.sysvipc_allowed
420 This MIB entry determines whether or not processes within a jail have access
421 to System V IPC primitives.
422 In the current jail implementation, System V primitives share a single
423 namespace across the host and jail environments, meaning that processes
424 within a jail would be able to communicate with (and potentially interfere
425 with) processes outside of the jail, and in other jails.
426 As such, this functionality is disabled by default, but can be enabled
427 by setting this MIB entry to 1.
454 Support for multiple IPs and IPv6 appeared in
459 The jail feature was written by
460 .An Poul-Henning Kamp
462 .Pa http://www.rndassociates.com/
463 who contributed it to
467 wrote the extended documentation, found a few bugs, added
468 a few new features, and cleaned up the userland jail environment.
470 .An Victor Balada Diaz
471 wrote the support for multiple IPs and IPv6. Multiple IPs support
472 is based on work done by
473 .An Pawel Jakub Dawidek .
475 Jail currently lacks strong management functionality, such as the ability
476 to deliver signals to all processes in a jail, and to allow access to
477 specific jail information via
481 Similarly, it might be a good idea to add an
482 address alias flag such that daemons listening on all IPs
484 will not bind on that address, which would facilitate building a safe
485 host environment such that host daemons do not impose on services offered
487 Currently, the simplist answer is to minimize services
488 offered on the host, possibly limiting it to services offered from
490 which is easily configurable.