xref: /netbsd-src/external/mpl/bind/dist/doc/arm/security.inc.rst (revision 9689912e6b171cbda866ec33f15ae94a04e2c02d)
1.. Copyright (C) Internet Systems Consortium, Inc. ("ISC")
2..
3.. SPDX-License-Identifier: MPL-2.0
4..
5.. This Source Code Form is subject to the terms of the Mozilla Public
6.. License, v. 2.0.  If a copy of the MPL was not distributed with this
7.. file, you can obtain one at https://mozilla.org/MPL/2.0/.
8..
9.. See the COPYRIGHT file distributed with this work for additional
10.. information regarding copyright ownership.
11
12.. _security:
13
14Security Configurations
15=======================
16
17Security Assumptions
18--------------------
19BIND 9's design assumes that access to the objects listed below is limited only to
20trusted parties. An incorrect deployment, which does not follow rules set by this
21section, cannot be the basis for CVE assignment or special security-sensitive
22handling of issues.
23
24Unauthorized access can potentially disclose sensitive data, slow down server
25operation, etc. Unauthorized, unexpected, or incorrect writes to any of the following listed objects
26can potentially cause crashes, incorrect data handling, or corruption:
27
28- All files stored on disk - including zone files, configuration files, key
29  files, temporary files, etc.
30- Clients communicating via the :any:`controls` socket using configured keys
31- Access to :any:`statistics-channels` from untrusted clients
32- Sockets used for :any:`update-policy` type `external`
33
34Certain aspects of the DNS protocol are left unspecified, such as the handling of
35responses from DNS servers which do not fully conform to the DNS protocol. For
36such a situation, BIND implements its own safety checks and limits which are
37subject to change as the protocol and deployment evolve.
38
39Authoritative Servers
40~~~~~~~~~~~~~~~~~~~~~
41By default, zones use intentionally lenient limits (unlimited size, long
42transfer timeouts, etc.). These defaults can be misused by the source of data
43(zone transfers or UPDATEs) to exhaust resources on the receiving side.
44
45The impact of malicious zone changes can be limited, to an extent, using
46configuration options listed in sections :ref:`server_resource_limits` and
47:ref:`zone_transfers`. Limits should also be applied to zones where malicious clients may potentially be authorized to use :ref:`dynamic_update`.
48
49DNS Resolvers
50~~~~~~~~~~~~~
51By definition, DNS resolvers act as traffic amplifiers;
52during normal operation, a DNS resolver can legitimately generate more outgoing
53traffic (counted in packets or bytes) than the incoming client traffic that
54triggered it. The DNS protocol specification does not currently specify limits
55for this amplification, but BIND implements its own limits to balance
56interoperability and safety. As a general rule, if a traffic amplification factor
57for any given scenario is lower than 100 packets, ISC does not handle the given
58scenario as a security issue. These limits are subject to change as DNS
59deployment evolves.
60
61All DNS answers received by the DNS resolver are treated as untrusted input and are
62subject to safety and correctness checks. However, protocol non-conformity
63might cause unexpected behavior. If such unexpected behavior is limited to DNS
64domains hosted on non-conformant servers, it is not deemed a security issue *in
65BIND*.
66
67.. _file_permissions:
68
69.. _access_Control_Lists:
70
71Access Control Lists
72--------------------
73
74Access Control Lists (ACLs) are address match lists that can be set up
75and nicknamed for future use in :any:`allow-notify`, :any:`allow-query`,
76:any:`allow-query-on`, :any:`allow-recursion`, :any:`blackhole`,
77:any:`allow-transfer`, :any:`match-clients`, etc.
78
79ACLs give users finer control over who can access the
80name server, without cluttering up configuration files with huge lists of
81IP addresses.
82
83It is a *good idea* to use ACLs and to control access.
84Limiting access to the server by outside parties can help prevent
85spoofing and denial-of-service (DoS) attacks against the server.
86
87ACLs match clients on the basis of up to three characteristics: 1) The
88client's IP address; 2) the TSIG or SIG(0) key that was used to sign the
89request, if any; and 3) an address prefix encoded in an EDNS
90Client-Subnet option, if any.
91
92Here is an example of ACLs based on client addresses:
93
94::
95
96   // Set up an ACL named "bogusnets" that blocks
97   // RFC1918 space and some reserved space, which is
98   // commonly used in spoofing attacks.
99   acl bogusnets {
100       0.0.0.0/8;  192.0.2.0/24; 224.0.0.0/3;
101       10.0.0.0/8; 172.16.0.0/12; 192.168.0.0/16;
102   };
103
104   // Set up an ACL called our-nets. Replace this with the
105   // real IP numbers.
106   acl our-nets { x.x.x.x/24; x.x.x.x/21; };
107   options {
108     ...
109     ...
110     allow-query { our-nets; };
111     allow-recursion { our-nets; };
112     ...
113     blackhole { bogusnets; };
114     ...
115   };
116
117   zone "example.com" {
118     type primary;
119     file "m/example.com";
120     allow-query { any; };
121   };
122
123This allows authoritative queries for ``example.com`` from any address,
124but recursive queries only from the networks specified in ``our-nets``,
125and no queries at all from the networks specified in ``bogusnets``.
126
127In addition to network addresses and prefixes, which are matched against
128the source address of the DNS request, ACLs may include ``key``
129elements, which specify the name of a TSIG or SIG(0) key.
130
131When BIND 9 is built with GeoIP support, ACLs can also be used for
132geographic access restrictions. This is done by specifying an ACL
133element of the form: ``geoip db database field value``.
134
135The ``field`` parameter indicates which field to search for a match. Available fields
136are ``country``, ``region``, ``city``, ``continent``, ``postal`` (postal code),
137``metro`` (metro code), ``area`` (area code), ``tz`` (timezone), ``isp``,
138``asnum``, and ``domain``.
139
140``value`` is the value to search for within the database. A string may be quoted
141if it contains spaces or other special characters. An ``asnum`` search for
142autonomous system number can be specified using the string "ASNNNN" or the
143integer NNNN. If a ``country`` search is specified with a string that is two characters
144long, it must be a standard ISO-3166-1 two-letter country code; otherwise,
145it is interpreted as the full name of the country.  Similarly, if
146``region`` is the search term and the string is two characters long, it is treated as a
147standard two-letter state or province abbreviation; otherwise, it is treated as the
148full name of the state or province.
149
150The :any:`database` field indicates which GeoIP database to search for a match. In
151most cases this is unnecessary, because most search fields can only be found in
152a single database.  However, searches for ``continent`` or ``country`` can be
153answered from either the ``city`` or ``country`` databases, so for these search
154types, specifying a :any:`database` forces the query to be answered from that
155database and no other. If a :any:`database` is not specified, these queries
156are first answered from the ``city`` database if it is installed, and then from the ``country``
157database if it is installed. Valid database names are ``country``,
158``city``, ``asnum``, ``isp``, and ``domain``.
159
160Some example GeoIP ACLs:
161
162::
163
164   geoip country US;
165   geoip country JP;
166   geoip db country country Canada;
167   geoip region WA;
168   geoip city "San Francisco";
169   geoip region Oklahoma;
170   geoip postal 95062;
171   geoip tz "America/Los_Angeles";
172   geoip org "Internet Systems Consortium";
173
174ACLs use a "first-match" logic rather than "best-match"; if an address
175prefix matches an ACL element, then that ACL is considered to have
176matched even if a later element would have matched more specifically.
177For example, the ACL ``{ 10/8; !10.0.0.1; }`` would actually match a
178query from 10.0.0.1, because the first element indicates that the query
179should be accepted, and the second element is ignored.
180
181When using "nested" ACLs (that is, ACLs included or referenced within
182other ACLs), a negative match of a nested ACL tells the containing ACL to
183continue looking for matches. This enables complex ACLs to be
184constructed, in which multiple client characteristics can be checked at
185the same time. For example, to construct an ACL which allows a query
186only when it originates from a particular network *and* only when it is
187signed with a particular key, use:
188
189::
190
191   allow-query { !{ !10/8; any; }; key example; };
192
193Within the nested ACL, any address that is *not* in the 10/8 network
194prefix is rejected, which terminates the processing of the ACL.
195Any address that *is* in the 10/8 network prefix is accepted, but
196this causes a negative match of the nested ACL, so the containing ACL
197continues processing. The query is accepted if it is signed by
198the key ``example``, and rejected otherwise. The ACL, then, only
199matches when *both* conditions are true.
200
201.. _chroot_and_setuid:
202
203``Chroot`` and ``Setuid``
204-------------------------
205
206On Unix servers, it is possible to run BIND in a *chrooted* environment
207(using the ``chroot()`` function) by specifying the :option:`-t <named -t>` option for
208:iscman:`named`. This can help improve system security by placing BIND in a
209"sandbox," which limits the damage done if a server is compromised.
210
211Another useful feature in the Unix version of BIND is the ability to run
212the daemon as an unprivileged user (:option:`-u <named -u>` user). We suggest running
213as an unprivileged user when using the ``chroot`` feature.
214
215Here is an example command line to load BIND in a ``chroot`` sandbox,
216``/var/named``, and to run :iscman:`named` ``setuid`` to user 202:
217
218``/usr/local/sbin/named -u 202 -t /var/named``
219
220.. _chroot:
221
222The ``chroot`` Environment
223~~~~~~~~~~~~~~~~~~~~~~~~~~
224
225For a ``chroot`` environment to work properly in a particular
226directory (for example, ``/var/named``), the
227environment must include everything BIND needs to run. From BIND's
228point of view, ``/var/named`` is the root of the filesystem;
229the values of options like :any:`directory` and :any:`pid-file`
230must be adjusted to account for this.
231
232Unlike with earlier versions of BIND,
233:iscman:`named` does *not* typically need to be compiled statically, nor do shared libraries need to be installed under the new
234root. However, depending on the operating system, it may be necessary to set
235up locations such as ``/dev/zero``, ``/dev/random``, ``/dev/log``, and
236``/etc/localtime``.
237
238.. _setuid:
239
240Using the ``setuid`` Function
241~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242
243Prior to running the :iscman:`named` daemon, use the ``touch`` utility (to
244change file access and modification times) or the ``chown`` utility (to
245set the user id and/or group id) on files where BIND should
246write.
247
248.. note::
249
250   If the :iscman:`named` daemon is running as an unprivileged user, it
251   cannot bind to new restricted ports if the server is
252   reloaded.
253
254.. _dynamic_update_security:
255
256Dynamic Update Security
257-----------------------
258
259Access to the dynamic update facility should be strictly limited. In
260earlier versions of BIND, the only way to do this was based on the IP
261address of the host requesting the update, by listing an IP address or
262network prefix in the :any:`allow-update` zone option. This method is
263insecure, since the source address of the update UDP packet is easily
264forged. Also note that if the IP addresses allowed by the
265:any:`allow-update` option include the address of a secondary server which
266performs forwarding of dynamic updates, the primary can be trivially
267attacked by sending the update to the secondary, which forwards it to
268the primary with its own source IP address - causing the primary to approve
269it without question.
270
271For these reasons, we strongly recommend that updates be
272cryptographically authenticated by means of transaction signatures
273(TSIG). That is, the :any:`allow-update` option should list only TSIG key
274names, not IP addresses or network prefixes. Alternatively, the
275:any:`update-policy` option can be used.
276
277Some sites choose to keep all dynamically updated DNS data in a
278subdomain and delegate that subdomain to a separate zone. This way, the
279top-level zone containing critical data, such as the IP addresses of
280public web and mail servers, need not allow dynamic updates at all.
281
282.. _sec_file_transfer:
283
284.. _dns_over_tls:
285