| Commit | Line | Data |
|---|---|---|
| 984263bc MD |
1 | .\" |
| 2 | .\" Copyright (c) 2000 Robert N. M. Watson | |
| 3 | .\" All rights reserved. | |
| 4 | .\" | |
| 5 | .\" Redistribution and use in source and binary forms, with or without | |
| 6 | .\" modification, are permitted provided that the following conditions | |
| 7 | .\" are met: | |
| 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. | |
| 13 | .\" | |
| 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 | |
| 24 | .\" SUCH DAMAGE. | |
| 25 | .\" | |
| 26 | .\" | |
| 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 | .\" ---------------------------------------------------------------------------- | |
| 33 | .\" | |
| 34 | .\" $FreeBSD: src/usr.sbin/jail/jail.8,v 1.13.2.15 2003/05/08 13:04:24 maxim Exp $ | |
| 8a7bdfea | 35 | .\" $DragonFly: src/usr.sbin/jail/jail.8,v 1.11 2008/05/02 02:05:07 swildner Exp $ |
| 984263bc MD |
36 | .\" |
| 37 | .Dd December 12, 2001 | |
| 38 | .Dt JAIL 8 | |
| 39 | .Os | |
| 40 | .Sh NAME | |
| 41 | .Nm jail | |
| 42 | .Nd "imprison process and its descendants" | |
| 43 | .Sh SYNOPSIS | |
| 44 | .Nm | |
| 61deed49 | 45 | .Op Fl i |
| e8e3f0ad | 46 | .Op Fl l u Ar username | Fl U Ar username |
| 3e4150ef | 47 | .Ar path hostname ip-list command ... |
| 984263bc MD |
48 | .Sh DESCRIPTION |
| 49 | The | |
| 50 | .Nm | |
| 51 | command imprisons a process and all future descendants. | |
| 52 | .Pp | |
| 53 | The options are as follows: | |
| 54 | .Bl -tag -width ".Fl u Ar username" | |
| 61deed49 | 55 | .It Fl i |
| 3f5e28f4 | 56 | Output the jail identifier of the newly created jail. |
| e8e3f0ad VBD |
57 | .It Fl l |
| 58 | Run program in the clean environment. | |
| 59 | The environment is discarded except for | |
| 60 | .Ev HOME , SHELL , TERM | |
| 61 | and | |
| 62 | .Ev USER . | |
| 63 | .Ev HOME | |
| 64 | and | |
| 65 | .Ev SHELL | |
| 66 | are set to the target login's default values. | |
| 67 | .Ev USER | |
| 68 | is set to the target login. | |
| 69 | .Ev TERM | |
| 70 | is imported from the current environment. | |
| 71 | The environment variables from the login class capability database for the | |
| 72 | target login are also set. | |
| 984263bc MD |
73 | .It Fl u Ar username |
| 74 | The user name as whom the | |
| 75 | .Ar command | |
| 76 | should run. | |
| e8e3f0ad VBD |
77 | .It Fl U Ar username |
| 78 | The user name from jailed environment as whom the | |
| 0474a71e | 79 | .Ar command |
| e8e3f0ad | 80 | should run. |
| 984263bc MD |
81 | .It Ar path |
| 82 | Directory which is to be the root of the prison. | |
| 83 | .It Ar hostname | |
| 84 | Hostname of the prison. | |
| 3e4150ef VBD |
85 | .It Ar ip-list |
| 86 | Comma separated IP list assigned to the prison. | |
| 984263bc MD |
87 | .It Ar command |
| 88 | Pathname of the program which is to be executed. | |
| 89 | .El | |
| 90 | .Pp | |
| 91 | Please see the | |
| 92 | .Xr jail 2 | |
| 93 | man page for further details. | |
| 94 | .Sh EXAMPLES | |
| 95 | .Ss "Setting up a Jail Directory Tree" | |
| 96 | This example shows how to setup a jail directory tree | |
| 97 | containing an entire | |
| 9bb2a92d | 98 | .Dx |
| 5c1ee908 | 99 | distribution, provided that you built world before already: |
| 984263bc MD |
100 | .Bd -literal |
| 101 | D=/here/is/the/jail | |
| 102 | cd /usr/src | |
| 103 | mkdir -p $D | |
| 5c1ee908 | 104 | make installworld DESTDIR=$D |
| 984263bc MD |
105 | cd etc |
| 106 | make distribution DESTDIR=$D -DNO_MAKEDEV_RUN | |
| 107 | cd $D/dev | |
| 108 | sh MAKEDEV jail | |
| 109 | cd $D | |
| 110 | ln -sf dev/null kernel | |
| 111 | .Ed | |
| 112 | .Pp | |
| 113 | In many cases this example would put far more stuff in the jail than is needed. | |
| 114 | In the other extreme case a jail might contain only one single file: | |
| 115 | the executable to be run in the jail. | |
| 116 | .Pp | |
| 117 | We recommend experimentation and caution that it is a lot easier to | |
| 118 | start with a | |
| 119 | .Dq fat | |
| 120 | jail and remove things until it stops working, | |
| 121 | than it is to start with a | |
| 122 | .Dq thin | |
| 123 | jail and add things until it works. | |
| 124 | .Ss "Setting Up a Jail" | |
| 125 | Do what was described in | |
| 126 | .Sx "Setting Up a Jail Directory Tree" | |
| 127 | to build the jail directory tree. | |
| 128 | For the sake of this example, we will | |
| 129 | assume you built it in | |
| 130 | .Pa /data/jail/192.168.11.100 , | |
| 3e4150ef | 131 | named for the external jail IP address. |
| 984263bc | 132 | Substitute below as needed with your |
| 3e4150ef | 133 | own directory, IP addresses, and hostname. |
| 984263bc MD |
134 | .Pp |
| 135 | First, you will want to set up your real system's environment to be | |
| 136 | .Dq jail-friendly . | |
| 137 | For consistency, we will refer to the parent box as the | |
| 138 | .Dq "host environment" , | |
| 139 | and to the jailed virtual machine as the | |
| 140 | .Dq "jail environment" . | |
| 141 | Because jail is implemented using IP aliases, one of the first things to do | |
| 142 | is to disable IP services on the host system that listen on all local | |
| 143 | IP addresses for a service. | |
| 144 | This means changing | |
| 145 | .Xr inetd 8 | |
| 146 | to only listen on the | |
| 147 | appropriate IP address, and so forth. | |
| 148 | Add the following to | |
| 149 | .Pa /etc/rc.conf | |
| 150 | in the host environment: | |
| 151 | .Bd -literal -offset indent | |
| 152 | sendmail_enable="NO" | |
| 153 | inetd_flags="-wW -a 192.168.11.23" | |
| 3b813696 | 154 | rpcbind_enable="NO" |
| 984263bc MD |
155 | .Ed |
| 156 | .Pp | |
| 157 | .Li 192.168.11.23 | |
| 158 | is the native IP address for the host system, in this example. | |
| 159 | Daemons that run out of | |
| 160 | .Xr inetd 8 | |
| 161 | can be easily set to use only the specified host IP address. | |
| 162 | Other daemons | |
| 163 | will need to be manually configured\(emfor some this is possible through | |
| 164 | the | |
| 165 | .Xr rc.conf 5 | |
| 166 | flags entries, for others it is not possible without munging | |
| 167 | the per-application configuration files, or even recompiling. | |
| 168 | For those | |
| 169 | applications that cannot specify the IP they run on, it is better to disable | |
| 170 | them, if possible. | |
| 171 | .Pp | |
| 172 | A number of daemons ship with the base system that may have problems when | |
| 173 | run from outside of a jail in a jail-centric environment. | |
| 174 | This includes | |
| 175 | .Xr sendmail 8 , | |
| 176 | .Xr named 8 , | |
| 177 | and | |
| 3b813696 | 178 | .Xr rpcbind 8 . |
| 984263bc MD |
179 | While |
| 180 | .Xr sendmail 8 | |
| 181 | and | |
| 182 | .Xr named 8 | |
| 183 | can be configured to listen only on a specific | |
| 184 | IP using their configuration files, in most cases it is easier to simply | |
| 185 | run the daemons in jails only, and not in the host environment. | |
| 186 | Attempting to serve | |
| 187 | NFS from the host environment may also cause confusion, and cannot be | |
| 188 | easily reconfigured to use only specific IPs, as some NFS services are | |
| 189 | hosted directly from the kernel. | |
| 190 | Any third party network software running | |
| 191 | in the host environment should also be checked and configured so that it | |
| 192 | does not bind all IP addresses, which would result in those services also | |
| 193 | appearing to be offered by the jail environments. | |
| 194 | .Pp | |
| 195 | Once | |
| 196 | these daemons have been disabled or fixed in the host environment, it is | |
| 197 | best to reboot so that all daemons are in a known state, to reduce the | |
| 198 | potential for confusion later (such as finding that when you send mail | |
| 199 | to a jail, and its sendmail is down, the mail is delivered to the host, | |
| 200 | etc.) | |
| 201 | .Pp | |
| 202 | Start any jails for the first time without configuring the network | |
| 203 | interface so that you can clean it up a little and set up accounts. | |
| 204 | As | |
| 205 | with any machine (virtual or not) you will need to set a root password, time | |
| 206 | zone, etc. | |
| 984263bc MD |
207 | .Pp |
| 208 | Now start the jail: | |
| 209 | .Pp | |
| 3e4150ef | 210 | .Dl "jail /data/jail/192.168.11.100 testhostname 127.0.0.1,192.168.11.100 /bin/sh" |
| 984263bc MD |
211 | .Pp |
| 212 | You will end up with a shell prompt, assuming no errors, within the jail. | |
| 6d2362d1 JS |
213 | You can now do the post-install configuration to set various configuration |
| 214 | options by editing | |
| 984263bc MD |
215 | .Pa /etc/rc.conf , |
| 216 | etc. | |
| 217 | .Pp | |
| 218 | .Bl -bullet -offset indent -compact | |
| 219 | .It | |
| 220 | Create an empty | |
| 221 | .Pa /etc/fstab | |
| 222 | to quell startup warnings about missing fstab | |
| 223 | .It | |
| 224 | Disable the port mapper | |
| 225 | .Pa ( /etc/rc.conf : | |
| 3b813696 | 226 | .Li rpcbind_enable="NO" ) |
| 984263bc MD |
227 | .It |
| 228 | Run | |
| 229 | .Xr newaliases 1 | |
| 230 | to quell | |
| 231 | .Xr sendmail 8 | |
| 232 | warnings. | |
| 233 | .It | |
| 234 | Disable interface configuration to quell startup warnings about | |
| 235 | .Xr ifconfig 8 | |
| 236 | .Pq Li network_interfaces="" | |
| 237 | .It | |
| 238 | Configure | |
| 239 | .Pa /etc/resolv.conf | |
| 240 | so that name resolution within the jail will work correctly | |
| 241 | .It | |
| 242 | Set a root password, probably different from the real host system | |
| 243 | .It | |
| 6d2362d1 JS |
244 | Set the timezone with |
| 245 | .Xr tzsetup 8 | |
| 984263bc MD |
246 | .It |
| 247 | Add accounts for users in the jail environment | |
| 248 | .It | |
| 249 | Install any packages that you think the environment requires | |
| 250 | .El | |
| 251 | .Pp | |
| 252 | You may also want to perform any package-specific configuration (web servers, | |
| 253 | SSH servers, etc), patch up | |
| 254 | .Pa /etc/syslog.conf | |
| 255 | so it logs as you would like, etc. | |
| 256 | .Pp | |
| 257 | Exit from the shell, and the jail will be shut down. | |
| 258 | .Ss "Starting the Jail" | |
| 259 | You are now ready to restart the jail and bring up the environment with | |
| 260 | all of its daemons and other programs. | |
| 261 | To do this, first bring up the | |
| 262 | virtual host interface, and then start the jail's | |
| 263 | .Pa /etc/rc | |
| 264 | script from within the jail. | |
| 265 | .Pp | |
| 266 | NOTE: If you plan to allow untrusted users to have root access inside the | |
| 267 | jail, you may wish to consider setting the | |
| 268 | .Va jail.set_hostname_allowed | |
| 269 | to 0. | |
| 270 | Please see the management reasons why this is a good idea. | |
| 271 | If you do decide to set this variable, | |
| 272 | it must be set before starting any jails, and once each boot. | |
| 273 | .Bd -literal -offset indent | |
| 274 | ifconfig ed0 inet alias 192.168.11.100/32 | |
| 275 | mount -t procfs proc /data/jail/192.168.11.100/proc | |
| 3e4150ef | 276 | jail /data/jail/192.168.11.100 testhostname 127.0.0.1,192.168.11.100 \\ |
| 984263bc MD |
277 | /bin/sh /etc/rc |
| 278 | .Ed | |
| 279 | .Pp | |
| 280 | A few warnings will be produced, because most | |
| 281 | .Xr sysctl 8 | |
| 282 | configuration variables cannot be set from within the jail, as they are | |
| 283 | global across all jails and the host environment. | |
| 284 | However, it should all | |
| 285 | work properly. | |
| 286 | You should be able to see | |
| 287 | .Xr inetd 8 , | |
| 288 | .Xr syslogd 8 , | |
| 289 | and other processes running within the jail using | |
| 290 | .Xr ps 1 , | |
| 291 | with the | |
| 292 | .Ql J | |
| 293 | flag appearing beside jailed processes. | |
| 294 | You should also be able to | |
| 295 | .Xr telnet 1 | |
| 296 | to the hostname or IP address of the jailed environment, and log | |
| 297 | in using the accounts you created previously. | |
| 298 | .Ss "Managing the Jail" | |
| 299 | Normal machine shutdown commands, such as | |
| 300 | .Xr halt 8 , | |
| 301 | .Xr reboot 8 , | |
| 302 | and | |
| 303 | .Xr shutdown 8 , | |
| 304 | cannot be used successfully within the jail. | |
| 305 | To kill all processes in a | |
| 306 | jail, you may log into the jail and, as root, use one of the following | |
| 307 | commands, depending on what you want to accomplish: | |
| 984263bc MD |
308 | .Bd -literal -offset indent |
| 309 | kill -TERM -1 | |
| 310 | kill -KILL -1 | |
| 311 | .Ed | |
| 312 | .Pp | |
| 313 | This will send the | |
| 314 | .Dv SIGTERM | |
| 315 | or | |
| 316 | .Dv SIGKILL | |
| 317 | signals to all processes in the jail from within the jail. | |
| 318 | Depending on | |
| 319 | the intended use of the jail, you may also want to run | |
| 320 | .Pa /etc/rc.shutdown | |
| 321 | from within the jail. | |
| 322 | Currently there is no way to insert new processes | |
| 323 | into a jail, so you must first log into the jail before performing these | |
| 324 | actions. | |
| 325 | .Pp | |
| 326 | To kill processes from outside the jail, you must individually identify the | |
| 327 | PID of each process to be killed. | |
| 328 | The | |
| 329 | .Pa /proc/ Ns Ar pid Ns Pa /status | |
| 330 | file contains, as its last field, the hostname of the jail in which the | |
| 331 | process runs, or | |
| 332 | .Dq Li - | |
| 333 | to indicate that the process is not running within a jail. | |
| 334 | The | |
| 335 | .Xr ps 1 | |
| 336 | command also shows a | |
| 337 | .Ql J | |
| 338 | flag for processes in a jail. | |
| 339 | However, the hostname for a jail may be, by | |
| 340 | default, modified from within the jail, so the | |
| 341 | .Pa /proc | |
| 342 | status entry is unreliable by default. | |
| 343 | To disable the setting of the hostname | |
| 344 | from within a jail, set the | |
| 345 | .Va jail.set_hostname_allowed | |
| 346 | sysctl variable in the host environment to 0, which will affect all jails. | |
| 347 | You can have this sysctl set on each boot using | |
| 348 | .Xr sysctl.conf 5 . | |
| 349 | Just add the following line to | |
| 350 | .Pa /etc/sysctl.conf : | |
| 351 | .Pp | |
| 352 | .Dl jail.set_hostname_allowed=0 | |
| 353 | .Pp | |
| 354 | In a future version of | |
| 9bb2a92d HP |
355 | .Dx , |
| 356 | the mechanisms for managing jails may be | |
| 984263bc MD |
357 | more refined. |
| 358 | .Ss "Sysctl MIB Entries" | |
| 359 | Certain aspects of the jail containments environment may be modified from | |
| 360 | the host environment using | |
| 361 | .Xr sysctl 8 | |
| 362 | MIB variables. | |
| 363 | Currently, these variables affect all jails on the system, although in | |
| 364 | the future this functionality may be finer grained. | |
| 365 | .Bl -tag -width XXX | |
| 366 | .It Va jail.set_hostname_allowed | |
| 367 | This MIB entry determines whether or not processes within a jail are | |
| 368 | allowed to change their hostname via | |
| 369 | .Xr hostname 1 | |
| 370 | or | |
| 371 | .Xr sethostname 3 . | |
| 372 | In the current jail implementation, the ability to set the hostname from | |
| 373 | within the jail can impact management tools relying on the accuracy of jail | |
| 374 | information in | |
| 375 | .Pa /proc . | |
| 376 | As such, this should be disabled in environments where privileged access to | |
| 377 | jails is given out to untrusted parties. | |
| 378 | .It Va jail.socket_unixiproute_only | |
| 3e4150ef VBD |
379 | The jail functionality binds IPv4 and IPv6 addresses to each jail, and limits |
| 380 | access to other network addresses in the IPv4 and IPv6 space that may be available | |
| 984263bc MD |
381 | in the host environment. |
| 382 | However, jail is not currently able to limit access to other network | |
| 383 | protocol stacks that have not had jail functionality added to them. | |
| 384 | As such, by default, processes within jails may only access protocols | |
| 385 | in the following domains: | |
| 3e4150ef | 386 | .Dv PF_LOCAL , PF_INET , PF_INET6 , |
| 984263bc MD |
387 | and |
| 388 | .Dv PF_ROUTE , | |
| 389 | permitting them access to | |
| 390 | .Ux | |
| 391 | domain sockets, | |
| 3e4150ef | 392 | IPv4 and IPv6 addresses, and routing sockets. |
| 984263bc MD |
393 | To enable access to other domains, this MIB variable may be set to |
| 394 | 0. | |
| 395 | .It Va jail.sysvipc_allowed | |
| 396 | This MIB entry determines whether or not processes within a jail have access | |
| 397 | to System V IPC primitives. | |
| 398 | In the current jail implementation, System V primitives share a single | |
| 399 | namespace across the host and jail environments, meaning that processes | |
| 400 | within a jail would be able to communicate with (and potentially interfere | |
| 401 | with) processes outside of the jail, and in other jails. | |
| 402 | As such, this functionality is disabled by default, but can be enabled | |
| 403 | by setting this MIB entry to 1. | |
| 404 | .El | |
| 405 | .Sh SEE ALSO | |
| 406 | .Xr newaliases 1 , | |
| 407 | .Xr ps 1 , | |
| 408 | .Xr chroot 2 , | |
| 409 | .Xr jail 2 , | |
| 410 | .Xr procfs 5 , | |
| 411 | .Xr rc.conf 5 , | |
| 412 | .Xr sysctl.conf 5 , | |
| 413 | .Xr halt 8 , | |
| 414 | .Xr inetd 8 , | |
| 415 | .Xr named 8 , | |
| 6d2362d1 | 416 | .Xr pw 8 , |
| 984263bc | 417 | .Xr reboot 8 , |
| 3b813696 | 418 | .Xr rpcbind 8 , |
| 984263bc MD |
419 | .Xr sendmail 8 , |
| 420 | .Xr shutdown 8 , | |
| 421 | .Xr sysctl 8 , | |
| 6d2362d1 JS |
422 | .Xr syslogd 8 , |
| 423 | .Xr tzsetup 8 | |
| 984263bc MD |
424 | .Sh HISTORY |
| 425 | The | |
| 426 | .Nm | |
| 427 | command appeared in | |
| 428 | .Fx 4.0 . | |
| 3e4150ef VBD |
429 | .Pp |
| 430 | Support for multiple IPs and IPv6 appeared in | |
| 431 | .Dx | |
| 432 | 1.7. | |
| 984263bc MD |
433 | .Sh AUTHORS |
| 434 | .An -nosplit | |
| 435 | The jail feature was written by | |
| 436 | .An Poul-Henning Kamp | |
| 437 | for R&D Associates | |
| 438 | .Pa http://www.rndassociates.com/ | |
| 439 | who contributed it to | |
| 440 | .Fx . | |
| 441 | .Pp | |
| 442 | .An Robert Watson | |
| 443 | wrote the extended documentation, found a few bugs, added | |
| 444 | a few new features, and cleaned up the userland jail environment. | |
| 3e4150ef VBD |
445 | .Pp |
| 446 | .An Victor Balada Diaz | |
| 447 | wrote the support for multiple IPs and IPv6. Multiple IPs support | |
| 448 | is based on work done by | |
| 449 | .An Pawel Jakub Dawidek . | |
| 984263bc MD |
450 | .Sh BUGS |
| 451 | Jail currently lacks strong management functionality, such as the ability | |
| 452 | to deliver signals to all processes in a jail, and to allow access to | |
| 453 | specific jail information via | |
| 454 | .Xr ps 1 | |
| 455 | as opposed to | |
| 456 | .Xr procfs 5 . | |
| 457 | Similarly, it might be a good idea to add an | |
| 458 | address alias flag such that daemons listening on all IPs | |
| 459 | .Pq Dv INADDR_ANY | |
| 460 | will not bind on that address, which would facilitate building a safe | |
| 461 | host environment such that host daemons do not impose on services offered | |
| 462 | from within jails. | |
| 463 | Currently, the simplist answer is to minimize services | |
| 464 | offered on the host, possibly limiting it to services offered from | |
| 465 | .Xr inetd 8 | |
| 466 | which is easily configurable. |