Annotation of apache-modules/mod_ip_forwarding/mod_ip_forwarding.html, revision 1.8
1.1 kahan 1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2: "http://www.w3.org/TR/REC-html40/loose.dtd">
3: <html>
4: <head>
1.4 kahan 5: <meta http-equiv="Content-Type" content="">
6: <title>IP Forwarding Module: Compilation and Configuration</title>
1.1 kahan 7: </head>
1.4 kahan 8:
1.2 kahan 9: <body bgcolor="#ffffff">
10: <p><code>Created: 24/August/1998</code></p>
11: <hr>
1.1 kahan 12:
1.2 kahan 13: <h1 style="text-align: center"><span style="color: #E55500">mod_ip_forwarding
1.8 ! kahan 14: v2.0</span></h1>
1.2 kahan 15: <hr>
16:
17: <h2>Outline of the document</h2>
1.1 kahan 18: <ul>
1.4 kahan 19: <li>1. <a href="#1">Purpose</a></li>
20: <li>2. <a href="#2">Compiling the IP Forwarding module into Apache</a></li>
21: <li>3. <a href="#3">Configuring the IP Forwarding module</a>
22: <ul>
23: <li>3.1 <a href="#3.1">New directives</a></li>
24: <li>3.2 <a href="#3.2">Example</a></li>
25: </ul>
26: </li>
27: <li>4. <a href="#4.">Security Notes</a></li>
1.1 kahan 28: </ul>
29:
30: <h3>Special considerations</h3>
1.2 kahan 31:
1.4 kahan 32: <p>This module is dependent on the Apache API. If you'd like to use the
33: module on an Apache version higher than v1.3.6, please <a
1.2 kahan 34: href="mailto:jose@w3.org">mail me</a>.</p>
1.1 kahan 35:
36: <h3>Notation</h3>
37: <dl>
1.4 kahan 38: <dt>apache/</dt>
39: <dd>The apache source directory</dd>
1.1 kahan 40: </dl>
41:
42: <h2><a name="1"></a>1. Purpose<a name="2."></a></h2>
1.2 kahan 43:
44: <p>The motivation for this module was to be able to forward the IP address of
45: the source of a request between a proxy and the final destination server.
46: Under normal circumstances, this information is lost and the server only sees
47: the proxy's IP address. This hampers access control based on IP addresses.
48: This module answers this limitation in a transparent and secure way.</p>
49:
50: <p>Proxies forward the IP address inside a custom HTTP header. A server only
1.1 kahan 51: accepts this new header from a list of user-defined authorized proxies. Once
52: the header is accepted, it's internally substituted with the proxy's IP
53: address, so that this value is used for all access control and CGI modules.
54: This doesn't affect the actual IP address used to answer the proxy (they are
55: stored in different places).</p>
56:
1.4 kahan 57: <h2><a name="1"></a>2. Compiling the IP forwarding module into Apache</h2>
1.2 kahan 58:
1.4 kahan 59: <h3>2.1 Apache 2.4.x (or superior)</h3>
60:
1.7 kahan 61: <p>This is what I do to compile the module under Apache 2.4.3. I compile it
62: as a shared library. You don't need to compile apache yourself anymore. Isn't
63: life beautiful? These steps may change or not under newer versions of
1.4 kahan 64: Apache.</p>
1.1 kahan 65: <ol>
1.5 kahan 66: <li>Copy the latest apache 2 file <a
1.6 kahan 67: href="http://dev.w3.org/cvsweb/~checkout~/apache-modules/mod_ip_forwarding/mod_ip_forwarding.c?content-type=text/plain&only_with_tag=HEAD">mod_w3c_ip_forwarding.c</a>
1.5 kahan 68: to a local directory</li>
1.4 kahan 69: <li>Compile and install the module as follows:
70: <p><code># /path/to/this/tool/apxs2 -i -a -c
71: /path/to/mod_ip_forwarding.c</code></p>
72: </li>
73: </ol>
1.2 kahan 74:
1.4 kahan 75: <p>Note that module has to have the highest priority among the access control
76: modules. If you're using other proprietary access control modules, this
77: module should correspond to the last <code>activate-module </code>option.
78: Alternatively, you may use the Apache <code>ClearModuleList</code> and
79: <code>AddModule</code> configuration directives to reorder the modules. Also
80: note that you need to enable the <code>proxy</code> module too, as you want
81: to proxy requests.</p>
1.1 kahan 82:
1.4 kahan 83: <h3>2.2 Apache <a name="1." id="1.">1.3.x</a></h3>
1.1 kahan 84:
1.7 kahan 85: <p>This is what I do to compile the module under Apache 1.3.4. These steps
86: may change or not under newer versions of Apache.</p>
1.4 kahan 87: <ol>
88: <li>Copy the apache (1) file <a
89: href="http://dev.w3.org/cvsweb/~checkout~/apache-modules/mod_ip_forwarding/mod_ip_forwarding.c?rev=1.4">mod_w3c_ip_forwarding.c</a>
90: to the apache/src/modules/extra directory.
91: <p><em><strong>Note that you must follow this link to get the correct
92: version of this file. The latest version will only compile on apache
93: 2.x..</strong></em></p>
94: </li>
95: <li>Compile the module as follows:
96: <p><code># cd apache</code></p>
97: <p><code># ./configure --prefix=/usr/local/apache \</code></p>
98: <p><code>--enable-module=proxy \</code></p>
99: <p><code>--activate-module=src/modules/extra/mod_ip_forwarding.c</code></p>
100: <p><code># make</code></p>
101: <p><code># make install</code></p>
102: </li>
1.1 kahan 103: </ol>
1.2 kahan 104: Note that module has to have the highest priority among the access control
1.4 kahan 105: modules. If you're using other proprietary access control modules, this
106: module should correspond to the last <code>activate-module </code>option.
1.2 kahan 107: Alternatively, you may use the Apache <code>ClearModuleList</code> and
108: <code>AddModule</code> configuration directives to reorder the modules. Also
1.4 kahan 109: note that you need to enable the <code>proxy</code> module too, as you want
110: to proxy requests.
111:
1.7 kahan 112: <h3>2.3 Debian package</h3>
1.4 kahan 113:
1.7 kahan 114: <p>This is what I do to make a debian sarge package of this module for Apache
115: 2.x.</p>
116: <ol>
117: <li>Make a cvs checkout of the entire mod_ip_forwarding directory:
118: <p><code> $ cvs -d dev.w3.org:/sources/public co
119: apache-modules/mod_ip_forwarding</code></p>
120: </li>
121: <li><code> $ cd apache-modules/mod_ip_forwarding</code></li>
122: <li>As root, type:
123: <p> # <code>dpkg-buildpackage -us -us</code></p>
124: <p><code>(obmit the last two parameters if you want to sign the
125: module)</code></p>
126: </li>
127: <li>Once the module is created, it will be stored on the parent directory,
128: with a name such as
129: <code>libapache2-mod-ip-forward_20051129-1_i386.deb</code>. You can
130: install
131: <p>it using the usual debian command (as root):</p>
132: <p><code># dpkg --install
133: libapache2-mod-ip-forward_20051129-1_i386.deb</code></p>
134: </li>
135: </ol>
1.2 kahan 136:
1.1 kahan 137: <h2><a name="2">3</a>. Configuring the IP Forwarding module</h2>
138:
139: <h3><a name="2.1"></a>3.1 New directives</h3>
1.2 kahan 140:
141: <p>The IP Forwarding module introduces three directives to Apache:</p>
1.1 kahan 142: <dl>
1.4 kahan 143: <dt>ForwardClientIPAddress [on/off default = off]</dt>
144: <dd>Controls forwarding of the X_Client_Address header</dd>
145: <dt>AcceptForwardedClientIPAddress [on/off default = off]</dt>
146: <dd>Authorizes accepting an X_Client_Address header</dd>
147: <dt>LogUnauthorizedIPForwarding [on/off default = on]</dt>
148: <dd>Logs any unauthorized attemp to forward an IP address</dd>
149: <dt>X_ClientIPAddrHeader string [default = X_Fwd_IP_Addr]</dt>
150: <dd>Customizable header string for sending the client ip _addr</dd>
151: <dt>AuthorizedProxies [space separated list of IP addresses]</dt>
152: <dd>List of authorized proxies who can send an X_Client_Address
153: header</dd>
1.1 kahan 154: </dl>
1.2 kahan 155:
156: <p>Note that you need to set up this module on both the proxy server and the
1.1 kahan 157: final destination server. In addition, both servers must use the same
1.4 kahan 158: <code>X_ClientIPAddrHeader</code> value. Finally, the final destination
159: server must add the address of the proxy server using the
1.1 kahan 160: <code>AuthorizedProxies</code> directive. This protects against intruders
161: spoofing this header (unless they also spoof the IP address).</p>
162:
1.3 kahan 163: <p><em>The following is a tip contributed by Paul Roe. Thanks!</em></p>
164:
1.4 kahan 165: <p>If you're using this module as an Apache precompiled module (dynamic
1.3 kahan 166: modules that are downloaded at runtime), you need to add the following
167: configuration directive:</p>
168: <dl>
1.4 kahan 169: <dt>LoadModule ip_forwarding_module
170: /path_to_apache_modules/mod_ip_forwarding.so</dt>
1.3 kahan 171: </dl>
1.4 kahan 172:
1.3 kahan 173: <p>Note that the Debian apache-common-1.3.12-1 package seems to have renamed
1.4 kahan 174: this module as w3c_ip_forwarding_module. In this case, you need to load the
1.3 kahan 175: precompiled module as follows:</p>
176: <dl>
1.4 kahan 177: <dt>LoadModule w3c_ip_forwarding_module
178: /path_to_apache_modules/mod_ip_forwarding.so</dt>
1.3 kahan 179: </dl>
180:
1.1 kahan 181: <h3><a name="3.2"></a>3.2 Example</h3>
1.2 kahan 182:
183: <p>Let's suppose I have a proxy on 134.129.20.116 and a server on
184: 134.129.20.130. In addition, my client is at 123.123.123.123. Here's a
185: fragment of the proxy and final server's configuration:</p>
186: <pre>## Proxy configuration (may also be setup using mod_rewrite)
187: ProxyPass / http://134.129.20.130/
1.1 kahan 188: ForwardClientIPAddress On</pre>
189: <pre>## Server Configuration
190: AcceptForwardedClientIPAddress On
191: AuthorizedProxies 132.129.20.116</pre>
1.2 kahan 192:
193: <p>When the proxy contacts the server, it includes the following header:</p>
194: <pre>X_Forward_IP_Addr: 123.123.123.123</pre>
195:
196: <p>When the server calls a CGI-script, it sends the following environment
1.1 kahan 197: variable:</p>
1.2 kahan 198: <pre>REMOTE_ADDR: 123.123.123.123</pre>
199:
200: <p>Note that the value of the REMOTE_ADDR environment variable corresponds to
201: the one in the X_FWD_IP_ADDR header. Also, the X_ header was removed, as the
202: final server is not configured to forward the X_ header. To continue
1.4 kahan 203: forwarding the same header, you need to set the ForwardClientIPAddress in
204: that server too.</p>
1.2 kahan 205:
206: <p>If a non-authorized proxy (say,<code> 132.129.20.116</code>) sends the
207: custom header, the module will remove it from the headers and add the
208: following entry in the error log:</p>
1.1 kahan 209: <pre>[Mon Aug 24 15:57:48 1998] Unauthorized Proxy (132.129.20.116) tried to forward
1.2 kahan 210: a client IP address (123.123.123.123)</pre>
211:
212: <h2><a name="4.">4.</a> Security notes</h2>
213:
214: <p>This module does not implement a full-blown secure ip@ forwarding
215: mechanism. In particular, there are two weak security points:</p>
216: <ul>
1.4 kahan 217: <li><strong>IP spoofing.</strong> There's no protection against an
218: intruder's spoofing of the IP@ of an authorized proxy. Under such an
219: attack, the intruder may send any IP@ he wants in the<code>
220: X_ClientIPAddrHeader</code> heeader. This attack is less important when
221: the authorized proxy is on the border of a firewall and the destination
222: server is behind the firewall.</li>
223: <li><strong>Denial of service</strong>. The module generates a log message
224: each time that it detects an an IP@ forwarding by an unauthorized proxy.
225: An intruder may attempt filling up a server's logs with a flood of
226: unauthorized IP@ forwarding requests. If this attacks occurs, you can
227: temporarily turn off the logging by means of the module's
228: <code>LogUnauthorizedIPForwarding</code> directive.</li>
1.2 kahan 229: </ul>
230:
231: <p></p>
232: <hr>
1.1 kahan 233: <address>
1.4 kahan 234: <a href="mailto:jose@w3.org">Jose</a>
235: </address>
1.8 ! kahan 236: $Author: kahan $ $Date: Wednesday 01 February 2006 - 19:10:28$</body>
1.1 kahan 237: </html>
Webmaster