]> granicus.if.org Git - apache/blob - docs/manual/dns-caveats.xml
Update transformations
[apache] / docs / manual / dns-caveats.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="dns-caveats.xml.meta">
24
25   <title>Issues Regarding DNS and Apache HTTP Server</title>
26
27   <summary>
28     <p>This page could be summarized with the statement: don't
29     configure Apache HTTP Server in such a way that it relies on DNS resolution
30     for parsing of the configuration files. If httpd requires DNS
31     resolution to parse the configuration files then your server
32     may be subject to reliability problems (ie. it might not boot),
33     or denial and theft of service attacks (including users able
34     to steal hits from other users).</p>
35   </summary>
36
37   <section id="example">
38     <title>A Simple Example</title>
39
40     <example>
41       # This is a misconfiguration example, do not use on your server <br />
42       &lt;VirtualHost www.abc.dom&gt; <br />
43       ServerAdmin webgirl@abc.dom <br />
44       DocumentRoot /www/abc <br />
45       &lt;/VirtualHost&gt;
46     </example>
47
48     <p>In order for the server to function properly, it absolutely needs
49     to have two pieces of information about each virtual host: the
50     <directive module="core">ServerName</directive> and at least one
51     IP address that the server will bind and respond to. The above
52     example does not include the IP address, so httpd must use DNS
53     to find the address of <code>www.abc.dom</code>. If for some
54     reason DNS is not available at the time your server is parsing
55     its config file, then this virtual host <strong>will not be
56     configured</strong>. It won't be able to respond to any hits
57     to this virtual host (prior to httpd version 1.2 the server
58     would not even boot).</p>
59
60     <p>Suppose that <code>www.abc.dom</code> has address 192.0.2.1.
61     Then consider this configuration snippet:</p>
62
63     <example>
64       # This is a misconfiguration example, do not use on your server <br />
65       &lt;VirtualHost 192.0.2.1&gt; <br />
66       ServerAdmin webgirl@abc.dom <br />
67       DocumentRoot /www/abc <br />
68       &lt;/VirtualHost&gt;
69     </example>
70
71     <p>This time httpd needs to use reverse DNS to find the
72     <code>ServerName</code> for this virtualhost. If that reverse
73     lookup fails then it will partially disable the virtualhost.
74     If the virtual host is name-based then it will effectively be
75     totally disabled, but if it is IP-based then it will mostly
76     work. However, if httpd should ever have to generate a full
77     URL for the server which includes the server name, then it will
78     fail to generate a valid URL.</p>
79
80     <p>Here is a snippet that avoids both of these problems:</p>
81
82     <example>
83       &lt;VirtualHost 192.0.2.1&gt; <br />
84       ServerName www.abc.dom <br />
85       ServerAdmin webgirl@abc.dom <br />
86       DocumentRoot /www/abc <br />
87       &lt;/VirtualHost&gt;
88     </example>
89   </section>
90
91   <section id="denial">
92     <title>Denial of Service</title>
93
94     <p>There are (at least) two forms that denial of service
95     can come in. If you are running a version of httpd prior to
96     version 1.2 then your server will not even boot if one of the
97     two DNS lookups mentioned above fails for any of your virtual
98     hosts. In some cases this DNS lookup may not even be under your
99     control; for example, if <code>abc.dom</code> is one of your
100     customers and they control their own DNS, they can force your
101     (pre-1.2) server to fail while booting simply by deleting the
102     <code>www.abc.dom</code> record.</p>
103
104     <p>Another form is far more insidious. Consider this
105     configuration snippet:</p>
106
107     <example>
108       &lt;VirtualHost www.abc.dom&gt;<br />
109       <indent>
110         ServerAdmin webgirl@abc.dom<br />
111         DocumentRoot /www/abc<br />
112       </indent>
113       &lt;/VirtualHost&gt;<br />
114       <br />
115       &lt;VirtualHost www.def.dom&gt;<br />
116       <indent>
117         ServerAdmin webguy@def.dom<br />
118         DocumentRoot /www/def<br />
119       </indent>
120       &lt;/VirtualHost&gt;
121     </example>
122
123     <p>Suppose that you've assigned 192.0.2.1 to
124     <code>www.abc.dom</code> and 192.0.2.2 to
125     <code>www.def.dom</code>. Furthermore, suppose that
126     <code>def.dom</code> has control of their own DNS. With this
127     config you have put <code>def.dom</code> into a position where
128     they can steal all traffic destined to <code>abc.dom</code>. To
129     do so, all they have to do is set <code>www.def.dom</code> to
130     192.0.2.1. Since they control their own DNS you can't stop them
131     from pointing the <code>www.def.dom</code> record wherever they
132     wish.</p>
133
134     <p>Requests coming in to 192.0.2.1 (including all those where
135     users typed in URLs of the form
136     <code>http://www.abc.dom/whatever</code>) will all be served by
137     the <code>def.dom</code> virtual host. To better understand why
138     this happens requires a more in-depth discussion of how httpd 
139     matches up incoming requests with the virtual host that will
140     serve it. A rough document describing this <a
141     href="vhosts/details.html">is available</a>.</p>
142   </section>
143
144   <section id="main">
145     <title>The "main server" Address</title>
146
147     <p><a href="vhosts/name-based.html">Name-based
148     virtual host support</a> requires httpd to know
149     the IP address(es) of the host that <program>httpd</program>
150     is running on. To get this address it uses either the global
151     <directive module="core">ServerName</directive>
152     (if present) or calls the C function <code>gethostname</code>
153     (which should return the same as typing "hostname" at the
154     command prompt). Then it performs a DNS lookup on this address.
155     At present there is no way to avoid this lookup.</p>
156
157     <p>If you fear that this lookup might fail because your DNS
158     server is down then you can insert the hostname in
159     <code>/etc/hosts</code> (where you probably already have it so
160     that the machine can boot properly). Then ensure that your
161     machine is configured to use <code>/etc/hosts</code> in the
162     event that DNS fails. Depending on what OS you are using this
163     might be accomplished by editing <code>/etc/resolv.conf</code>,
164     or maybe <code>/etc/nsswitch.conf</code>.</p>
165
166     <p>If your server doesn't have to perform DNS for any other
167     reason then you might be able to get away with running httpd 
168     with the <code>HOSTRESORDER</code> environment variable set to
169     "local". This all depends on what OS and resolver libraries you
170     are using. It also affects CGIs unless you use
171     <module>mod_env</module> to control the environment. It's best
172     to consult the man pages or FAQs for your OS.</p>
173   </section>
174
175   <section id="tips">
176     <title>Tips to Avoid These Problems</title>
177
178     <ul>
179       <li>
180         use IP addresses in
181         <directive module="core">VirtualHost</directive>
182       </li>
183
184       <li>
185         use IP addresses in
186         <directive module="mpm_common">Listen</directive>
187       </li>
188
189       <li>
190         ensure all virtual hosts have an explicit
191         <directive module="core">ServerName</directive>
192       </li>
193
194       <li>create a <code>&lt;VirtualHost _default_:*&gt;</code>
195       server that has no pages to serve</li>
196     </ul>
197   </section>
198
199   <section id="appendix">
200     <title>Appendix: Future Directions</title>
201
202     <p>The situation regarding DNS is highly undesirable. Although
203     we've attempted to make the server at least continue
204     booting in the event of failed DNS, it might not be the
205     best we can do. In any event, requiring the use of explicit IP
206     addresses in configuration files is highly undesirable in
207     today's Internet where renumbering is a necessity.</p>
208
209     <p>A possible work around to the theft of service attack
210     described above would be to perform a reverse DNS lookup on the
211     IP address returned by the forward lookup and compare the two
212     names -- in the event of a mismatch, the virtualhost would be
213     disabled. This would require reverse DNS to be configured
214     properly (which is something that most admins are familiar with
215     because of the common use of "double-reverse" DNS lookups by
216     FTP servers and TCP wrappers).</p>
217
218     <p>In any event, it doesn't seem possible to reliably boot a
219     virtual-hosted web server when DNS has failed unless IP
220     addresses are used. Partial solutions such as disabling
221     portions of the configuration might be worse than not booting
222     at all depending on what the webserver is supposed to
223     accomplish.</p>
224
225     <p>As HTTP/1.1 is deployed and browsers and proxies start
226     issuing the <code>Host</code> header it will become possible to
227     avoid the use of IP-based virtual hosts entirely. In this case,
228     a webserver has no requirement to do DNS lookups during
229     configuration. But as of March 1997 these features have not
230     been deployed widely enough to be put into use on critical
231     webservers.</p>
232   </section>
233 </manualpage>