Bv9ARM.ch07.html revision def82e8de9ff45e29ab21e5aba9a39539138c1f4
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews<!--
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews - Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews - Copyright (C) 2000-2003 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews -
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews - Permission to use, copy, modify, and/or distribute this software for any
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson - purpose with or without fee is hereby granted, provided that the above
c13b8351b4dfb18806af4eb3c0fea240d83d1f82Andreas Gustafsson - copyright notice and this permission notice appear in all copies.
c13b8351b4dfb18806af4eb3c0fea240d83d1f82Andreas Gustafsson -
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
c13b8351b4dfb18806af4eb3c0fea240d83d1f82Andreas Gustafsson - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson - PERFORMANCE OF THIS SOFTWARE.
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson-->
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson<!-- $Id$ -->
a185ac41ac0627ec711d13bf6fdd8a830b753060Andreas Gustafsson<html>
1928be262ca25485f4d7f0f6473fc5cafa0c3905Andreas Gustafsson<head>
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson<title>Chapter�7.�BIND 9 Security Considerations</title>
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt<meta name="generator" content="DocBook XSL Stylesheets V1.71.1">
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews<link rel="start" href="Bv9ARM.html" title="BIND 9 Administrator Reference Manual">
b947e1a521c6931f787d6d1b3604d5b138170c3dMukund Sivaraman<link rel="up" href="Bv9ARM.html" title="BIND 9 Administrator Reference Manual">
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson<link rel="prev" href="Bv9ARM.ch06.html" title="Chapter�6.�BIND 9 Configuration Reference">
ca44fe49bec16436cd95ace0af2e244f2096b284Brian Wellington<link rel="next" href="Bv9ARM.ch08.html" title="Chapter�8.�Troubleshooting">
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson</head>
dd977047669f15fe3ea1a977871d7678cebf5082Andreas Gustafsson<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
1928be262ca25485f4d7f0f6473fc5cafa0c3905Andreas Gustafsson<div class="navheader">
a185ac41ac0627ec711d13bf6fdd8a830b753060Andreas Gustafsson<table width="100%" summary="Navigation header">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<tr><th colspan="3" align="center">Chapter�7.�<acronym class="acronym">BIND</acronym> 9 Security Considerations</th></tr>
e9918d6a9df388b971a4805844165dd3fc3a88caAndreas Gustafsson<tr>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<td width="20%" align="left">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<a accesskey="p" href="Bv9ARM.ch06.html">Prev</a>�</td>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<th width="60%" align="center">�</th>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<td width="20%" align="right">�<a accesskey="n" href="Bv9ARM.ch08.html">Next</a>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson</td>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson</tr>
0d50da49baa7d2d39146d46789d88053af5b1b50Michael Sawyer</table>
0d50da49baa7d2d39146d46789d88053af5b1b50Michael Sawyer<hr>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson</div>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<div class="chapter" lang="en">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<div class="titlepage"><div><div><h2 class="title">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<a name="Bv9ARM.ch07"></a>Chapter�7.�<acronym class="acronym">BIND</acronym> 9 Security Considerations</h2></div></div></div>
e1e635578dedd17313312031be2759285c7c8e17Andreas Gustafsson<div class="toc">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<p><b>Table of Contents</b></p>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews<dl>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews<dt><span class="sect1"><a href="Bv9ARM.ch07.html#Access_Control_Lists">Access Control Lists</a></span></dt>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews<dt><span class="sect1"><a href="Bv9ARM.ch07.html#id2607129"><span><strong class="command">Chroot</strong></span> and <span><strong class="command">Setuid</strong></span></a></span></dt>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews<dd><dl>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews<dt><span class="sect2"><a href="Bv9ARM.ch07.html#id2607210">The <span><strong class="command">chroot</strong></span> Environment</a></span></dt>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews<dt><span class="sect2"><a href="Bv9ARM.ch07.html#id2607270">Using the <span><strong class="command">setuid</strong></span> Function</a></span></dt>
17be07ab818846dffb79e898da888a29c919bb02Mark Andrews</dl></dd>
7beeb415ca3f1b230d35a8d385d99d2901cf9ff9Andreas Gustafsson<dt><span class="sect1"><a href="Bv9ARM.ch07.html#dynamic_update_security">Dynamic Update Security</a></span></dt>
7beeb415ca3f1b230d35a8d385d99d2901cf9ff9Andreas Gustafsson</dl>
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson</div>
7beeb415ca3f1b230d35a8d385d99d2901cf9ff9Andreas Gustafsson<div class="sect1" lang="en">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<div class="titlepage"><div><div><h2 class="title" style="clear: both">
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson<a name="Access_Control_Lists"></a>Access Control Lists</h2></div></div></div>
a185ac41ac0627ec711d13bf6fdd8a830b753060Andreas Gustafsson<p>
a185ac41ac0627ec711d13bf6fdd8a830b753060Andreas Gustafsson Access Control Lists (ACLs) are address match lists that
0e9dcd548051a8ec34744bfa18b4e09fea742a39Andreas Gustafsson you can set up and nickname for future use in
7beeb415ca3f1b230d35a8d385d99d2901cf9ff9Andreas Gustafsson <span><strong class="command">allow-notify</strong></span>, <span><strong class="command">allow-query</strong></span>,
7beeb415ca3f1b230d35a8d385d99d2901cf9ff9Andreas Gustafsson <span><strong class="command">allow-query-on</strong></span>, <span><strong class="command">allow-recursion</strong></span>,
5a505fc4c2e99842052d9409790c7da0b5663bceMukund Sivaraman <span><strong class="command">blackhole</strong></span>, <span><strong class="command">allow-transfer</strong></span>,
5a505fc4c2e99842052d9409790c7da0b5663bceMukund Sivaraman <span><strong class="command">match-clients</strong></span>, etc.
5a505fc4c2e99842052d9409790c7da0b5663bceMukund Sivaraman </p>
10dd5f62f27b050c0e51d85cbd97e2f5925eb9acMukund Sivaraman<p>
10dd5f62f27b050c0e51d85cbd97e2f5925eb9acMukund Sivaraman Using ACLs allows you to have finer control over who can access
10dd5f62f27b050c0e51d85cbd97e2f5925eb9acMukund Sivaraman your name server, without cluttering up your config files with huge
lists of IP addresses.
</p>
<p>
It is a <span class="emphasis"><em>good idea</em></span> to use ACLs, and to
control access to your server. Limiting access to your server by
outside parties can help prevent spoofing and denial of service
(DoS) attacks against your server.
</p>
<p>
ACLs match clients on the basis of up to three characteristics:
1) The client's IP address; 2) the TSIG or SIG(0) key that was
used to sign the request, if any; and 3) an address prefix
encoded in an EDNS Client Subnet option, if any.
</p>
<p>
Here is an example of ACLs based on client addresses:
</p>
<pre class="programlisting">
// Set up an ACL named "bogusnets" that will block
// RFC1918 space and some reserved space, which is
// commonly used in spoofing attacks.
acl bogusnets {
0.0.0.0/8; 192.0.2.0/24; 224.0.0.0/3;
10.0.0.0/8; 172.16.0.0/12; 192.168.0.0/16;
};
// Set up an ACL called our-nets. Replace this with the
// real IP numbers.
acl our-nets { x.x.x.x/24; x.x.x.x/21; };
options {
...
...
allow-query { our-nets; };
allow-recursion { our-nets; };
...
blackhole { bogusnets; };
...
};
zone "example.com" {
type master;
file "m/example.com";
allow-query { any; };
};
</pre>
<p>
This allows authoritative queries for "example.com" from any
address, but recursive queries only from the networks specified
in "our-nets", and no queries at all from the networks
specified in "bogusnets".
</p>
<p>
In addition to network addresses and prefixes, which are
matched against the source address of the DNS request, ACLs
may include <code class="option">key</code> elements, which specify the
name of a TSIG or SIG(0) key, or <code class="option">ecs</code>
elements, which specify a network prefix but are only matched
if that prefix matches an EDNS client subnet option included
in the request.
</p>
<p>
The EDNS Client Subnet (ECS) option is used by a recursive
resolver to inform an authoritative name server of the network
address block from which the original query was received, enabling
authoritative servers to give different answers to the same
resolver for different resolver clients. An ACL containing
an element of the form
<span><strong class="command">ecs <em class="replaceable"><code>prefix</code></em></strong></span>
will match if a request arrives in containing an ECS option
encoding an address within that prefix. If the request has no
ECS option, then "ecs" elements are simply ignored. Addresses
in ACLs that are not prefixed with "ecs" are matched only
against the source address.
</p>
<p>
When <acronym class="acronym">BIND</acronym> 9 is built with GeoIP support,
ACLs can also be used for geographic access restrictions.
This is done by specifying an ACL element of the form:
<span><strong class="command">geoip [<span class="optional">db <em class="replaceable"><code>database</code></em></span>] <em class="replaceable"><code>field</code></em> <em class="replaceable"><code>value</code></em></strong></span>
</p>
<p>
The <em class="replaceable"><code>field</code></em> indicates which field
to search for a match. Available fields are "country",
"region", "city", "continent", "postal" (postal code),
"metro" (metro code), "area" (area code), "tz" (timezone),
"isp", "org", "asnum", "domain" and "netspeed".
</p>
<p>
<em class="replaceable"><code>value</code></em> is the value to search
for within the database. A string may be quoted if it
contains spaces or other special characters. If this is
an "asnum" search, then the leading "ASNNNN" string can be
used, otherwise the full description must be used (e.g.
"ASNNNN Example Company Name"). If this is a "country"
search and the string is two characters long, then it must
be a standard ISO-3166-1 two-letter country code, and if it
is three characters long then it must be an ISO-3166-1
three-letter country code; otherwise it is the full name
of the country. Similarly, if this is a "region" search
and the string is two characters long, then it must be a
standard two-letter state or province abbreviation;
otherwise it is the full name of the state or province.
</p>
<p>
The <em class="replaceable"><code>database</code></em> field indicates which
GeoIP database to search for a match. In most cases this is
unnecessary, because most search fields can only be found in
a single database. However, searches for country can be
answered from the "city", "region", or "country" databases,
and searches for region (i.e., state or province) can be
answered from the "city" or "region" databases. For these
search types, specifying a <em class="replaceable"><code>database</code></em>
will force the query to be answered from that database and no
other. If <em class="replaceable"><code>database</code></em> is not
specified, then these queries will be answered from the "city",
database if it is installed, or the "region" database if it is
installed, or the "country" database, in that order.
</p>
<p>
By default, if a DNS query includes an EDNS Client Subnet (ECS)
option which encodes a non-zero address prefix, then GeoIP ACLs
will be matched against that address prefix. Otherwise, they
are matched against the source address of the query. To
prevent GeoIP ACLs from matching against ECS options, set
the <span><strong class="command">geoip-use-ecs</strong></span> to <code class="literal">no</code>.
</p>
<p>
Some example GeoIP ACLs:
</p>
<pre class="programlisting">geoip country US;
geoip country JAP;
geoip db country country Canada;
geoip db region region WA;
geoip city "San Francisco";
geoip region Oklahoma;
geoip postal 95062;
geoip tz "America/Los_Angeles";
geoip org "Internet Systems Consortium";
</pre>
<p>
ACLs use a "first-match" logic rather than "best-match":
if an address prefix matches an ACL element, then that ACL
is considered to have matched even if a later element would
have matched more specifically. For example, the ACL
<span><strong class="command"> { 10/8; !10.0.0.1; }</strong></span> would actually
match a query from 10.0.0.1, because the first element
indicated that the query should be accepted, and the second
element is ignored.
</p>
<p>
When using "nested" ACLs (that is, ACLs included or referenced
within other ACLs), a negative match of a nested ACL will
the containing ACL to continue looking for matches. This
enables complex ACLs to be constructed, in which multiple
client characteristics can be checked at the same time. For
example, to construct an ACL which allows queries only when
it originates from a particular network <span class="emphasis"><em>and</em></span>
only when it is signed with a particular key, use:
</p>
<pre class="programlisting">
allow-query { !{ !10/8; any; }; key example; };
</pre>
<p>
Within the nested ACL, any address that is
<span class="emphasis"><em>not</em></span> in the 10/8 network prefix will
be rejected, and this will terminate processing of the
ACL. Any address that <span class="emphasis"><em>is</em></span> in the 10/8
network prefix will be accepted, but this causes a negative
match of the nested ACL, so the containing ACL continues
processing. The query will then be accepted if it is signed
by the key "example", and rejected otherwise. The ACL, then,
will only matches when <span class="emphasis"><em>both</em></span> conditions
are true.
</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="id2607129"></a><span><strong class="command">Chroot</strong></span> and <span><strong class="command">Setuid</strong></span>
</h2></div></div></div>
<p>
On UNIX servers, it is possible to run <acronym class="acronym">BIND</acronym>
in a <span class="emphasis"><em>chrooted</em></span> environment (using
the <span><strong class="command">chroot()</strong></span> function) by specifying
the "<code class="option">-t</code>" option for <span><strong class="command">named</strong></span>.
This can help improve system security by placing
<acronym class="acronym">BIND</acronym> in a "sandbox", which will limit
the damage done if a server is compromised.
</p>
<p>
Another useful feature in the UNIX version of <acronym class="acronym">BIND</acronym> is the
ability to run the daemon as an unprivileged user ( <code class="option">-u</code> <em class="replaceable"><code>user</code></em> ).
We suggest running as an unprivileged user when using the <span><strong class="command">chroot</strong></span> feature.
</p>
<p>
Here is an example command line to load <acronym class="acronym">BIND</acronym> in a <span><strong class="command">chroot</strong></span> sandbox,
<span><strong class="command">/var/named</strong></span>, and to run <span><strong class="command">named</strong></span> <span><strong class="command">setuid</strong></span> to
user 202:
</p>
<p>
<strong class="userinput"><code>/usr/local/sbin/named -u 202 -t /var/named</code></strong>
</p>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="id2607210"></a>The <span><strong class="command">chroot</strong></span> Environment</h3></div></div></div>
<p>
In order for a <span><strong class="command">chroot</strong></span> environment
to
work properly in a particular directory
(for example, <code class="filename">/var/named</code>),
you will need to set up an environment that includes everything
<acronym class="acronym">BIND</acronym> needs to run.
From <acronym class="acronym">BIND</acronym>'s point of view, <code class="filename">/var/named</code> is
the root of the filesystem. You will need to adjust the values of
options like
like <span><strong class="command">directory</strong></span> and <span><strong class="command">pid-file</strong></span> to account
for this.
</p>
<p>
Unlike with earlier versions of BIND, you typically will
<span class="emphasis"><em>not</em></span> need to compile <span><strong class="command">named</strong></span>
statically nor install shared libraries under the new root.
However, depending on your operating system, you may need
to set up things like
<code class="filename">/dev/zero</code>,
<code class="filename">/dev/random</code>,
<code class="filename">/dev/log</code>, and
<code class="filename">/etc/localtime</code>.
</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="id2607270"></a>Using the <span><strong class="command">setuid</strong></span> Function</h3></div></div></div>
<p>
Prior to running the <span><strong class="command">named</strong></span> daemon,
use
the <span><strong class="command">touch</strong></span> utility (to change file
access and
modification times) or the <span><strong class="command">chown</strong></span>
utility (to
set the user id and/or group id) on files
to which you want <acronym class="acronym">BIND</acronym>
to write.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
Note that if the <span><strong class="command">named</strong></span> daemon is running as an
unprivileged user, it will not be able to bind to new restricted
ports if the server is reloaded.
</div>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="dynamic_update_security"></a>Dynamic Update Security</h2></div></div></div>
<p>
Access to the dynamic
update facility should be strictly limited. In earlier versions of
<acronym class="acronym">BIND</acronym>, the only way to do this was
based on the IP
address of the host requesting the update, by listing an IP address
or
network prefix in the <span><strong class="command">allow-update</strong></span>
zone option.
This method is insecure since the source address of the update UDP
packet
is easily forged. Also note that if the IP addresses allowed by the
<span><strong class="command">allow-update</strong></span> option include the
address of a slave
server which performs forwarding of dynamic updates, the master can
be
trivially attacked by sending the update to the slave, which will
forward it to the master with its own source IP address causing the
master to approve it without question.
</p>
<p>
For these reasons, we strongly recommend that updates be
cryptographically authenticated by means of transaction signatures
(TSIG). That is, the <span><strong class="command">allow-update</strong></span>
option should
list only TSIG key names, not IP addresses or network
prefixes. Alternatively, the new <span><strong class="command">update-policy</strong></span>
option can be used.
</p>
<p>
Some sites choose to keep all dynamically-updated DNS data
in a subdomain and delegate that subdomain to a separate zone. This
way, the top-level zone containing critical data such as the IP
addresses
of public web and mail servers need not allow dynamic update at
all.
</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="Bv9ARM.ch06.html">Prev</a>�</td>
<td width="20%" align="center">�</td>
<td width="40%" align="right">�<a accesskey="n" href="Bv9ARM.ch08.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter�6.�<acronym class="acronym">BIND</acronym> 9 Configuration Reference�</td>
<td width="20%" align="center"><a accesskey="h" href="Bv9ARM.html">Home</a></td>
<td width="40%" align="right" valign="top">�Chapter�8.�Troubleshooting</td>
</tr>
</table>
</div>
<p style="text-align: center;">BIND 9.11.0pre-alpha</p>
</body>
</html>