xref: /freebsd/usr.sbin/jail/jail.conf.5 (revision 26a58599a09a6181e0f5abe624021865a0c23186)
1.\" Copyright (c) 2012 James Gritton
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd Jun 3, 2023
26.Dt JAIL.CONF 5
27.Os
28.Sh NAME
29.Nm jail.conf
30.Nd configuration file for
31.Xr jail 8
32.Sh DESCRIPTION
33A
34.Xr jail 8
35configuration file consists of one or more jail definitions statements,
36and parameter or variable statements within those jail definitions.
37A jail definition statement looks something like a C compound statement.
38A parameter statement looks like a C assignment,
39including a terminating semicolon.
40.Pp
41The general syntax of a jail definition is:
42.Bd -literal -offset indent
43jailname {
44	parameter = "value";
45	parameter = "value";
46	...
47}
48.Ed
49.Pp
50Each jail is required to have a
51.Va name
52at the front of its definition.
53This is used by
54.Xr jail 8
55to specify a jail on the command line and report the jail status,
56and is also passed to the kernel when creating the jail.
57.Ss Parameters
58A jail is defined by a set of named parameters, specified inside the
59jail definition.
60.Em See
61.Xr jail 8
62.Em for a list of jail parameters
63passed to the kernel, as well as internal parameters used when creating and
64removing jails.
65.Pp
66A typical parameter has a name and a value.
67Some parameters are boolean and may be specified with values of
68.Dq true
69or
70.Dq false ,
71or as valueless shortcuts, with a
72.Dq no
73prefix indicating a false value.
74For example, these are equivalent:
75.Bd -literal -offset indent
76allow.mount = "false";
77allow.nomount;
78.Ed
79.Pp
80Other parameters may have more than one value.
81A comma-separated list of values may be set in a single statement,
82or an existing parameter list may be appended to using
83.Dq += :
84.Bd -literal -offset indent
85ip4.addr = 10.1.1.1, 10.1.1.2, 10.1.1.3;
86
87ip4.addr = 10.1.1.1;
88ip4.addr += 10.1.1.2;
89ip4.addr += 10.1.1.3;
90.Ed
91.Pp
92Note the
93.Va name
94parameter is implicitly set to the name in the jail definition.
95.Ss String format
96Parameter values, including jail names, can be single tokens or quoted
97strings.
98A token is any sequence of characters that aren't considered special in
99the syntax of the configuration file (such as a semicolon or
100whitespace).
101If a value contains anything more than letters, numbers, dots, dashes
102and underscores, it is advisable to put quote marks around that value.
103Either single or double quotes may be used.
104.Pp
105Special characters may be quoted by preceding them with a backslash.
106Common C-style backslash character codes are also supported, including
107control characters and octal or hex ASCII codes.
108A backslash at the end of a line will ignore the subsequent newline and
109continue the string at the start of the next line.
110.Ss Variables
111A string may use shell-style variable substitution.
112A parameter or variable name preceded by a dollar sign, and possibly
113enclosed in braces, will be replaced with the value of that parameter or
114variable.
115For example, a jail's path may be defined in terms of its name or
116hostname:
117.Bd -literal -offset indent
118path = "/var/jail/$name";
119
120path = "/var/jail/${host.hostname}";
121.Ed
122.Pp
123Variable substitution occurs in unquoted tokens or in double-quoted
124strings, but not in single-quote strings.
125.Pp
126A variable is defined in the same way a parameter is, except that the
127variable name is preceded with a dollar sign:
128.Bd -literal -offset indent
129$parentdir = "/var/jail";
130path = "$parentdir/$name";
131.Ed
132.Pp
133The difference between parameters and variables is that variables are
134only used for substitution, while parameters are used both for
135substitution and for passing to the kernel.
136.Ss Wildcards
137A jail definition with a name of
138.Dq *
139is used to define wildcard parameters.
140Every defined jail will contain both the parameters from its own
141definition statement, as well as any parameters in a wildcard
142definition.
143.Pp
144Variable substitution is done on a per-jail basis, even when that
145substitution is for a parameter defined in a wildcard section.
146This is useful for wildcard parameters based on e.g. a jail's name.
147.Pp
148Later definitions in the configuration file supersede earlier ones, so a
149wildcard section placed before (above) a jail definition defines
150parameters that could be changed on a per-jail basis.
151Or a wildcard section placed after (below) all jails would contain
152parameters that always apply to every jail.
153Multiple wildcard statements are allowed, and wildcard parameters may
154also be specified outside of a jail definition statement.
155.Pp
156If hierarchical jails are defined, a partial-matching wildcard
157definition may be specified.
158For example, a definition with a name of
159.Dq foo.*
160would apply to jails with names like
161.Dq foo.bar
162and
163.Dq foo.bar.baz .
164.Ss Includes
165A line of the form
166.Bd -literal -offset ident
167.include "filename";
168.Ed
169.Pp
170will include another file in the configuration.  The filename must be
171a literal string, and cannot contain variable expansions.
172.Ss Comments
173The configuration file may contain comments in the common C, C++, and
174shell formats:
175.Bd -literal -offset indent
176/* This is a C style comment.
177 * It may span multiple lines.
178 */
179
180// This is a C++ style comment.
181
182#  This is a shell style comment.
183.Ed
184.Pp
185Comments are legal wherever whitespace is allowed, i.e. anywhere except
186in the middle of a string or a token.
187.Sh FILES
188.Bl -tag -width "indent" -compact
189.It Pa /etc/jail.conf
190.It Pa /etc/jail.*.conf
191.It Pa /etc/jail.conf.d/*.conf
192.It Pa /usr/share/examples/jails/
193.El
194.Sh EXAMPLES
195.Bd -literal
196# Typical static defaults:
197# Use the rc scripts to start and stop jails.  Mount jail's /dev.
198exec.start = "/bin/sh /etc/rc";
199exec.stop = "/bin/sh /etc/rc.shutdown jail";
200exec.clean;
201mount.devfs;
202
203# Dynamic wildcard parameter:
204# Base the path off the jail name.
205path = "/var/jail/$name";
206
207# A typical jail.
208foo {
209	host.hostname = "foo.com";
210	ip4.addr = 10.1.1.1, 10.1.1.2, 10.1.1.3;
211}
212
213# This jail overrides the defaults defined above.
214bar {
215	exec.start = '';
216	exec.stop = '';
217	path = /;
218	mount.nodevfs;
219	persist;	// Required because there are no processes
220}
221
222# Include configurations from standard locations.
223\[char46]include "/etc/jail.conf.d/*.conf";
224\[char46]include "/etc/jail.*.conf";
225\[char46]include "/usr/local/etc/jail[.]conf";
226\[char46]include "/usr/local/etc/jail.conf.d/*.conf";
227\[char46]include "/usr/local/etc/jail.*.conf";
228.Ed
229.Sh SEE ALSO
230.Xr jail_set 2 ,
231.Xr rc.conf 5 ,
232.Xr jail 8 ,
233.Xr jls 8
234.Sh HISTORY
235The
236.Xr jail 8
237utility appeared in
238.Fx 4.0 .
239The
240.Nm
241file was added in
242.Fx 9.1 .
243.Sh AUTHORS
244.An -nosplit
245The jail feature was written by
246.An Poul-Henning Kamp
247for R&D Associates
248who contributed it to
249.Fx .
250.Pp
251.An James Gritton
252added the extensible jail parameters and configuration file.
253