xref: /netbsd-src/external/mpl/bind/dist/doc/arm/rpz.inc.rst (revision b2c35e17b976cf7ccd7250c86c6f5e95090ed636)
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.. highlight:: none
13
14.. dns_firewalls_rpz:
15
16DNS Firewalls and Response Policy Zones
17---------------------------------------
18
19A DNS firewall examines DNS traffic and allows some responses to pass
20through while blocking others. This examination can be based on several
21criteria, including the name requested, the data (such as an IP address)
22associated with that name, or the name or IP address of the name server
23that is authoritative for the requested name.  Based on these criteria, a
24DNS firewall can be configured to discard, modify, or replace the original
25response, allowing administrators more control over what systems can access
26or be accessed from their networks.
27
28DNS Response Policy Zones (RPZ) are a form of DNS firewall in which the
29firewall rules are expressed within the DNS itself - encoded in an open,
30vendor-neutral format as records in specially constructed DNS zones.
31
32Using DNS zones to configure policy allows policy to be shared from
33one server to another using the standard DNS zone transfer mechanism.
34This allows a DNS operator to maintain their own firewall policies and
35share them easily amongst their internal name servers, or to subscribe to
36external firewall policies such as commercial or cooperative "threat
37feeds," or both.
38
39:iscman:`named` can subscribe to up to 64 Response Policy Zones, each of which
40encodes a separate policy rule set.  Each rule is stored in a DNS resource
41record set (RRset) within the RPZ, and consists of a **trigger** and an
42**action**.  There are five types of triggers and six types of actions.
43
44A response policy rule in a DNS RPZ can be triggered as follows:
45
46- by the IP address of the client
47- by the query name
48- by an address which would be present in a truthful response
49- by the name or address of an authoritative name server responsible for
50  publishing the original response
51
52A response policy action can be one of the following:
53
54- to synthesize a "domain does not exist" (NXDOMAIN) response
55- to synthesize a "name exists but there are no records of the requested
56  type" (NODATA) response
57- to drop the response
58- to switch to TCP by sending a truncated UDP response that requires the
59  DNS client to try again with TCP
60- to replace/override the response's data with specific data (provided
61  within the response policy zone)
62- to exempt the response from further policy processing
63
64The most common use of a DNS firewall is to "poison" a domain name, IP
65address, name server name, or name server IP address. Poisoning is usually
66done by forcing a synthetic "domain does not exist" (NXDOMAIN) response.
67This means that if an administrator maintains a list of known "phishing"
68domains, these names can be made unreachable by customers or end users just
69by adding a firewall policy into the recursive DNS server, with a trigger
70for each known "phishing" domain, and an action in every case forcing a
71synthetic NXDOMAIN response. It is also possible to use a data-replacement
72action such as answering for these known "phishing" domains with the name
73of a local web server that can display a warning page. Such a web server
74would be called a "walled garden."
75
76.. note::
77
78  Authoritative name servers can be responsible for many different domains.
79  If DNS RPZ is used to poison all domains served by some authoritative
80  name server name or address, the effects can be quite far-reaching. Users
81  are advised to ensure that such authoritative name servers do not also
82  serve domains that should not be poisoned.
83
84.. _why_dns_firewall:
85
86Why Use a DNS Firewall?
87~~~~~~~~~~~~~~~~~~~~~~~
88
89Criminal and network abuse traffic on the Internet often uses the Domain
90Name System (DNS), so protection against these threats should include DNS
91firewalling.  A DNS firewall can selectively intercept DNS queries for
92known network assets including domain names, IP addresses, and name
93servers. Interception can mean rewriting a DNS response to direct a web
94browser to a "walled garden," or simply making any malicious network assets
95invisible and unreachable.
96
97.. _what_dns_firewalls_do:
98
99What Can a DNS Firewall Do?
100~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
102Firewalls work by applying a set of rules to a traffic flow, where each
103rule consists of a trigger and an action. Triggers determine which messages
104within the traffic flow are handled specially, and actions determine what
105that special handling is. For a DNS firewall, the traffic flow to be
106controlled consists of responses sent by a recursive DNS server to its
107end-user clients. Some true responses are not safe for all clients, so the
108policy rules in a DNS firewall allow some responses to be intercepted and
109replaced with safer content.
110
111.. _rpz_rule_sets:
112
113Creating and Maintaining RPZ Rule Sets
114~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115
116In DNS RPZ, the DNS firewall policy rule set is stored in a DNS zone, which
117is maintained and synchronized using the same tools and methods as for any
118other DNS zone. The primary name server for a DNS RPZ may be an internal
119server, if an administrator is creating and maintaining their own DNS
120policy zone, or it may be an external name server (such as a security
121vendor's server), if importing a policy zone published externally. The
122primary copy of the DNS firewall policy can be a DNS "zone file" which is
123either edited by hand or generated from a database. A DNS zone can also be
124edited indirectly using DNS dynamic updates (for example, using the
125"nsupdate" shell level utility).
126
127DNS RPZ allows firewall rules to be expressed in a DNS zone format and then
128carried to subscribers as DNS data. A recursive DNS server which is capable
129of processing DNS RPZ synchronizes these DNS firewall rules using the same
130standard DNS tools and protocols used for secondary name service. The DNS
131policy information is then promoted to the DNS control plane inside the
132customer's DNS resolver, making that server into a DNS firewall.
133
134A security company whose products include threat intelligence feeds can use
135a DNS Response Policy Zone (RPZ) as a delivery channel to customers.
136Threats can be expressed as known-malicious IP addresses and subnets,
137known-malicious domain names, and known-malicious domain name servers. By
138feeding this threat information directly into customers' local DNS
139resolvers, providers can transform these DNS servers into a distributed DNS
140firewall.
141
142When a customer's DNS resolver is connected by a realtime subscription to a
143threat intelligence feed, the provider can protect the customer's end users
144from malicious network elements (including IP addresses and subnets, domain
145names, and name servers) immediately as they are discovered. While it may
146take days or weeks to "take down" criminal and abusive infrastructure once
147reported, a distributed DNS firewall can respond instantly.
148
149Other distributed TCP/IP firewalls have been on the market for many years,
150and enterprise users are now comfortable importing real-time threat
151intelligence from their security vendors directly into their firewalls.
152This intelligence can take the form of known-malicious IP addresses or
153subnets, or of patterns which identify known-malicious email attachments,
154file downloads, or web addresses (URLs). In some products it is also
155possible to block DNS packets based on the names or addresses they carry.
156
157.. _rpz_limitations:
158
159Limitations of DNS RPZ
160~~~~~~~~~~~~~~~~~~~~~~
161
162We're often asked if DNS RPZ could be used to set up redirection to a CDN.
163For example, if "mydomain.com" is a normal domain with SOA, NS, MX, TXT
164records etc., then if someone sends an A or AAAA query for "mydomain.com",
165can we use DNS RPZ on an authoritative nameserver to return "CNAME
166mydomain.com.my-cdn-provider.net"?
167
168The problem with this suggestion is that there is no way to CNAME only A
169and AAAA queries, not even with RPZ.
170
171The underlying reason is that if the authoritative server answers with a
172CNAME, the recursive server making that query will cache the response.
173Thereafter (while the CNAME is still in cache), it assumes that there are
174no records of any non-CNAME type for the name that was being queried, and
175directs subsequent queries for all other types directly to the target name
176of the CNAME record.
177
178To be clear, this is not a limitation of RPZ; it is a function of the way
179the DNS protocol works. It's simply not possible to use "partial" CNAMES to
180help when setting up CDNs because doing this will break other functionality
181such as email routing.
182
183Similarly, following the DNS protocol definition, wildcards in the form of
184``*.example`` records might behave in unintuitive ways. For a detailed
185definition of wildcards in DNS, please see :rfc:`4592`, especially section 2.
186
187.. _dns_firewall_examples:
188
189DNS Firewall Usage Examples
190~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
192Here are some scenarios in which a DNS firewall might be useful.
193
194Some known threats are based on an IP address or subnet (IP address range).
195For example, an analysis may show that all addresses in a "class C" network
196are used by a criminal gang for "phishing" web servers. With a DNS firewall
197based on DNS RPZ, a firewall policy can be created such as "if a DNS lookup
198would result in an address from this class C network, then answer instead
199with an NXDOMAIN indication." That simple rule would prevent any end users
200inside customers' networks from being able to look up any domain name used
201in this phishing attack – without having to know in advance what those
202names might be.
203
204Other known threats are based on domain names. An analysis may determine
205that a certain domain name or set of domain names is being or will shortly
206be used for spamming, phishing, or other Internet-based attacks which all
207require working domain names. By adding name-triggered rules to a
208distributed DNS firewall, providers can protect customers' end users from
209any attacks which require them to be able to look up any of these malicious
210names. The names can be wildcards (for example, \*.evil.com), and these
211wildcards can have exceptions if some domains are not as malicious as
212others (if \*.evil.com is bad, then not.evil.com might be an exception).
213
214Alongside growth in electronic crime has come growth of electronic criminal
215expertise. Many criminal gangs now maintain their own extensive DNS
216infrastructure to support a large number of domain names and a diverse set
217of IP addressing resources. Analyses show in many cases that the only truly
218fixed assets criminal organizations have are their name servers, which are
219by nature slightly less mobile than other network assets. In such cases,
220DNS administrators can anchor their DNS firewall policies in the abusive
221name server names or name server addresses, and thus protect their
222customers' end users from threats where neither the domain name nor the IP
223address of that threat is known in advance.
224
225Electronic criminals rely on the full resiliency of DNS just as the rest of
226digital society does. By targeting criminal assets at the DNS level we can
227deny these criminals the resilience they need. A distributed DNS firewall
228can leverage the high skills of a security company to protect a large
229number of end users. DNS RPZ, as the first open and vendor-neutral
230distributed DNS firewall, can be an effective way to deliver threat
231intelligence to customers.
232
233A Real-World Example of DNS RPZ's Value
234^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
235
236The Conficker malware worm (https://en.wikipedia.org/wiki/Conficker) was
237first detected in 2008. Although it is no longer an active threat, the
238techniques described here can be applied to other DNS threats.
239
240Conficker used a domain generation algorithm (DGA) to choose up to 50,000
241command and control domains per day. It would be impractical to create
242an RPZ that contains so many domain names and changes so much on a daily
243basis. Instead, we can trigger RPZ rules based on the names of the name
244servers that are authoritative for the command and control domains, rather
245than trying to trigger on each of 50,000 different (daily) query names.
246Since the well-known name server names for Conficker's domain names are
247never used by nonmalicious domains, it is safe to poison all lookups that
248rely on these name servers.  Here is an example that achieves this result:
249
250::
251
252  $ORIGIN rpz.example.com.
253  ns.0xc0f1c3a5.com.rpz-nsdname  CNAME  *.walled-garden.example.com.
254  ns.0xc0f1c3a5.net.rpz-nsdname  CNAME  *.walled-garden.example.com.
255  ns.0xc0f1c3a5.org.rpz-nsdname  CNAME  *.walled-garden.example.com.
256
257The ``*`` at the beginning of these CNAME target names is special, and it
258causes the original query name to be prepended to the CNAME target. So if a
259user tries to visit the Conficker command and control domain
260http://racaldftn.com.ai/ (which was a valid Conficker command and control
261domain name on 19-October-2011), the RPZ-configured recursive name server
262will send back this answer:
263
264::
265
266  racaldftn.com.ai.     CNAME     racaldftn.com.ai.walled-garden.example.com.
267  racaldftn.com.ai.walled-garden.example.com.     A      192.168.50.3
268
269This example presumes that the following DNS content has also been created,
270which is not part of the RPZ zone itself but is in another domain:
271
272::
273
274  $ORIGIN walled-garden.example.com.
275  *     A     192.168.50.3
276
277Assuming that we're running a web server listening on 192.168.50.3 that
278always displays a warning message no matter what uniform resource
279identifier (URI) is used, the above RPZ configuration will instruct the web
280browser of any infected end user to connect to a "server name" consisting
281of their original lookup name (racaldftn.com.ai) prepended to the walled
282garden domain name (walled-garden.example.com). This is the name that will
283appear in the web server's log file, and having the full name in that log
284file will facilitate an analysis as to which users are infected with what
285virus.
286
287.. _firewall_updates:
288
289Keeping Firewall Policies Updated
290~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291
292It is vital for overall system performance that incremental zone transfers
293(see :rfc:`1995`) and real-time change notification (see :rfc:`1996`) be
294used to synchronize DNS firewall rule sets between the publisher's primary
295copy of the rule set and the subscribers' working copies of the rule set.
296
297If DNS dynamic updates are used to maintain a DNS RPZ rule set, the name
298server automatically calculates a stream of deltas for use when sending
299incremental zone transfers to the subscribing name servers. Sending a
300stream of deltas – known as an "incremental zone transfer" or IXFR – is
301usually much faster than sending the full zone every time it changes, so
302it's worth the effort to use an editing method that makes such incremental
303transfers possible.
304
305Administrators who edit or periodically regenerate a DNS RPZ rule set and
306whose primary name server uses BIND can enable the
307:any:`ixfr-from-differences` option, which tells the primary name server to
308calculate the differences between each new zone and the preceding version,
309and to make these differences available as a stream of deltas for use in
310incremental zone transfers to the subscribing name servers. This will look
311something like the following:
312
313.. code-block:: c
314
315       options {
316                 // ...
317                 ixfr-from-differences yes;
318                 // ...
319       };
320
321As mentioned above, the simplest and most common use of a DNS firewall is
322to poison domain names known to be purely malicious, by simply making them
323disappear. All DNS RPZ rules are expressed as resource record sets
324(RRsets), and the way to express a "force a name-does-not-exist condition"
325is by adding a CNAME pointing to the root domain (``.``). In practice this
326looks like:
327
328::
329
330  $ORIGIN rpz.example.com.
331  malicious1.org          CNAME .
332  *.malicious1.org        CNAME .
333  malicious2.org          CNAME .
334  *.malicious2.org        CNAME .
335
336Two things are noteworthy in this example. First, the malicious names are
337made relative within the response policy zone. Since there is no trailing
338dot following ".org" in the above example, the actual RRsets created within
339this response policy zone are, after expansion:
340
341::
342
343  malicious1.org.rpz.example.com.         CNAME .
344  *.malicious1.org.rpz.example.com.       CNAME .
345  malicious2.org.rpz.example.com.         CNAME .
346  *.malicious2.org.rpz.example.com.       CNAME .
347
348Second, for each name being poisoned, a wildcard name is also listed.
349This is because a malicious domain name probably has or may potentially
350have malicious subdomains.
351
352In the above example, the relative domain names `malicious1.org` and
353`malicious2.org` will match only the real domain names `malicious1.org`
354and `malicious2.org`, respectively. The relative domain names
355`*.malicious1.org` and `*.malicious2.org` will match any
356`subdomain.of.malicious1.org` or `subdomain.of.malicious2.org`,
357respectively.
358
359This example forces an NXDOMAIN condition as its policy action, but other
360policy actions are also possible.
361
362.. _multiple_rpz_performance:
363
364Performance and Scalability When Using Multiple RPZs
365~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366
367Since version 9.10, BIND can be configured to have different response
368policies depending on the identity of the querying client and the nature of
369the query. To configure BIND response policy, the information is placed
370into a zone file whose only purpose is conveying the policy information to
371BIND. A zone file containing response policy information is called a
372Response Policy Zone, or RPZ, and the mechanism in BIND that uses the
373information in those zones is called DNS RPZ.
374
375It is possible to use as many as 64 separate RPZ files in a single instance
376of BIND, and BIND is not significantly slowed by such heavy use of RPZ.
377
378(Note: by default, BIND 9.11 only supports up to 32 RPZ files, but this
379can be increased to 64 at compile time. All other supported versions of
380BIND support 64 by default.)
381
382Each one of the policy zone files can specify policy for as many
383different domains as necessary. The limit of 64 is on the number of
384independently-specified policy collections and not the number of zones
385for which they specify policy.
386
387Policy information from all of the policy zones together are stored in a
388special data structure allowing simultaneous lookups across all policy
389zones to be performed very rapidly. Looking up a policy rule is
390proportional to the logarithm of the number of rules in the largest
391single policy zone.
392
393.. _rpz_practical_tips:
394
395Practical Tips for DNS Firewalls and DNS RPZ
396~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
397
398Administrators who subscribe to an externally published DNS policy zone and
399who have a large number of internal recursive name servers should create an
400internal name server called a "distribution master" (DM). The DM is a
401secondary (stealth secondary) name server from the publisher's point of
402view; that is, the DM is fetching zone content from the external server.
403The DM is also a primary name server from the internal recursive name
404servers' point of view: they fetch zone content from the DM.  In this
405configuration the DM is acting as a gateway between the external publisher
406and the internal subscribers.
407
408The primary server must know the unicast listener address of every
409subscribing recursive server, and must enumerate all of these addresses as
410destinations for real time zone change notification (as described in
411:rfc:`1996`). So if an enterprise-wide RPZ is called "rpz.example.com" and
412if the unicast listener addresses of four of the subscribing recursive name
413servers are 192.0.200.1, 192.0.201.1, 192.0.202.1, and 192.0.203.1, the
414primary server's configuration looks like this:
415
416.. code-block:: c
417
418  zone "rpz.example.com" {
419       type primary;
420       file "primary/rpz.example.com";
421       notify explicit;
422       also-notify { 192.0.200.1;
423                     192.0.201.1;
424                     192.0.202.1;
425                     192.0.203.1; };
426       allow-transfer { 192.0.200.1;
427                        192.0.201.1;
428                        192.0.202.1;
429                        192.0.203.1; };
430       allow-query { localhost; };
431  };
432
433Each recursive DNS server that subscribes to the policy zone must be
434configured as a secondary server for the zone, and must also be configured
435to use the policy zone for local response policy. To subscribe a recursive
436name server to a response policy zone where the unicast listener address
437of the primary server is 192.0.220.2, the server's configuration should
438look like this:
439
440.. code-block:: c
441
442  options {
443       // ...
444       response-policy {
445            zone "rpz.example.com";
446       };
447       // ...
448  };
449
450  zone "rpz.example.com";
451       type secondary;
452       primaries { 192.0.222.2; };
453       file "secondary/rpz.example.com";
454       allow-query { localhost; };
455       allow-transfer { none; };
456  };
457
458Note that queries are restricted to "localhost," since query access is
459never used by DNS RPZ itself, but may be useful to DNS operators for use in
460debugging. Transfers should be disallowed to prevent policy information
461leaks.
462
463If an organization's business continuity depends on full connectivity with
464another company whose ISP also serves some criminal or abusive customers,
465it's possible that one or more external RPZ providers – that is, security
466feed vendors – may eventually add some RPZ rules that could hurt a
467company's connectivity to its business partner. Users can protect
468themselves from this risk by using an internal RPZ in addition to any
469external RPZs, and by putting into their internal RPZ some "pass-through"
470rules to prevent any policy action from affecting a DNS response that
471involves a business partner.
472
473A recursive DNS server can be connected to more than one RPZ, and these are
474searched in order. Therefore, to protect a network from dangerous policies
475which may someday appear in external RPZ zones, administrators should list
476the internal RPZ zones first.
477
478
479.. code-block:: c
480
481  options {
482       // ...
483       response-policy {
484            zone "rpz.example.com";
485            zone "rpz.security-vendor-1.com";
486            zone "rpz.security-vendor-2.com";
487       };
488       // ...
489  };
490
491Within an internal RPZ, there need to be rules describing the network
492assets of business partners whose communications need to be protected.
493Although it is not generally possible to know what domain names they use,
494administrators will be aware of what address space they have and perhaps
495what name server names they use.
496
497::
498
499  $ORIGIN rpz.example.com.
500  8.0.0.0.10.rpz-ip                CNAME   rpz-passthru.
501  16.0.0.45.128.rpz-nsip           CNAME   rpz-passthru.
502  ns.partner1.com.rpz-nsdname      CNAME   rpz-passthru.
503  ns.partner2.com.rpz-nsdname      CNAME   rpz-passthru.
504
505Here, we know that answers in address block 10.0.0.0/8 indicate a business
506partner, as well as answers involving any name server whose address is in
507the 128.45.0.0/16 address block, and answers involving the name servers
508whose names are ns.partner1.com or ns.partner2.com.
509
510The above example demonstrates that when matching by answer IP address (the
511.rpz-ip owner), or by name server IP address (the .rpz-nsip owner) or by
512name server domain name (the .rpz-nsdname owner), the special RPZ marker
513(.rpz-ip, .rpz-nsip, or .rpz-nsdname) does not appear as part of the CNAME
514target name.
515
516By triggering these rules using the known network assets of a partner,
517and using the "pass-through" policy action, no later RPZ processing
518(which in the above example refers to the "rpz.security-vendor-1.com" and
519"rpz.security-vendor-2.com" policy zones) will have any effect on DNS
520responses for partner assets.
521
522.. _walled_garden_ip_address:
523
524Creating a Simple Walled Garden Triggered by IP Address
525~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
526
527It may be the case that the only thing known about an attacker is the IP
528address block they are using for their "phishing" web servers. If the
529domain names and name servers they use are unknown, but it is known that
530every one of their "phishing" web servers is within a small block of IP
531addresses, a response can be triggered on all answers that would include
532records in this address range, using RPZ rules that look like the following
533example:
534
535::
536
537  $ORIGIN rpz.example.com.
538  22.0.212.94.109.rpz-ip          CNAME   drop.garden.example.com.
539  *.212.94.109.in-addr.arpa       CNAME   .
540  *.213.94.109.in-addr.arpa       CNAME   .
541  *.214.94.109.in-addr.arpa       CNAME   .
542  *.215.94.109.in-addr.arpa       CNAME   .
543
544Here, if a truthful answer would include an A (address) RR (resource
545record) whose value were within the 109.94.212.0/22 address block, then a
546synthetic answer is sent instead of the truthful answer. Assuming the query
547is for www.malicious.net, the synthetic answer is:
548
549::
550
551  www.malicious.net.              CNAME   drop.garden.example.com.
552  drop.garden.example.com.        A       192.168.7.89
553
554This assumes that `drop.garden.example.com` has been created as real DNS
555content, outside of the RPZ:
556
557::
558
559  $ORIGIN example.com.
560  drop.garden                     A       192.168.7.89
561
562In this example, there is no "\*" in the CNAME target name, so the original
563query name will not be present in the walled garden web server's log file.
564This is an undesirable loss of information, and is shown here for example
565purposes only.
566
567The above example RPZ rules would also affect address-to-name (also
568known as "reverse DNS") lookups for the unwanted addresses. If a mail
569or web server receives a connection from an address in the example's
570109.94.212.0/22 address block, it will perform a PTR record lookup to
571find the domain name associated with that IP address.
572
573This kind of address-to-name translation is usually used for diagnostic or
574logging purposes, but it is also common for email servers to reject any
575email from IP addresses which have no address-to-name translation. Most
576mail from such IP addresses is spam, so the lack of a PTR record here has
577some predictive value.  By using the "force name-does-not-exist" policy
578trigger on all lookups in the PTR name space associated with an address
579block, DNS administrators can give their servers a hint that these IP
580addresses are probably sending junk.
581
582.. _known_rpz_inconsistency:
583
584A Known Inconsistency in DNS RPZ's NSDNAME and NSIP Rules
585~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
586
587Response Policy Zones define several possible triggers for each rule, and
588among these two are known to produce inconsistent results. This is not a
589bug; rather, it relates to inconsistencies in the DNS delegation model.
590
591DNS Delegation
592^^^^^^^^^^^^^^
593
594In DNS authority data, an NS RRset that is not at the apex of a DNS zone
595creates a sub-zone.  That sub-zone’s data is separate from the current (or
596"parent") zone, and it can have different authoritative name servers than
597the current zone. In this way, the root zone leads to COM, NET, ORG, and so
598on, each of which have their own name servers and their own way of managing
599their authoritative data. Similarly, ORG has delegations to ISC.ORG and to
600millions of other “dot-ORG” zones, each of which can have its own set of
601authoritative name servers. In the parlance of the protocol, these NS
602RRsets below the apex of a zone are called “delegation points.” An
603NS RRset at a delegation point contains a list of authoritative servers
604to which the parent zone is delegating authority for all names at or below
605the delegation point.
606
607At the apex of every zone there is also an NS RRset. Ideally, this
608so-called “apex NS RRset” should be identical to the “delegation point NS
609RRset” in the parent zone, but this ideal is not always achieved. In the
610real DNS, it’s almost always easier for a zone administrator to update one
611of these NS RRsets than the other, so that one will be correct and the
612other out of date. This inconsistency is so common that it’s been
613necessarily rendered harmless: domains that are inconsistent in this way
614are less reliable and perhaps slower, but they still function as long as
615there is some overlap between each of the NS RRsets and the truth. (“Truth”
616in this case refers to the actual set of name servers that are
617authoritative for the zone.)
618
619A Quick Review of DNS Iteration
620^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
621
622In DNS recursive name servers, an incoming query that cannot be answered
623from the local cache is sent to the closest known delegation point for the
624query name. For example, if a server is looking up XYZZY.ISC.ORG and it
625the name servers for ISC.ORG, then it sends the query to those servers
626directly; however, if it has never heard of ISC.ORG before, it must first
627send the query to the name servers for ORG (or perhaps even to the root
628zone that is the parent of ORG).
629
630When it asks one of the parent name servers, that server will not have an
631answer, so it sends a “referral” consisting only of the “delegation point
632NS RRset.” Once the server receives this referral, it “iterates” by sending
633the same query again, but this time to name servers for a more specific
634part of the query name.  Eventually this iteration terminates, usually by
635getting an answer or a “name error” (NXDOMAIN) from the query name’s
636authoritative server, or by encountering some type of server failure.
637
638When an authoritative server for the query name sends an answer, it has the
639option of including a copy of the zone’s apex NS RRset. If this occurs, the
640recursive name server caches this NS RRset, replacing the delegation point
641NS RRset that it had received during the iteration process. In the parlance
642of the DNS, the delegation point NS RRset is “glue,” meaning
643non-authoritative data, or more of a hint than a real truth. On the other
644hand, the apex NS RRset is authoritative data, coming as it does from the
645zone itself, and it is considered more credible than the “glue.” For this
646reason, it’s a little bit more important that the apex NS RRset be correct
647than that the delegation point NS RRset be correct, since the former will
648quickly replace the latter, and will be used more often for a longer total
649period of time.
650
651Importantly, the authoritative name server need not include its apex NS
652RRset in any answers, and recursive name servers do not ordinarily query
653directly for this RRset. Therefore it is possible for the apex NS RRset to
654be completely wrong without any operational ill-effects, since the wrong
655data need not be exposed. Of course, if a query comes in for this NS RRset,
656most recursive name servers will forward the query to the zone’s authority
657servers, since it’s bad form to return “glue” data when asked a specific
658question. In these corner cases, bad apex NS RRset data can cause a zone to
659become unreachable unpredictably, according to what other queries the
660recursive name server has processed.
661
662There is another kind of “glue," for name servers whose names are below
663delegation points. If ORG delegates ISC.ORG to NS-EXT.ISC.ORG, the ORG
664server needs to know an address for NS-EXT.ISC.ORG and return this address
665as part of the delegation response. However, the name-to-address binding
666for this name server is only authoritative inside the ISC.ORG zone;
667therefore, the A or AAAA RRset given out with the delegation is
668non-authoritative “glue,” which is replaced by an authoritative RRset if
669one is seen. As with apex NS RRsets, the real A or AAAA RRset is not
670automatically queried for by the recursive name server, but is queried for
671if an incoming query asks for this RRset.
672
673Enter RPZ
674^^^^^^^^^
675
676RPZ has two trigger types that are intended to allow policy zone authors to
677target entire groups of domains based on those domains all being served by
678the same DNS servers: NSDNAME and NSIP. The NSDNAME and NSIP rules are
679matched against the name and IP address (respectively) of the nameservers
680of the zone the answer is in, and all of its parent zones. In its default
681configuration, BIND actively fetches any missing NS RRsets and address
682records.  If, in the process of attempting to resolve the names of all of
683these delegated server names, BIND receives a SERVFAIL response for any of
684the queries, then it aborts the policy rule evaluation and returns SERVFAIL
685for the query. This is technically neither a match nor a non-match of the
686rule.
687
688Every "." in a fully qualified domain name (FQDN) represents a potential
689delegation point. When BIND goes searching for parent zone NS RRsets (and,
690in the case of NSIP, their accompanying address records), it has to check
691every possible delegation point. This can become a problem for some
692specialized pseudo-domains, such as some domain name and network reputation
693systems, that have many "." characters in the names. It is further
694complicated if that system also has non-compliant DNS servers that silently
695drop queries for NS and SOA records. This forces BIND to wait for those
696queries to time out before it can finish evaluating the policy rule, even
697if this takes longer than a reasonable client typically waits for an answer
698(delays of over 60 seconds have been observed).
699
700While both of these cases do involve configurations and/or servers that are
701technically "broken," they may still "work" outside of RPZ NSIP and NSDNAME
702rules because of redundancy and iteration optimizations.
703
704There are two RPZ options, ``nsip-wait-recurse`` and ``nsdname-wait-recurse``,
705that alter BIND's behavior by allowing it to use only those records that
706already exist in the cache when evaluating NSIP and NSDNAME rules,
707respectively.
708
709Therefore NSDNAME and NSIP rules are unreliable. The rules may be matched
710against either the apex NS RRset or the "glue" NS RRset, each with their
711associated addresses (that also might or might not be "glue"). It’s in the
712administrator's interests to discover both the delegation name server names
713and addresses, and the apex name server names and authoritative address
714records, to ensure correct use of NS and NSIP triggers in RPZ. Even then,
715there may be collateral damage to completely unrelated domains that
716otherwise "work," just by having NSIP and NSDNAME rules.
717
718.. _rpz_disable_mozilla_doh:
719
720Example: Using RPZ to Disable Mozilla DoH-by-Default
721~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
722
723Mozilla announced in September 2019 that they would enable DNS-over-HTTPS
724(DoH) for all US-based users of the Firefox browser, sending all their DNS
725queries to predefined DoH providers (Cloudflare's 1.1.1.1 service in
726particular). This is a concern for some network administrators who do not
727want their users' DNS queries to be rerouted unexpectedly. However,
728Mozilla provides a mechanism to disable the DoH-by-default setting:
729if the Mozilla-owned domain `use-application-dns.net
730<https://use-application-dns.net>`_ returns an NXDOMAIN response code, Firefox
731will not use DoH.
732
733To accomplish this using RPZ:
734
7351. Create a polizy zone file called ``mozilla.rpz.db`` configured so
736   that NXDOMAIN will be returned for any query to ``use-application-dns.net``:
737
738::
739
740  $TTL	604800
741  $ORIGIN	mozilla.rpz.
742  @	IN	SOA	localhost. root.localhost. 1 604800 86400 2419200 604800
743  @	IN	NS	localhost.
744  use-application-dns.net CNAME .
745
7462. Add the zone into the BIND configuration (usually :iscman:`named.conf`):
747
748.. code-block:: c
749
750  zone mozilla.rpz {
751      type primary;
752      file "/<PATH_TO>/mozilla.rpz.db";
753      allow-query { localhost; };
754  };
755
7563. Enable use of the Response Policy Zone for all incoming queries
757   by adding the :any:`response-policy` directive into the ``options {}``
758   section:
759
760.. code-block:: c
761
762  options {
763  	response-policy { zone mozilla.rpz; } break-dnssec yes;
764  };
765
7664. Reload the configuration and test whether the Response Policy
767   Zone that was just added is in effect:
768
769.. code-block:: shell-session
770
771  # rndc reload
772  # dig IN A use-application-dns.net @<IP_ADDRESS_OF_YOUR_RESOLVER>
773  # dig IN AAAA use-application-dns.net @<IP_ADDRESS_OF_YOUR_RESOLVER>
774
775The response should return NXDOMAIN instead of the list of IP addresses,
776and the BIND 9 log should contain lines like this:
777
778.. code-block:: none
779
780  09-Sep-2019 18:50:49.439 client @0x7faf8e004a00 ::1#54175 (use-application-dns.net): rpz QNAME NXDOMAIN rewrite use-application-dns.net/AAAA/IN via use-application-dns.net.mozilla.rpz
781  09-Sep-2019 18:50:49.439 client @0x7faf8e007800 127.0.0.1#62915 (use-application-dns.net): rpz QNAME NXDOMAIN rewrite use-application-dns.net/AAAA/IN via use-application-dns.net.mozilla.rpz
782
783Note that this is the simplest possible configuration; specific
784configurations may be different, especially for administrators who are
785already using other response policy zones, or whose servers are configured
786with multiple views.
787